Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(tests): EOF - EIP-6206: Runtime stack overflow at JUMPF #690

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Test fixtures for use by clients are available for each release on the [Github r
- ✨ Convert a few eip1153 tests from ethereum/tests repo into .py ([#440](https://github.com/ethereum/execution-spec-tests/pull/440)).
- ✨ 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)).
- ✨ 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)).
- ✨ 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)).
- ✨ 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)).
- ✨ 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)).

### πŸ› οΈ Framework

Expand Down
192 changes: 192 additions & 0 deletions tests/prague/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""
EOF JUMPF tests covering simple cases.
"""

import pytest

from ethereum_test_tools import Account, EOFException, EOFStateTestFiller
from ethereum_test_tools.eof.v1 import Container, Section
from ethereum_test_tools.eof.v1.constants import NON_RETURNING_SECTION
from ethereum_test_tools.vm.opcode import Opcodes as Op

from .. import EOF_FORK_NAME
Expand Down Expand Up @@ -149,3 +151,193 @@ def test_callf_to_non_returning_section(
validity_error=EOFException.MISSING_STOP_OPCODE,
),
)


def test_jumpf_stack_size_1024(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in target function of JUMPF"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1022 + Op.JUMPF[1],
max_stack_height=1022,
),
Section.Code(
Op.SSTORE(slot_code_worked, value_code_worked) + Op.STOP,
code_inputs=0,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=2,
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_jumpf_with_inputs_stack_size_1024(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in target function of JUMPF with inputs"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1022 + Op.JUMPF[1],
max_stack_height=1022,
),
Section.Code(
Op.SSTORE(slot_code_worked, value_code_worked) + Op.STOP,
code_inputs=3,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=5,
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_jumpf_stack_size_1024_at_push(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in JUMPF target function at PUSH0 instruction"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1023,
),
Section.Code(
# stack has 1023 items
Op.JUMPF[2],
code_inputs=0,
code_outputs=0,
max_stack_height=0,
),
Section.Code(
Op.PUSH0 +
# stack has 1024 items
Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
marioevz marked this conversation as resolved.
Show resolved Hide resolved
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_jumpf_stack_overflow(
eof_state_test: EOFStateTestFiller,
):
"""Test stack overflowing 1024 items in JUMPF target function"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1023,
),
Section.Code(
# Stack has 1023 items
Op.JUMPF[2],
code_inputs=0,
code_outputs=0,
max_stack_height=0,
),
Section.Code(
Op.PUSH0 + Op.PUSH0 +
# Runtime stack overflow
Op.POP + Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=2,
),
],
),
container_post=Account(storage={slot_code_worked: 0}),
)


def test_jumpf_with_inputs_stack_size_1024_at_push(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in JUMPF target function with inputs at PUSH0 instruction"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1023,
),
Section.Code(
# Stack has 1023 items
Op.JUMPF[2],
code_inputs=3,
code_outputs=3,
max_stack_height=3,
),
Section.Code(
Op.PUSH0 +
# Stack has 1024 items
Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_jumpf_with_inputs_stack_overflow(
eof_state_test: EOFStateTestFiller,
):
"""Test stack overflowing 1024 items in JUMPF target function with inputs"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1023,
),
Section.Code(
# Stack has 1023 items
Op.JUMPF[2],
code_inputs=3,
code_outputs=3,
max_stack_height=3,
),
Section.Code(
Op.PUSH0 + Op.PUSH0 +
# Runtime stackoverflow
Op.POP + Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=5,
),
],
),
container_post=Account(storage={slot_code_worked: 0}),
)