Skip to content

Commit 164913e

Browse files
committed
review comments
Signed-off-by: Danno Ferrin <[email protected]>
1 parent 479e728 commit 164913e

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,33 @@ def test_jumpf_stack_size_1024_at_push(
236236

237237

238238
@pytest.mark.parametrize(
239-
("stack_height", "failure"),
239+
("stack_height", "target_inputs", "target_max_stack_height", "failure"),
240240
(
241-
pytest.param(1021, False, id="no_overflow"),
242-
pytest.param(1022, True, id="rule_overflow"),
243-
pytest.param(1023, True, id="execution_overflow"),
241+
pytest.param(1021, 0, 3, False, id="no_overflow_no_inputs"),
242+
pytest.param(1022, 0, 3, True, id="rule_overflow_no_inputs"),
243+
pytest.param(1023, 0, 3, True, id="execution_overflow"),
244+
pytest.param(1021, 1, 4, False, id="no_overflow_with_inputs"),
245+
pytest.param(1021, 2, 4, False, id="no_overflow_with_2_inputs"),
246+
pytest.param(1022, 2, 5, True, id="rule_overflow_with_inputs"),
247+
pytest.param(1022, 2, 3, True, id="rule_overflow_call_max"),
244248
),
245249
)
246250
def test_jumpf_stack_overflow(
247251
stack_height: int,
248252
failure: bool,
253+
target_inputs: int,
254+
target_max_stack_height: int,
249255
eof_state_test: EOFStateTestFiller,
250256
):
251257
"""
252-
Test stack overflowing 1024 items in JUMPF target function
258+
Test rule #2 in execution semantics, where we make sure we have enough stack to guarantee
259+
safe execution (the "reserved stack rule") max possible stack will not exceed 1024. But some
260+
executions may not overflow the stack, so we need to ensure the rule is checked.
253261
254262
`no_overflow` - the stack does not overflow at JUMPF call, executes to end
255-
`rule_overflow` - reserved stack overflows, but execution would not overflow
256263
`execution_overflow` - execution would overflow (but still blocked by reserved stack rule)
264+
`rule_overflow_*` - reserved stack rule triggers, but execution would not overflow,
265+
in various combinations
257266
"""
258267
eof_state_test(
259268
data=Container(
@@ -274,12 +283,16 @@ def test_jumpf_stack_overflow(
274283
max_stack_height=0,
275284
),
276285
Section.Code(
277-
Op.CALLDATALOAD(0)
286+
# clear space to work if needed
287+
Op.POP * max(0, target_inputs-3)
288+
+ Op.CALLDATALOAD(0)
278289
+ Op.ISZERO
279290
+ Op.RJUMPI[6]
280291
+ Op.PUSH0 * 3
281292
+ Op.POP * 3
282293
+ Op.SSTORE(slot_stack_canary, value_canary_written)
294+
# restore popped space, to ensure stack net zero
295+
+ Op.PUSH0 * max(0, target_inputs-3)
283296
+ Op.RETF,
284297
code_inputs=0,
285298
code_outputs=0,

0 commit comments

Comments
 (0)