Skip to content

test_slotnum_stack_overflow()

Documentation for tests/amsterdam/eip7843_slotnum/test_slotnum.py::test_slotnum_stack_overflow@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip7843_slotnum/test_slotnum.py::test_slotnum_stack_overflow --fork Bogota

Test that SLOTNUM aborts when pushing past the 1024-item stack limit.

The callee executes push_count consecutive SLOTNUM opcodes: 1024 pushes fill the stack exactly and succeed, while the 1025th push aborts the frame exceptionally. The caller stores the call's success flag over a nonzero canary.

Source code in tests/amsterdam/eip7843_slotnum/test_slotnum.py
@EIPChecklist.Opcode.Test.StackOverflow()
@EIPChecklist.Opcode.Test.ExceptionalAbort()
@pytest.mark.parametrize(
    "push_count,call_succeeds",
    [
        pytest.param(1024, True, id="stack_at_limit"),
        pytest.param(1025, False, id="stack_overflow"),
    ],
)
def test_slotnum_stack_overflow(
    state_test: StateTestFiller,
    pre: Alloc,
    push_count: int,
    call_succeeds: bool,
) -> None:
    """
    Test that SLOTNUM aborts when pushing past the 1024-item stack limit.

    The callee executes `push_count` consecutive SLOTNUM opcodes: 1024
    pushes fill the stack exactly and succeed, while the 1025th push
    aborts the frame exceptionally. The caller stores the call's success
    flag over a nonzero canary.
    """
    callee_code = Op.SLOTNUM * push_count + Op.STOP
    callee_address = pre.deploy_contract(callee_code)

    caller_code = Op.SSTORE(0, Op.CALL(gas=Op.GAS, address=callee_address))
    caller_address = pre.deploy_contract(caller_code, storage={0: 0xBA5E})

    tx = Transaction(
        sender=pre.fund_eoa(),
        to=caller_address,
    )

    post = {
        caller_address: Account(
            storage={0: 1 if call_succeeds else 0},
        ),
    }

    state_test(
        env=Environment(slot_number=12345),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 2 forks.