Skip to content

test_swapn_jump_to_immediate_byte_0x5b_succeeds()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py::test_swapn_jump_to_immediate_byte_0x5b_succeeds@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_immediate_byte_0x5b_succeeds --fork Amsterdam

Test that jumping to 0x5b after SWAPN succeeds (backward compat).

Bytecode: PUSH1(4) JUMP SWAPN[0x5b] Hex: 6004 56 e7 5b Position 4 contains 0x5b which is an INVALID immediate for SWAPN. Per EIP-8024, 0x5b is preserved as valid JUMPDEST for compatibility. The SWAPN instruction is never executed due to the jump.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_swapn.py
388
389
390
391
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
@EIPChecklist.Opcode.Test.DataPortion.Jump()
def test_swapn_jump_to_immediate_byte_0x5b_succeeds(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test that jumping to 0x5b after SWAPN succeeds (backward compat).

    Bytecode: PUSH1(4) JUMP SWAPN[0x5b]
    Hex: 6004 56 e7 5b
    Position 4 contains 0x5b which is an INVALID immediate for SWAPN.
    Per EIP-8024, 0x5b is preserved as valid JUMPDEST for compatibility.
    The SWAPN instruction is never executed due to the jump.
    """
    sender = pre.fund_eoa()

    # Build code that jumps to 0x5b after SWAPN opcode
    code = Bytecode()
    code += Op.PUSH1(4)  # Push jump target (position 4)
    code += Op.JUMP  # Jump to position 4
    # Pass as bytes (raw immediate byte for testing)
    code += Op.SWAPN[b"\x5b"]  # Position 3-4: SWAPN + 0x5b (invalid)

    # This SHOULD execute because 0x5b is a valid JUMPDEST
    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 succeeds - 0x5b is preserved as valid JUMPDEST
    post = {contract_address: Account(storage={0: 0x42})}

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.