Skip to content

test_dupn_jump_into_immediate_then_execute()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py::test_dupn_jump_into_immediate_then_execute@26332146.

Generate fixtures for these test cases for Amsterdam with:

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

Test jumping into a DUPN immediate, then executing a second DUPN.

The jump lands on the first DUPN's 0x5b immediate, a valid JUMPDEST because analysis is unchanged by EIP-8024, and a second DUPN then duplicates the deepest pushed value and stores it over the canary.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_dupn.py
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
@EIPChecklist.Opcode.Test.DataPortion.Jump()
def test_dupn_jump_into_immediate_then_execute(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    Test jumping into a DUPN immediate, then executing a second DUPN.

    The jump lands on the first DUPN's 0x5b immediate, a valid JUMPDEST
    because analysis is unchanged by EIP-8024, and a second DUPN then
    duplicates the deepest pushed value and stores it over the canary.
    """
    sender = pre.fund_eoa()

    setup = sum(
        (Op.PUSH1[i] for i in range(Spec.MIN_STACK_INDEX, 0, -1)),
        Bytecode(),
    )
    # The 0x5b landing pad sits 4 bytes past the setup: PUSH1,
    # target, JUMP, then the DUPN opcode byte itself.
    landing_pad = len(setup) + 4

    code = setup
    code += Op.PUSH1(landing_pad) + Op.JUMP
    code += Op.DUPN[b"\x5b"]  # Jumped into, never executed.
    code += Op.SSTORE(
        0,
        Op.DUPN[Spec.MIN_STACK_INDEX],  # Executed after landing.
    )
    code += Op.STOP

    contract_address = pre.deploy_contract(code=code, storage={0: 0xBA5E})

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

    post = {contract_address: Account(storage={0: Spec.MIN_STACK_INDEX})}

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.