Skip to content

Commit 09bbffb

Browse files
committed
new(tests): EOF validation RETF stack overflow
1 parent 4521b62 commit 09bbffb

File tree

3 files changed

+161
-5
lines changed

3 files changed

+161
-5
lines changed

converted-ethereum-tests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ EOFTests/efStack/backwards_rjumpi_variable_stack_.json
2323
EOFTests/efStack/backwards_rjumpv_.json
2424
EOFTests/efStack/backwards_rjumpv_variable_stack_.json
2525
EOFTests/efStack/jumpf_stack_overflow_.json
26+
EOFTests/efStack/retf_stack_validation_.json
27+
EOFTests/efStack/retf_variable_stack_.json
2628
EOFTests/efStack/forwards_rjump_.json
2729
EOFTests/efStack/forwards_rjump_variable_stack_.json
2830
EOFTests/efStack/forwards_rjumpi_.json

tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@
2424
pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)
2525

2626
VALID: List[Container] = [
27+
Container(
28+
name="retf_stack_validation_0",
29+
sections=[
30+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=2),
31+
Section.Code(
32+
code=Op.PUSH0 * 2 + Op.RETF,
33+
code_outputs=2,
34+
max_stack_height=2,
35+
),
36+
],
37+
),
38+
Container(
39+
name="retf_stack_validation_3",
40+
sections=[
41+
Section.Code(
42+
code=Op.PUSH0 + Op.CALLF[1] + Op.STOP,
43+
max_stack_height=2,
44+
),
45+
Section.Code(
46+
code=Op.RJUMPI[7] + Op.PUSH1[1] * 2 + Op.RJUMP[2] + Op.PUSH0 * 2 + Op.RETF,
47+
code_inputs=1,
48+
code_outputs=2,
49+
max_stack_height=2,
50+
),
51+
],
52+
),
2753
Container(
2854
name="retf_code_input_output",
2955
sections=[
@@ -90,6 +116,72 @@
90116
]
91117

92118
INVALID: List[Container] = [
119+
Container(
120+
name="retf_stack_validation_1",
121+
sections=[
122+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=2),
123+
Section.Code(
124+
code=Op.PUSH0 + Op.RETF,
125+
code_outputs=2,
126+
max_stack_height=1,
127+
),
128+
],
129+
validity_error=EOFException.STACK_UNDERFLOW,
130+
),
131+
Container(
132+
name="retf_variable_stack_0",
133+
sections=[
134+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=5),
135+
Section.Code(
136+
code=Op.PUSH0 + Op.PUSH1[0] + Op.RJUMPI[2] + Op.PUSH0 * 2 + Op.RETF,
137+
code_outputs=5,
138+
max_stack_height=3,
139+
),
140+
],
141+
validity_error=EOFException.STACK_UNDERFLOW,
142+
),
143+
Container(
144+
name="retf_variable_stack_1",
145+
sections=[
146+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=3),
147+
Section.Code(
148+
code=Op.PUSH0 + Op.PUSH1[0] + Op.RJUMPI[2] + Op.PUSH0 * 2 + Op.RETF,
149+
code_outputs=3,
150+
max_stack_height=3,
151+
),
152+
],
153+
validity_error=EOFException.STACK_UNDERFLOW,
154+
),
155+
Container(
156+
name="retf_variable_stack_4",
157+
sections=[
158+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=3),
159+
Section.Code(
160+
code=Op.PUSH0 * 3 + Op.PUSH1[0] + Op.RJUMPI[2] + Op.POP * 2 + Op.RETF,
161+
code_outputs=3,
162+
max_stack_height=4,
163+
),
164+
],
165+
validity_error=EOFException.STACK_UNDERFLOW,
166+
),
167+
Container(
168+
name="callf_inputs_underflow_0",
169+
sections=[
170+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=1),
171+
Section.Code(
172+
code=Op.PUSH0 + Op.CALLF[2] + Op.RETF,
173+
code_outputs=1,
174+
max_stack_height=1,
175+
),
176+
Section.Code(
177+
code=Op.POP + Op.RETF,
178+
code_inputs=2,
179+
code_outputs=1,
180+
max_stack_height=2,
181+
),
182+
],
183+
validity_error=EOFException.STACK_UNDERFLOW,
184+
),
93185
Container(
94186
# CALLF to function with incorrectly specified number of inputs
95187
name="code_inputs_underflow_1", # EOF1I4750_0020
@@ -128,6 +220,66 @@
128220
],
129221
validity_error=EOFException.STACK_UNDERFLOW,
130222
),
223+
Container(
224+
name="retf_stack_validation_2",
225+
sections=[
226+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=2),
227+
Section.Code(
228+
code=Op.PUSH0 * 3 + Op.RETF,
229+
code_outputs=2,
230+
max_stack_height=3,
231+
),
232+
],
233+
validity_error=EOFException.STACK_HIGHER_THAN_OUTPUTS,
234+
),
235+
Container(
236+
name="retf_variable_stack_2",
237+
sections=[
238+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=1),
239+
Section.Code(
240+
code=Op.PUSH0 + Op.PUSH1[0] + Op.RJUMPI[2] + Op.PUSH0 * 2 + Op.RETF,
241+
code_outputs=1,
242+
max_stack_height=3,
243+
),
244+
],
245+
validity_error=EOFException.STACK_HIGHER_THAN_OUTPUTS,
246+
),
247+
Container(
248+
name="retf_variable_stack_5",
249+
sections=[
250+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=1),
251+
Section.Code(
252+
code=Op.PUSH0 + Op.PUSH1[0] + Op.RJUMPI[1] + Op.PUSH0 + Op.RETF,
253+
code_outputs=1,
254+
max_stack_height=3,
255+
),
256+
],
257+
validity_error=EOFException.STACK_HIGHER_THAN_OUTPUTS,
258+
),
259+
Container(
260+
name="retf_variable_stack_6",
261+
sections=[
262+
Section.Code(code=Op.CALLF[1] + Op.STOP, max_stack_height=1),
263+
Section.Code(
264+
code=Op.PUSH0 * 2 + Op.PUSH1[0] + Op.RJUMPI[1] + Op.POP + Op.RETF,
265+
code_outputs=1,
266+
max_stack_height=3,
267+
),
268+
],
269+
validity_error=EOFException.STACK_HIGHER_THAN_OUTPUTS,
270+
),
271+
Container(
272+
name="retf_variable_stack_3",
273+
sections=[
274+
Section.Code(code=Op.CALLF[1] + Op.STOP),
275+
Section.Code(
276+
code=Op.PUSH0 + Op.PUSH1[0] + Op.RJUMPI[2] + Op.PUSH0 * 2 + Op.RETF,
277+
code_outputs=0,
278+
max_stack_height=3,
279+
),
280+
],
281+
validity_error=EOFException.STACK_HIGHER_THAN_OUTPUTS,
282+
),
131283
Container(
132284
name="stack_higher_than_code_outputs",
133285
sections=[

tests/osaka/eip7692_eof_v1/eof_tracker.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,13 @@
253253

254254
#### RETF
255255

256-
- [ ] Valid RETF with correct number of items on stack (ethereum/tests: src/EOFTestsFiller/efStack/retf_stack_validation_Copier.json src/EOFTestsFiller/EIP5450/validInvalidFiller.yml)
257-
- [ ] Invalid RETF with extra items on stack (ethereum/tests: src/EOFTestsFiller/efStack/retf_stack_validation_Copier.json ./src/EOFTestsFiller/efExample/validInvalidFiller.yml)
258-
- [ ] RETF stack underflow (ethereum/tests: src/EOFTestsFiller/efStack/retf_stack_validation_Copier.json)
259-
- [ ] RETF reached via different paths (ethereum/tests: src/EOFTestsFiller/efStack/retf_stack_validation_Copier.json)
260-
- [ ] RETF in variable stack segment is not allowed (ethereum/tests: src/EOFTestsFiller/efStack/retf_variable_stack_Copier.json)
256+
- [ ] Valid RETF with correct number of items on stack ([`tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py::test_eof_validity`](./eip4750_functions/test_code_validation/test_eof_validity.md))
257+
- [ ] src/EOFTestsFiller/EIP5450/validInvalidFiller.yml
258+
- [ ] Invalid RETF with extra items on stack ([`tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py::test_eof_validity`](./eip4750_functions/test_code_validation/test_eof_validity.md))
259+
- [ ] ./src/EOFTestsFiller/efExample/validInvalidFiller.yml
260+
- [x] RETF stack underflow ([`tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py::test_eof_validity`](./eip4750_functions/test_code_validation/test_eof_validity.md))
261+
- [x] RETF reached via different paths ([`tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py::test_eof_validity`](./eip4750_functions/test_code_validation/test_eof_validity.md))
262+
- [x] RETF in variable stack segment is not allowed ([`tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py::test_eof_validity`](./eip4750_functions/test_code_validation/test_eof_validity.md))
261263
- [ ] Extra items on stack allowed for terminating instructions other than RETF (ethereum/tests: src/EOFTestsFiller/EIP5450/validInvalidFiller.yml)
262264
- [x] Invalid RETF in a non-returning function ([`tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_nonreturning_validation.py::test_first_section_returning`](./eip6206_jumpf/test_nonreturning_validation/test_first_section_returning.md))
263265

0 commit comments

Comments
 (0)