Skip to content

Commit a16fe20

Browse files
committed
new(tests) Add stack overflow by rule check to JUMPF
Just like CALLF, JUMPF has a stack overflow by rule check that tests were not tripping. Signed-off-by: Danno Ferrin <[email protected]>
1 parent 295879d commit a16fe20

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

tests/osaka/eip7692_eof_v1/eip6206_jumpf/helpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
next(_slot) # don't use slot 0
99
slot_code_worked = next(_slot)
1010
slot_last_slot = next(_slot)
11+
slot_stack_canary = next(_slot)
1112

1213
"""Storage values for common testing fields"""
1314
value_code_worked = 0x2015
15+
value_canary_written = 0xDEADB12D
16+
value_canary_should_not_change = 0x2019
17+
value_canary_to_be_overwritten = 0x2009

tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ethereum_test_tools.vm.opcode import Opcodes as Op
1111

1212
from .. import EOF_FORK_NAME
13-
from .helpers import slot_code_worked, value_code_worked
13+
from .helpers import slot_code_worked, slot_stack_canary, value_canary_written, value_code_worked
1414

1515
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-6206.md"
1616
REFERENCE_SPEC_VERSION = "2f365ea0cd58faa6e26013ea77ce6d538175f7d0"
@@ -235,39 +235,64 @@ def test_jumpf_stack_size_1024_at_push(
235235
)
236236

237237

238+
@pytest.mark.parametrize(
239+
("stack_height", "failure"),
240+
(
241+
pytest.param(1021, False, id="no_overflow"),
242+
pytest.param(1022, True, id="rule_overflow"),
243+
pytest.param(1023, True, id="execution_overflow"),
244+
),
245+
)
238246
def test_jumpf_stack_overflow(
247+
stack_height: int,
248+
failure: bool,
239249
eof_state_test: EOFStateTestFiller,
240250
):
241-
"""Test stack overflowing 1024 items in JUMPF target function"""
251+
"""
252+
Test stack overflowing 1024 items in JUMPF target function
253+
254+
`no_overflow` - the stack does not overflow at JUMPF call, executes to end
255+
`rule_overflow` - reserved stack overflows, but execution would not overflow
256+
`execution_overflow` - execution would overflow (but still blocked by reserved stack rule)
257+
"""
242258
eof_state_test(
243259
data=Container(
244260
sections=[
245261
Section.Code(
246-
code=Op.PUSH0 * 1023
262+
code=Op.PUSH0 * stack_height
247263
+ Op.CALLF[1]
248-
+ Op.POP * 1023
264+
+ Op.POP * stack_height
249265
+ Op.SSTORE(slot_code_worked, value_code_worked)
250266
+ Op.RETURN(0, 0),
251-
max_stack_height=1023,
267+
max_stack_height=stack_height,
252268
),
253269
Section.Code(
254-
# Stack has 1023 items
270+
# Stack has stack_height items
255271
Op.JUMPF[2],
256272
code_inputs=0,
257273
code_outputs=0,
258274
max_stack_height=0,
259275
),
260276
Section.Code(
261-
Op.PUSH0 + Op.PUSH0 +
262-
# Runtime stack overflow
263-
Op.POP + Op.POP + Op.RETF,
277+
Op.CALLDATALOAD(0)
278+
+ Op.ISZERO
279+
+ Op.RJUMPI[6]
280+
+ Op.PUSH0 * 3
281+
+ Op.POP * 3
282+
+ Op.SSTORE(slot_stack_canary, value_canary_written)
283+
+ Op.RETF,
264284
code_inputs=0,
265285
code_outputs=0,
266-
max_stack_height=2,
286+
max_stack_height=3,
267287
),
268288
],
269289
),
270-
container_post=Account(storage={slot_code_worked: 0}),
290+
container_post=Account(
291+
storage={
292+
slot_code_worked: 0 if failure else value_code_worked,
293+
slot_stack_canary: 0 if failure else value_canary_written,
294+
}
295+
),
271296
)
272297

273298

0 commit comments

Comments
 (0)