Skip to content

test_dupn_jump_to_immediate_byte_0x5b_succeeds()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_jump_to_immediate_byte_0x5b_succeeds@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_jump_to_immediate_byte_0x5b_succeeds --fork Bogota

Test that jumping to 0x5b after DUPN succeeds (backward compatibility).

Bytecode: DUPN[0x5b] The jump target contains 0x5b which is an INVALID immediate for DUPN. Per EIP-8024, 0x5b is preserved as valid JUMPDEST for compatibility. The DUPN instruction is never executed due to the jump.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
@EIPChecklist.Opcode.Test.DataPortion.Jump()
@pytest.mark.parametrize(
    "jump",
    [
        pytest.param(Op.JUMP, id="jump"),
        pytest.param(Op.JUMPI, id="jumpi_taken"),
    ],
)
def test_dupn_jump_to_immediate_byte_0x5b_succeeds(
    jump: Op,
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test that jumping to 0x5b after DUPN succeeds (backward compatibility).

    Bytecode: <JUMP or taken JUMPI> DUPN[0x5b]
    The jump target contains 0x5b which is an INVALID immediate for DUPN.
    Per EIP-8024, 0x5b is preserved as valid JUMPDEST for compatibility.
    The DUPN instruction is never executed due to the jump.
    """
    sender = pre.fund_eoa()

    # Build code that jumps to 0x5b after DUPN opcode
    code = Bytecode()
    pc = Op.PUSH1(data_placeholder="jump_pc")
    code += (
        Op.JUMPI(pc=pc, condition=1) if jump == Op.JUMPI else Op.JUMP(pc=pc)
    )  # Jump to the immediate byte
    # Pass as bytes (raw immediate byte for testing)
    code += Op.DUPN[b"\x5b"]  # DUPN + 0x5b (invalid immediate)
    code.substitute(jump_pc=len(code) - 1)

    # This SHOULD execute because 0x5b is a valid JUMPDEST
    code += Op.SSTORE(0, 0x42)
    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 2 parametrized test cases across 2 forks.