Skip to content

Commit

Permalink
new(tests): unreachable EOF code sections
Browse files Browse the repository at this point in the history
This migrates tests for unreachable code sections from
EOFTests/efValidation/unreachable_code_sections_.json
but also complements test cases with focus on containers where
each section is referenced by some section but some are not reachable
from section 0.
  • Loading branch information
chfast committed Oct 1, 2024
1 parent 1675bda commit 8750cb2
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 5 deletions.
1 change: 1 addition & 0 deletions converted-ethereum-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ EOFTests/efValidation/EOF1_embedded_container_.json
EOFTests/efValidation/EOF1_eofcreate_valid_.json
EOFTests/efValidation/EOF1_section_order_.json
EOFTests/efValidation/EOF1_truncated_section_.json
EOFTests/efValidation/unreachable_code_sections_.json

([#647](https://github.com/ethereum/execution-spec-tests/pull/647))
EOFTests/efValidation/EOF1_returncontract_invalid_.json
Expand Down
171 changes: 166 additions & 5 deletions tests/prague/eip7692_eof_v1/eip4750_functions/test_code_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,170 @@ def test_eof_validity(
container: Container,
):
"""
Test EOF container validaiton for features around EIP-4750 / Functions / Code Sections
Test EOF container validation for features around EIP-4750 / Functions / Code Sections
"""
eof_test(
data=bytes(container),
expect_exception=container.validity_error,
)
eof_test(data=container)


@pytest.mark.parametrize(
"container",
[
Container(
name="unreachable1",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.INVALID), # unreachable
],
),
Container(
name="unreachable1_selfjumpf",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.JUMPF[1]), # unreachable
],
),
Container(
name="unreachable1_selfcallf",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.CALLF[1] + Op.STOP), # unreachable
],
),
Container(
name="unreachable1_jumpf0",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.JUMPF[0]), # unreachable
],
),
Container(
name="unreachable1_callf0",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.CALLF[0] + Op.STOP), # unreachable
],
),
Container(
name="unreachable1_selfcall_jumpf0",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.CALLF[1] + Op.JUMPF[0]), # unreachable
],
),
Container(
name="unreachable12_of3_2jumpf1",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.STOP), # unreachable
Section.Code(Op.JUMPF[1]), # unreachable
],
),
Container(
name="unreachable12_of3_2callf1",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.STOP), # unreachable
Section.Code(Op.CALLF[1] + Op.STOP), # unreachable
],
),
Container(
name="unreachable12_of3_jumpf_loop",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.JUMPF[2]), # unreachable
Section.Code(Op.JUMPF[1]), # unreachable
],
),
Container(
name="unreachable12_of3_callf_loop_stop",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.CALLF[2] + Op.STOP), # unreachable
Section.Code(Op.CALLF[1] + Op.STOP), # unreachable
],
),
Container(
name="unreachable12_of3_callf_loop_retf",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.CALLF[2] + Op.RETF, code_outputs=0), # unreachable
Section.Code(Op.CALLF[1] + Op.RETF, code_outputs=0), # unreachable
],
),
Container(
name="unreachable12_of3_callf_loop_mixed",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.CALLF[2] + Op.STOP), # unreachable
Section.Code(Op.CALLF[1] + Op.RETF, code_outputs=0), # unreachable
],
),
Container(
name="selfjumpf0_unreachable1",
sections=[
Section.Code(Op.JUMPF[0]), # self-reference
Section.Code(Op.JUMPF[1]), # unreachable
],
),
Container(
name="unreachable2_of3",
sections=[
Section.Code(Op.CALLF[1] + Op.STOP),
Section.Code(Op.RETF, code_outputs=0),
Section.Code(Op.INVALID), # unreachable
],
),
Container(
name="unreachable1_of3",
sections=[
Section.Code(Op.CALLF[2] + Op.STOP),
Section.Code(Op.INVALID), # unreachable
Section.Code(Op.RETF, code_outputs=0),
],
),
Container(
name="unreachable1_of4",
sections=[
Section.Code(Op.CALLF[3] + Op.STOP),
Section.Code(Op.INVALID), # unreachable
Section.Code(Op.RETF, code_outputs=0),
Section.Code(Op.CALLF[2] + Op.RETF, code_outputs=0),
],
),
Container(
name="xxxx",
sections=[
Section.Code(Op.JUMPF[1]),
Section.Code(Op.STOP),
Section.Code(Op.RETF, code_outputs=0),
],
),
Container(
name="xxxx",
sections=[
Section.Code(Op.JUMPF[1]),
Section.Code(Op.JUMPF[1]), # self-reference
]
+ [Section.Code(Op.JUMPF[i]) for i in range(3, 255)] # unreachable
+ [Section.Code(Op.STOP)], # unreachable
),
Container(
name="xxxx",
sections=[Section.Code(Op.JUMPF[i]) for i in range(1, 255)]
+ [
Section.Code(Op.JUMPF[254]), # self-reference
Section.Code(Op.STOP), # unreachable
],
),
],
ids=container_name,
)
def test_unreachable_code_sections(
eof_test: EOFTestFiller,
container: Container,
):
"""
Test cases for EOF unreachable code sections
(i.e. code sections not reachable from the code section 0).
"""
eof_test(data=container, expect_exception=EOFException.UNREACHABLE_CODE_SECTIONS)

0 comments on commit 8750cb2

Please sign in to comment.