Skip to content

Commit 8513a8e

Browse files
authored
new(tests): Add tests for ambiguous subcontainer kind (#1266)
Test EOF validation of ambiguous container kind: a single subcontainer reference by both EOFCREATE and RETURNCONTRACT.
1 parent 7dc3b73 commit 8513a8e

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

src/ethereum_clis/clis/evmone.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ def _mapping_data(self):
187187
ExceptionMessage(
188188
EOFException.INCOMPATIBLE_CONTAINER_KIND, "err: incompatible_container_kind"
189189
),
190+
ExceptionMessage(
191+
EOFException.AMBIGUOUS_CONTAINER_KIND, "err: ambiguous_container_kind"
192+
),
190193
ExceptionMessage(EOFException.STACK_HEIGHT_MISMATCH, "err: stack_height_mismatch"),
191194
ExceptionMessage(EOFException.TOO_MANY_CONTAINERS, "err: too_many_container_sections"),
192195
ExceptionMessage(

src/ethereum_test_exceptions/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,10 @@ class EOFException(ExceptionBase):
742742
"""
743743
Incompatible instruction found in a container of a specific kind.
744744
"""
745+
AMBIGUOUS_CONTAINER_KIND = auto()
746+
"""
747+
The kind of a sub-container cannot be uniquely deduced.
748+
"""
745749
TOO_MANY_CONTAINERS = auto()
746750
"""
747751
EOF container header has too many sub-containers.

tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_subcontainer_validation.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
stop_sub_container = Section.Container(stop_container)
3232
return_sub_container = Section.Container(Container.Code(Op.RETURN(0, 0)))
3333
revert_sub_container = Section.Container(Container.Code(Op.REVERT(0, 0)))
34+
abort_sub_container = Section.Container(Container.Code(Op.INVALID))
3435
returncontract_sub_container = Section.Container(
3536
Container(
3637
sections=[
@@ -447,6 +448,41 @@ def test_container_both_kinds_same_sub(eof_test: EOFTestFiller):
447448
)
448449

449450

451+
@pytest.mark.parametrize("container_idx", [0, 1, 255])
452+
@pytest.mark.parametrize(
453+
"sub_container",
454+
[
455+
pytest.param(abort_sub_container, id="abort"),
456+
pytest.param(revert_sub_container, id="revert"),
457+
],
458+
)
459+
def test_container_ambiguous_kind(
460+
eof_test: EOFTestFiller, container_idx: int, sub_container: Section
461+
):
462+
"""
463+
Test ambiguous container kind:
464+
a single subcontainer reference by both EOFCREATE and RETURNCONTRACT.
465+
"""
466+
sections = [
467+
Section.Code(
468+
code=(
469+
sum(Op.EOFCREATE[i](0, 0, 0, 0) for i in range(container_idx))
470+
+ Op.EOFCREATE[container_idx](0, 0, 0, 0)
471+
+ Op.RETURNCONTRACT[container_idx](0, 0)
472+
),
473+
),
474+
]
475+
sections += (container_idx + 1) * [sub_container]
476+
477+
eof_test(
478+
container=Container(
479+
sections=sections,
480+
kind=ContainerKind.INITCODE,
481+
),
482+
expect_exception=EOFException.AMBIGUOUS_CONTAINER_KIND,
483+
)
484+
485+
450486
def test_container_both_kinds_different_sub(eof_test: EOFTestFiller):
451487
"""Test multiple kinds of subcontainer at the same level."""
452488
eof_test(
@@ -715,7 +751,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
715751
+ Op.POP
716752
+ Op.STOP
717753
),
718-
Section.Container(Container.Code(Op.INVALID)),
754+
abort_sub_container,
719755
],
720756
expected_bytecode="""
721757
ef0001010004020001000b0300010014040000000080000436600060ff6000ec005000ef000101000402
@@ -727,7 +763,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
727763
Container(
728764
sections=[
729765
Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP),
730-
Section.Container(Container.Code(Op.INVALID)),
766+
abort_sub_container,
731767
],
732768
expected_bytecode="""
733769
ef00010100040200010006030001001404000000008000016000e0000000ef0001010004020001000104
@@ -742,7 +778,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
742778
Container(
743779
sections=[
744780
Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP),
745-
Section.Container(Container.Code(Op.INVALID)),
781+
abort_sub_container,
746782
Section.Data(custom_size=2),
747783
],
748784
expected_bytecode="""
@@ -758,7 +794,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
758794
Container(
759795
sections=[
760796
Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP),
761-
Section.Container(Container.Code(Op.INVALID)),
797+
abort_sub_container,
762798
Section.Data("aabb"),
763799
],
764800
expected_bytecode="""
@@ -794,7 +830,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
794830
+ Op.STOP
795831
)
796832
]
797-
+ 2 * [Section.Container(Container.Code(Op.INVALID))],
833+
+ 2 * [abort_sub_container],
798834
expected_bytecode="""
799835
ef0001010004020001000b03000200140014040000000080000436600060ff6000ec015000ef00010100
800836
0402000100010400000000800000feef000101000402000100010400000000800000fe""",
@@ -808,7 +844,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
808844
Container(
809845
sections=[
810846
Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP),
811-
Section.Container(Container.Code(Op.INVALID)),
847+
abort_sub_container,
812848
Section.Container(Container.Code(Op.PUSH0 + Op.PUSH0 + Op.RETURN)),
813849
],
814850
expected_bytecode="""
@@ -833,7 +869,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
833869
+ Op.STOP
834870
)
835871
]
836-
+ 256 * [Section.Container(Container.Code(Op.INVALID))],
872+
+ 256 * [abort_sub_container],
837873
# Originally this test was "valid" because it was created
838874
# before "orphan subcontainer" rule was introduced.
839875
validity_error=EOFException.ORPHAN_SUBCONTAINER,
@@ -843,7 +879,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
843879
pytest.param(
844880
Container(
845881
sections=[Section.Code(Op.PUSH1[0] + Op.RJUMP[0] + Op.STOP)]
846-
+ 256 * [Section.Container(Container.Code(Op.INVALID))],
882+
+ 256 * [abort_sub_container],
847883
# Originally this test was "valid" because it was created
848884
# before "orphan subcontainer" rule was introduced.
849885
validity_error=EOFException.ORPHAN_SUBCONTAINER,

0 commit comments

Comments
 (0)