Skip to content

Commit

Permalink
new(tests): unreachable EOF code sections
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Oct 1, 2024
1 parent 6968156 commit d7b6daf
Show file tree
Hide file tree
Showing 2 changed files with 84 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
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,87 @@ 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="xxxx",
sections=[
Section.Code(Op.INVALID),
Section.Code(Op.INVALID), # unreachable
],
),
Container(
name="xxxx",
sections=[
Section.Code(Op.CALLF[1] + Op.STOP),
Section.Code(Op.RETF, code_outputs=0),
Section.Code(Op.INVALID), # unreachable
],
),
Container(
name="xxxx",
sections=[
Section.Code(Op.CALLF[2] + Op.STOP),
Section.Code(Op.INVALID), # unreachable
Section.Code(Op.RETF, code_outputs=0),
],
),
Container(
name="xxxx",
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[0]), # self-reference
Section.Code(Op.JUMPF[1]), # unreachable
],
),
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 d7b6daf

Please sign in to comment.