Skip to content

test_slotnum_stack_overflow()

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

Generate fixtures for these test cases for Amsterdam with:

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

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
191
192
193
194
195
196
197
198
199
200
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
@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 1 fork.