Skip to content

test_swapn_jump_to_valid_immediate_fails()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py::test_swapn_jump_to_valid_immediate_fails@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py::test_swapn_jump_to_valid_immediate_fails --fork Amsterdam

Test jumping to a valid immediate byte fails.

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

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
def test_swapn_jump_to_valid_immediate_fails(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test jumping to a valid immediate byte fails.

    Bytecode: PUSH1(4) JUMP SWAPN[0x00]
    Hex: 6004 56 e7 00
    Position 4 contains 0x00 which is a VALID immediate for SWAPN.
    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.SWAPN[b"\x00"]  # Position 3-4: SWAPN + 0x00 (valid)

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

    contract_address = pre.deploy_contract(code=code)

    tx = Transaction(to=contract_address, sender=sender, gas_limit=1_000_000)

    # 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.