Skip to content

test_stack_overflow()

Documentation for tests/frontier/opcodes/test_all_opcodes.py::test_stack_overflow@8db70f93.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/frontier/opcodes/test_all_opcodes.py::test_stack_overflow --fork Amsterdam

Test that opcodes which leave new items on the stack can overflow.

Source code in tests/frontier/opcodes/test_all_opcodes.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
@pytest.mark.parametrize_by_fork("opcode", fork_opcodes_increasing_stack)
@pytest.mark.parametrize("fails", [True, False])
@pytest.mark.eels_base_coverage
def test_stack_overflow(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    opcode: Op,
    fails: bool,
    env: Environment,
) -> None:
    """Test that opcodes which leave new items on the stack can overflow."""
    pre_stack_items = fork.max_stack_height()
    if not fails:
        pre_stack_items -= (
            opcode.pushed_stack_items - opcode.popped_stack_items
        )
    slot_code_worked = 1
    value_code_failed = 0xDEADBEEF
    value_code_worked = 1

    contract = pre.deploy_contract(
        code=Op.SSTORE(slot_code_worked, value_code_worked)
        + Op.PUSH1(0) * pre_stack_items
        + opcode
        + Op.STOP,
        storage={slot_code_worked: value_code_failed},
    )

    tx = Transaction(
        gas_limit=100_000,
        to=contract,
        sender=pre.fund_eoa(),
        protected=fork.supports_protected_txs(),
    )
    expected_storage = {
        slot_code_worked: value_code_failed if fails else value_code_worked
    }

    state_test(
        env=env,
        pre=pre,
        tx=tx,
        post={contract: Account(storage=expected_storage)},
    )

Parametrized Test Cases

This test generates 138 parametrized test cases across 14 forks.