Skip to content

Commit 467a260

Browse files
gumb0chfast
authored andcommitted
new(tests): eip-7620: RETURNCONTRACT validation tests
1 parent 971fb0c commit 467a260

File tree

5 files changed

+160
-4
lines changed

5 files changed

+160
-4
lines changed

converted-ethereum-tests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
EOFTests/efValidation/EOF1_returncontract_invalid_.json
2+
EOFTests/efValidation/EOF1_returncontract_valid_.json

src/ethereum_test_tools/exceptions/evmone_exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class EvmoneExceptionMapper:
7777
ExceptionMessage(
7878
EOFException.CONTAINER_SIZE_ABOVE_LIMIT, "err: container_size_above_limit"
7979
),
80+
ExceptionMessage(
81+
EOFException.INVALID_CONTAINER_SECTION_INDEX, "err: invalid_container_section_index"
82+
),
8083
)
8184

8285
def __init__(self) -> None:

src/ethereum_test_tools/exceptions/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,10 @@ class EOFException(ExceptionBase):
696696
"""
697697
EOF container is above size limit
698698
"""
699+
INVALID_CONTAINER_SECTION_INDEX = auto()
700+
"""
701+
Instruction references container section that does not exist.
702+
"""
699703

700704

701705
"""
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""
2+
Tests for RETURNCONTRACT instruction validation
3+
"""
4+
5+
from ethereum_test_tools import EOFTestFiller
6+
from ethereum_test_tools.eof.v1 import Container, Section
7+
from ethereum_test_tools.exceptions import EOFException
8+
from ethereum_test_tools.vm.opcode import Opcodes as Op
9+
10+
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7620.md"
11+
REFERENCE_SPEC_VERSION = "f20b164b00ae5553f7536a6d7a83a0f254455e09"
12+
13+
14+
def test_returncontract_valid_index_0(
15+
eof_test: EOFTestFiller,
16+
):
17+
"""Deploy container index 0"""
18+
eof_test(
19+
data=Container(
20+
sections=[
21+
Section.Code(
22+
code=Op.RETURNCONTRACT[0](0, 0),
23+
),
24+
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])),
25+
],
26+
)
27+
)
28+
29+
30+
def test_returncontract_valid_index_1(
31+
eof_test: EOFTestFiller,
32+
):
33+
"""Deploy container index 1"""
34+
eof_test(
35+
data=Container(
36+
sections=[
37+
Section.Code(
38+
code=Op.RJUMPI[6](0) + Op.RETURNCONTRACT[0](0, 0) + Op.RETURNCONTRACT[1](0, 0),
39+
max_stack_height=2,
40+
),
41+
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])),
42+
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])),
43+
],
44+
)
45+
)
46+
47+
48+
def test_returncontract_valid_index_255(
49+
eof_test: EOFTestFiller,
50+
):
51+
"""Deploy container index 255"""
52+
eof_test(
53+
data=Container(
54+
sections=[
55+
Section.Code(
56+
sum((Op.RJUMPI[6](0) + Op.RETURNCONTRACT[i](0, 0)) for i in range(256))
57+
+ Op.REVERT(0, 0),
58+
max_stack_height=2,
59+
)
60+
]
61+
+ [Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)]))]
62+
* 256
63+
)
64+
)
65+
66+
67+
def test_returncontract_invalid_truncated_immediate(
68+
eof_test: EOFTestFiller,
69+
):
70+
"""Truncated immediate"""
71+
eof_test(
72+
data=Container(
73+
sections=[
74+
Section.Code(
75+
code=Op.PUSH0 + Op.PUSH0 + Op.RETURNCONTRACT,
76+
),
77+
],
78+
),
79+
expect_exception=EOFException.TRUNCATED_INSTRUCTION,
80+
)
81+
82+
83+
def test_returncontract_invalid_index_0(
84+
eof_test: EOFTestFiller,
85+
):
86+
"""Referring to non-existent container section index 0"""
87+
eof_test(
88+
data=Container(
89+
sections=[
90+
Section.Code(
91+
code=Op.RETURNCONTRACT[0](0, 0),
92+
),
93+
],
94+
),
95+
expect_exception=EOFException.INVALID_CONTAINER_SECTION_INDEX,
96+
)
97+
98+
99+
def test_returncontract_invalid_index_1(
100+
eof_test: EOFTestFiller,
101+
):
102+
"""Referring to non-existent container section index 1"""
103+
eof_test(
104+
data=Container(
105+
sections=[
106+
Section.Code(
107+
code=Op.RETURNCONTRACT[1](0, 0),
108+
),
109+
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])),
110+
],
111+
),
112+
expect_exception=EOFException.INVALID_CONTAINER_SECTION_INDEX,
113+
)
114+
115+
116+
def test_returncontract_invalid_index_255(
117+
eof_test: EOFTestFiller,
118+
):
119+
"""Referring to non-existent container section index 255"""
120+
eof_test(
121+
data=Container(
122+
sections=[
123+
Section.Code(
124+
code=Op.RETURNCONTRACT[255](0, 0),
125+
),
126+
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])),
127+
],
128+
),
129+
expect_exception=EOFException.INVALID_CONTAINER_SECTION_INDEX,
130+
)
131+
132+
133+
def test_returncontract_terminating(
134+
eof_test: EOFTestFiller,
135+
):
136+
"""Unreachable code after RETURNCONTRACT"""
137+
eof_test(
138+
data=Container(
139+
sections=[
140+
Section.Code(
141+
code=Op.RETURNCONTRACT[0](0, 0) + Op.REVERT(0, 0),
142+
),
143+
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])),
144+
],
145+
),
146+
expect_exception=EOFException.UNREACHABLE_INSTRUCTIONS,
147+
)

tests/prague/eip7692_eof_v1/tracker.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@
219219
- [ ] EOFCREATE is not a valid terminating instruction (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_eofcreate_invalid_Copier.json)
220220
- [ ] EOFCREATE immediate referring to non-existing container (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_eofcreate_invalid_Copier.json)
221221
- [ ] EOFCREATE immediate referring to container with truncated data (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_eofcreate_invalid_Copier.json)
222-
- [ ] Valid RETURNCONTRACTs referring to various container numbers (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_returncontract_valid_Copier.json)
223-
- [ ] Truncated before RETURNCONTRACT immediate (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_returncontract_invalid_Copier.json)
224-
- [ ] RETURNCONTRACT immediate referring to non-existing container (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_returncontract_invalid_Copier.json)
225-
- [ ] Unreachable code after RETURNCONTRACT, check that RETURNCONTRACT is terminating (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_returncontract_invalid_Copier.json)
222+
- [x] Valid RETURNCONTRACTs referring to various container numbers (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_returncontract_valid_Copier.json)
223+
- [x] Truncated before RETURNCONTRACT immediate (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_returncontract_invalid_Copier.json)
224+
- [x] RETURNCONTRACT immediate referring to non-existing container (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_returncontract_invalid_Copier.json)
225+
- [x] Unreachable code after RETURNCONTRACT, check that RETURNCONTRACT is terminating (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_returncontract_invalid_Copier.json)
226226

227227
## EIP-7698: EOF - Creation transaction

0 commit comments

Comments
 (0)