Skip to content

Commit e7fb7d8

Browse files
authored
new(tests): EOF - EIP-6206: Runtime stack overflow at JUMPF (#690)
* new(tests): EOF - EIP-6206: Runtime stack overflow at JUMPF * Update changelog
1 parent 00b4fb3 commit e7fb7d8

File tree

2 files changed

+194
-1
lines changed

2 files changed

+194
-1
lines changed

docs/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Test fixtures for use by clients are available for each release on the [Github r
2626
- ✨ Convert a few eip1153 tests from ethereum/tests repo into .py ([#440](https://github.com/ethereum/execution-spec-tests/pull/440)).
2727
- ✨ Add tests for [EIP-7480: EOF - Data section access instructions](https://eips.ethereum.org/EIPS/eip-7480) ([#518](https://github.com/ethereum/execution-spec-tests/pull/518), [#664](https://github.com/ethereum/execution-spec-tests/pull/664)).
2828
- ✨ Add tests for subcontainer kind validation from [EIP-7620: EOF Contract Creation](https://eips.ethereum.org/EIPS/eip-7620) for the cases with deeply nested containers and non-first code sections ([#676](https://github.com/ethereum/execution-spec-tests/pull/676)).
29-
- ✨ Add tests for runtime stack overflow at CALLF instruction from [EIP-4750: EOF - Functions](https://eips.ethereum.org/EIPS/eip-4750) for the cases with deeply nested containers and non-first code sections ([#678](https://github.com/ethereum/execution-spec-tests/pull/678)).
29+
- ✨ Add tests for runtime stack overflow at CALLF instruction from [EIP-4750: EOF - Functions](https://eips.ethereum.org/EIPS/eip-4750) ([#678](https://github.com/ethereum/execution-spec-tests/pull/678)).
30+
- ✨ Add tests for runtime stack overflow at JUMPF instruction from [EIP-6206: EOF - JUMPF and non-returning functions](https://eips.ethereum.org/EIPS/eip-6206) ([#690](https://github.com/ethereum/execution-spec-tests/pull/690)).
3031

3132
### 🛠️ Framework
3233

tests/prague/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""
22
EOF JUMPF tests covering simple cases.
33
"""
4+
45
import pytest
56

67
from ethereum_test_tools import Account, EOFException, EOFStateTestFiller
78
from ethereum_test_tools.eof.v1 import Container, Section
9+
from ethereum_test_tools.eof.v1.constants import NON_RETURNING_SECTION
810
from ethereum_test_tools.vm.opcode import Opcodes as Op
911

1012
from .. import EOF_FORK_NAME
@@ -149,3 +151,193 @@ def test_callf_to_non_returning_section(
149151
validity_error=EOFException.MISSING_STOP_OPCODE,
150152
),
151153
)
154+
155+
156+
def test_jumpf_stack_size_1024(
157+
eof_state_test: EOFStateTestFiller,
158+
):
159+
"""Test stack reaching 1024 items in target function of JUMPF"""
160+
eof_state_test(
161+
data=Container(
162+
sections=[
163+
Section.Code(
164+
code=Op.PUSH0 * 1022 + Op.JUMPF[1],
165+
max_stack_height=1022,
166+
),
167+
Section.Code(
168+
Op.SSTORE(slot_code_worked, value_code_worked) + Op.STOP,
169+
code_inputs=0,
170+
code_outputs=NON_RETURNING_SECTION,
171+
max_stack_height=2,
172+
),
173+
],
174+
),
175+
container_post=Account(storage={slot_code_worked: value_code_worked}),
176+
)
177+
178+
179+
def test_jumpf_with_inputs_stack_size_1024(
180+
eof_state_test: EOFStateTestFiller,
181+
):
182+
"""Test stack reaching 1024 items in target function of JUMPF with inputs"""
183+
eof_state_test(
184+
data=Container(
185+
sections=[
186+
Section.Code(
187+
code=Op.PUSH0 * 1022 + Op.JUMPF[1],
188+
max_stack_height=1022,
189+
),
190+
Section.Code(
191+
Op.SSTORE(slot_code_worked, value_code_worked) + Op.STOP,
192+
code_inputs=3,
193+
code_outputs=NON_RETURNING_SECTION,
194+
max_stack_height=5,
195+
),
196+
],
197+
),
198+
container_post=Account(storage={slot_code_worked: value_code_worked}),
199+
)
200+
201+
202+
def test_jumpf_stack_size_1024_at_push(
203+
eof_state_test: EOFStateTestFiller,
204+
):
205+
"""Test stack reaching 1024 items in JUMPF target function at PUSH0 instruction"""
206+
eof_state_test(
207+
data=Container(
208+
sections=[
209+
Section.Code(
210+
code=Op.PUSH0 * 1023
211+
+ Op.CALLF[1]
212+
+ Op.POP * 1023
213+
+ Op.SSTORE(slot_code_worked, value_code_worked)
214+
+ Op.RETURN(0, 0),
215+
max_stack_height=1023,
216+
),
217+
Section.Code(
218+
# stack has 1023 items
219+
Op.JUMPF[2],
220+
code_inputs=0,
221+
code_outputs=0,
222+
max_stack_height=0,
223+
),
224+
Section.Code(
225+
Op.PUSH0 +
226+
# stack has 1024 items
227+
Op.POP + Op.RETF,
228+
code_inputs=0,
229+
code_outputs=0,
230+
max_stack_height=1,
231+
),
232+
],
233+
),
234+
container_post=Account(storage={slot_code_worked: value_code_worked}),
235+
)
236+
237+
238+
def test_jumpf_stack_overflow(
239+
eof_state_test: EOFStateTestFiller,
240+
):
241+
"""Test stack overflowing 1024 items in JUMPF target function"""
242+
eof_state_test(
243+
data=Container(
244+
sections=[
245+
Section.Code(
246+
code=Op.PUSH0 * 1023
247+
+ Op.CALLF[1]
248+
+ Op.POP * 1023
249+
+ Op.SSTORE(slot_code_worked, value_code_worked)
250+
+ Op.RETURN(0, 0),
251+
max_stack_height=1023,
252+
),
253+
Section.Code(
254+
# Stack has 1023 items
255+
Op.JUMPF[2],
256+
code_inputs=0,
257+
code_outputs=0,
258+
max_stack_height=0,
259+
),
260+
Section.Code(
261+
Op.PUSH0 + Op.PUSH0 +
262+
# Runtime stack overflow
263+
Op.POP + Op.POP + Op.RETF,
264+
code_inputs=0,
265+
code_outputs=0,
266+
max_stack_height=2,
267+
),
268+
],
269+
),
270+
container_post=Account(storage={slot_code_worked: 0}),
271+
)
272+
273+
274+
def test_jumpf_with_inputs_stack_size_1024_at_push(
275+
eof_state_test: EOFStateTestFiller,
276+
):
277+
"""Test stack reaching 1024 items in JUMPF target function with inputs at PUSH0 instruction"""
278+
eof_state_test(
279+
data=Container(
280+
sections=[
281+
Section.Code(
282+
code=Op.PUSH0 * 1023
283+
+ Op.CALLF[1]
284+
+ Op.POP * 1023
285+
+ Op.SSTORE(slot_code_worked, value_code_worked)
286+
+ Op.RETURN(0, 0),
287+
max_stack_height=1023,
288+
),
289+
Section.Code(
290+
# Stack has 1023 items
291+
Op.JUMPF[2],
292+
code_inputs=3,
293+
code_outputs=3,
294+
max_stack_height=3,
295+
),
296+
Section.Code(
297+
Op.PUSH0 +
298+
# Stack has 1024 items
299+
Op.POP + Op.RETF,
300+
code_inputs=3,
301+
code_outputs=3,
302+
max_stack_height=4,
303+
),
304+
],
305+
),
306+
container_post=Account(storage={slot_code_worked: value_code_worked}),
307+
)
308+
309+
310+
def test_jumpf_with_inputs_stack_overflow(
311+
eof_state_test: EOFStateTestFiller,
312+
):
313+
"""Test stack overflowing 1024 items in JUMPF target function with inputs"""
314+
eof_state_test(
315+
data=Container(
316+
sections=[
317+
Section.Code(
318+
code=Op.PUSH0 * 1023
319+
+ Op.CALLF[1]
320+
+ Op.POP * 1023
321+
+ Op.SSTORE(slot_code_worked, value_code_worked)
322+
+ Op.RETURN(0, 0),
323+
max_stack_height=1023,
324+
),
325+
Section.Code(
326+
# Stack has 1023 items
327+
Op.JUMPF[2],
328+
code_inputs=3,
329+
code_outputs=3,
330+
max_stack_height=3,
331+
),
332+
Section.Code(
333+
Op.PUSH0 + Op.PUSH0 +
334+
# Runtime stackoverflow
335+
Op.POP + Op.POP + Op.RETF,
336+
code_inputs=3,
337+
code_outputs=3,
338+
max_stack_height=5,
339+
),
340+
],
341+
),
342+
container_post=Account(storage={slot_code_worked: 0}),
343+
)

0 commit comments

Comments
 (0)