Skip to content

test_eip_vector_dupn_stack_underflow()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_dupn_stack_underflow@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_dupn_stack_underflow --fork Amsterdam

EIP test vector: 6000808080808080808080808080808080e680.

Results in exceptional halt (stack underflow).

PUSH1 0, 15x DUP1, DUPN[0x80] - After 15 DUP1s: 16 items - DUPN[0x80]: decode_single(0x80)=17, needs position 17 but only 16 items - Result: exceptional halt

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
284
285
286
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
def test_eip_vector_dupn_stack_underflow(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    EIP test vector: 6000808080808080808080808080808080e680.

    Results in exceptional halt (stack underflow).

    PUSH1 0, 15x DUP1, DUPN[0x80]
    - After 15 DUP1s: 16 items
    - DUPN[0x80]: decode_single(0x80)=17, needs position 17 but only 16 items
    - Result: exceptional halt
    """
    sender = pre.fund_eoa()

    # Build the exact bytecode from the EIP
    code = Op.PUSH1[0x0] + Op.DUP1 * 15 + Op.DUPN[b"\x80"]
    assert bytes(code) == bytes.fromhex(
        "6000808080808080808080808080808080e680"
    )

    # This should not execute due to stack underflow
    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 fail, storage unchanged
    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.