Skip to content

test_dupn_jump_to_valid_immediate_fails()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_jump_to_valid_immediate_fails@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_jump_to_valid_immediate_fails --fork Amsterdam

Test jumping to a valid immediate byte fails.

Bytecode: PUSH1(4) JUMP DUPN[0x00] Hex: 6004 56 e6 00 Position 4 contains 0x00 which is a VALID immediate for DUPN. Valid immediates are skipped in JUMPDEST analysis, so jump fails.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py
316
317
318
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
def test_dupn_jump_to_valid_immediate_fails(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test jumping to a valid immediate byte fails.

    Bytecode: PUSH1(4) JUMP DUPN[0x00]
    Hex: 6004 56 e6 00
    Position 4 contains 0x00 which is a VALID immediate for DUPN.
    Valid immediates are skipped in JUMPDEST analysis, so jump fails.
    """
    sender = pre.fund_eoa()

    # Build code that tries to jump to a valid immediate
    code = Bytecode()
    code += Op.PUSH1(4)  # Push jump target (position 4)
    code += Op.JUMP  # Try to jump to position 4
    # Pass as bytes (raw immediate byte for testing)
    code += Op.DUPN[b"\x00"]  # Position 3-4: DUPN + 0x00 (valid immediate)

    # This should never execute
    code += Op.SSTORE(0, 0x42)
    code += Op.STOP

    contract_address = pre.deploy_contract(code=code)

    tx = Transaction(to=contract_address, sender=sender)

    # Transaction fails - position 4 is a valid immediate, not JUMPDEST
    post = {contract_address: Account(storage={})}

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.