Skip to content

test_eip_vector_jump_over_invalid_dupn()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_jump_over_invalid_dupn@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_jump_over_invalid_dupn --fork Amsterdam

EIP test vector: 600456e65b executes successfully.

PUSH1 04, JUMP, DUPN[0x5b] - The DUPN at position 2 has immediate 0x5b which would be invalid - But we JUMP to position 4 (the 0x5b byte), which is a valid JUMPDEST - The DUPN instruction is never executed

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def test_eip_vector_jump_over_invalid_dupn(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    EIP test vector: 600456e65b executes successfully.

    PUSH1 04, JUMP, DUPN[0x5b]
    - The DUPN at position 2 has immediate 0x5b which would be invalid
    - But we JUMP to position 4 (the 0x5b byte), which is a valid JUMPDEST
    - The DUPN instruction is never executed
    """
    sender = pre.fund_eoa()

    # Build the exact bytecode: PUSH1 04, JUMP, DUPN[0x5b]
    # Position 0: PUSH1 (0x60)
    # Position 1: 0x04
    # Position 2: JUMP (0x56)
    # Position 3: DUPN (0xe6)
    # Position 4: 0x5b (JUMPDEST when executed as opcode)
    code = Bytecode(
        Op.PUSH1[0x4] + Op.JUMP + Op.DUPN[b"\x5b"],
        popped_stack_items=0,
        pushed_stack_items=0,
    )
    assert bytes(code) == bytes.fromhex("600456e65b")

    # After jumping to JUMPDEST, mark success
    code += Op.PUSH1(1) + 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 should succeed
    post = {contract_address: Account(storage={0: 1})}

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.