test_stack_overflow()
Documentation for tests/frontier/opcodes/test_all_opcodes.py::test_stack_overflow@b2fd7c77.
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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211 | @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
push_opcode = Op.PUSH0 if Op.PUSH0 in fork.valid_opcodes() else Op.PUSH1(0)
contract = pre.deploy_contract(
code=Op.SSTORE(slot_code_worked, value_code_worked)
+ push_opcode * 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 142 parametrized test cases across 14 forks.