Skip to content

test_vector_dupn_followed_by_jumpdest()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_vector_dupn_followed_by_jumpdest@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_vector_dupn_followed_by_jumpdest --fork Amsterdam

Test vector: e6805b [DUPN 17, JUMPDEST].

Verify that DUPN with immediate 0x80 (128) correctly consumes the immediate byte. The 0x5b following the DUPN is a separate JUMPDEST instruction, not part of DUPN. decode_single(0x80) = 17, so DUPN duplicates the 17th stack item.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
def test_vector_dupn_followed_by_jumpdest(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test vector: e6805b [DUPN 17, JUMPDEST].

    Verify that DUPN with immediate 0x80 (128) correctly consumes the
    immediate byte. The 0x5b following the DUPN is a separate JUMPDEST
    instruction, not part of DUPN. decode_single(0x80) = 17, so DUPN
    duplicates the 17th stack item.
    """
    sender = pre.fund_eoa()

    # Push 17 items so DUPN[17] (immediate 0x80 / 128) succeeds
    marker_value = 0xBEEF
    code = Bytecode()
    code += Op.PUSH2(marker_value)  # This will be at position 17
    for i in range(16):
        code += Op.PUSH1(i)

    # DUPN[17] encodes to immediate 0x80 (128), followed by JUMPDEST
    # Bytecode: e6 80 5b
    code += Op.DUPN[17] + Op.JUMPDEST

    # Store the duplicated value (should be marker_value)
    code += Op.PUSH1(0) + Op.SSTORE
    code += Op.STOP

    contract_address = pre.deploy_contract(code=code)
    tx = Transaction(to=contract_address, sender=sender)

    # DUPN should duplicate position 17 (marker_value)
    post = {contract_address: Account(storage={0: marker_value})}

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.