@@ -236,24 +236,33 @@ def test_jumpf_stack_size_1024_at_push(
236
236
237
237
238
238
@pytest .mark .parametrize (
239
- ("stack_height" , "failure" ),
239
+ ("stack_height" , "target_inputs" , "target_max_stack_height" , " failure" ),
240
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" ),
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" ),
244
248
),
245
249
)
246
250
def test_jumpf_stack_overflow (
247
251
stack_height : int ,
248
252
failure : bool ,
253
+ target_inputs : int ,
254
+ target_max_stack_height : int ,
249
255
eof_state_test : EOFStateTestFiller ,
250
256
):
251
257
"""
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.
253
261
254
262
`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
263
`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
257
266
"""
258
267
eof_state_test (
259
268
data = Container (
@@ -274,12 +283,16 @@ def test_jumpf_stack_overflow(
274
283
max_stack_height = 0 ,
275
284
),
276
285
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 )
278
289
+ Op .ISZERO
279
290
+ Op .RJUMPI [6 ]
280
291
+ Op .PUSH0 * 3
281
292
+ Op .POP * 3
282
293
+ 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 )
283
296
+ Op .RETF ,
284
297
code_inputs = 0 ,
285
298
code_outputs = 0 ,
0 commit comments