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@622620d8.

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. JUMPDEST analysis is unchanged by EIP-8024: position 4 holds 0x00, not 0x5b, so it is not a valid jump target and the jump fails.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
@EIPChecklist.Opcode.Test.DataPortion.Jump()
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.
    JUMPDEST analysis is unchanged by EIP-8024: position 4 holds 0x00,
    not 0x5b, so it is not a valid jump target and the 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)

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