Skip to content

Commit 7dc3b73

Browse files
authored
new(tests): EOF validation JUMPF stack overflow (#1269)
1 parent d27275d commit 7dc3b73

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

converted-ethereum-tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ EOFTests/efStack/backwards_rjump_.json
2020
EOFTests/efStack/backwards_rjump_variable_stack_.json
2121
EOFTests/efStack/backwards_rjumpi_.json
2222
EOFTests/efStack/backwards_rjumpi_variable_stack_.json
23+
EOFTests/efStack/jumpf_stack_overflow_.json
2324
EOFTests/efStack/forwards_rjump_.json
2425
EOFTests/efStack/forwards_rjump_variable_stack_.json
2526
EOFTests/efStack/forwards_rjumpi_.json

tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_jumpf_validation.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ethereum_test_tools.vm.opcode import Opcodes as Op
88

99
from .. import EOF_FORK_NAME
10+
from ..eip4750_functions.test_code_validation import MAX_RUNTIME_OPERAND_STACK_HEIGHT
1011

1112
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-6206.md"
1213
REFERENCE_SPEC_VERSION = "2f365ea0cd58faa6e26013ea77ce6d538175f7d0"
@@ -136,3 +137,46 @@ def test_returning_section_aborts_jumpf(
136137
],
137138
)
138139
eof_test(container=container)
140+
141+
142+
@pytest.mark.parametrize("stack_height", [512, 513, 1023])
143+
def test_jumpf_self_stack_overflow(eof_test: EOFTestFiller, stack_height: int):
144+
"""Test JUMPF instruction jumping to itself causing validation time stack overflow."""
145+
container = Container(
146+
sections=[
147+
Section.Code(
148+
code=(Op.PUSH0 * stack_height) + Op.JUMPF[0],
149+
max_stack_height=stack_height,
150+
),
151+
],
152+
)
153+
stack_overflow = stack_height > MAX_RUNTIME_OPERAND_STACK_HEIGHT // 2
154+
eof_test(
155+
container=container,
156+
expect_exception=EOFException.STACK_OVERFLOW if stack_overflow else None,
157+
)
158+
159+
160+
@pytest.mark.parametrize("stack_height_other", [1, 2, 512, 513, 1023])
161+
@pytest.mark.parametrize("stack_height", [1, 2, 512, 513, 1023])
162+
def test_jumpf_other_stack_overflow(
163+
eof_test: EOFTestFiller, stack_height: int, stack_height_other: int
164+
):
165+
"""Test JUMPF instruction jumping to itself causing validation time stack overflow."""
166+
container = Container(
167+
sections=[
168+
Section.Code(
169+
code=(Op.PUSH0 * stack_height) + Op.JUMPF[1],
170+
max_stack_height=stack_height,
171+
),
172+
Section.Code(
173+
code=(Op.PUSH0 * stack_height_other) + Op.STOP,
174+
max_stack_height=stack_height_other,
175+
),
176+
],
177+
)
178+
stack_overflow = stack_height + stack_height_other > MAX_RUNTIME_OPERAND_STACK_HEIGHT
179+
eof_test(
180+
container=container,
181+
expect_exception=EOFException.STACK_OVERFLOW if stack_overflow else None,
182+
)

tests/osaka/eip7692_eof_v1/eof_tracker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@
296296

297297
##### JUMPF
298298

299-
- [ ] Max allowed stack height reached in JUMPF-ed function (ethereum/tests: src/EOFTestsFiller/efStack/jumpf_stack_overflow_Copier.json)
300-
- [ ] JUMPF validation time stack overflow (ethereum/tests: src/EOFTestsFiller/efStack/jumpf_stack_overflow_Copier.json)
299+
- [x] Max allowed stack height reached in JUMPF-ed function ([`tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_jumpf_validation.py::test_jumpf_other_stack_overflow`](./eip6206_jumpf/test_jumpf_validation/test_jumpf_other_stack_overflow.md))
300+
- [x] JUMPF validation time stack overflow ([`tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_jumpf_validation.py::test_jumpf_other_stack_overflow`](./eip6206_jumpf/test_jumpf_validation/test_jumpf_other_stack_overflow.md))
301301
- [ ] Max allowed stack height reached in JUMPF-ed function with inputs
302302
- [ ] JUMPF validation time stack overflow in function with inputs (ethereum/tests: src/EOFTestsFiller/efStack/jumpf_with_inputs_stack_overflow_Copier.json)
303303
- [ ] JUMPF validation time stack overflow in function with inputs, variable stack segment, only max overflow (ethereum/tests: src/EOFTestsFiller/efStack/jumpf_with_inputs_stack_overflow_variable_stack_Copier.json)

0 commit comments

Comments
 (0)