Skip to content

Commit 83942b0

Browse files
authored
new(tests): EOF: add tests for DATALOADN validation and execution (#1162)
1 parent 016bc4d commit 83942b0

File tree

4 files changed

+88
-13
lines changed

4 files changed

+88
-13
lines changed

converted-ethereum-tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ EOFTests/EIP3670/validInvalid.json
1616
EOFTests/EIP4200/validInvalid.json
1717
EOFTests/EIP4750/validInvalid.json
1818
EOFTests/efValidation/callf_into_nonreturning_.json
19+
EOFTests/efValidation/dataloadn_.json
1920
EOFTests/efValidation/EOF1_embedded_container_.json
2021
EOFTests/efValidation/EOF1_eofcreate_valid_.json
2122
EOFTests/efValidation/EOF1_callf_truncated_.json

tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@
8989
]
9090

9191
INVALID: List[Container] = [
92+
Container(
93+
name="DATALOADN_0_empty_data",
94+
sections=[
95+
Section.Code(
96+
code=Op.DATALOADN[0] + Op.POP + Op.STOP,
97+
),
98+
],
99+
validity_error=EOFException.INVALID_DATALOADN_INDEX,
100+
),
92101
Container(
93102
name="DATALOADN_max_empty_data",
94103
sections=[
@@ -98,6 +107,56 @@
98107
],
99108
validity_error=EOFException.INVALID_DATALOADN_INDEX,
100109
),
110+
Container(
111+
name="DATALOADN_1_over_data",
112+
sections=[
113+
Section.Code(
114+
code=Op.DATALOADN[1] + Op.POP + Op.STOP,
115+
),
116+
Section.Data(b"\x00"),
117+
],
118+
validity_error=EOFException.INVALID_DATALOADN_INDEX,
119+
),
120+
Container(
121+
name="DATALOADN_32_over_data",
122+
sections=[
123+
Section.Code(
124+
code=Op.DATALOADN[32] + Op.POP + Op.STOP,
125+
),
126+
Section.Data(b"\xda" * 32),
127+
],
128+
validity_error=EOFException.INVALID_DATALOADN_INDEX,
129+
),
130+
Container(
131+
name="DATALOADN_0_data_31",
132+
sections=[
133+
Section.Code(
134+
code=Op.DATALOADN[0] + Op.POP + Op.STOP,
135+
),
136+
Section.Data(b"\xda" * 31),
137+
],
138+
validity_error=EOFException.INVALID_DATALOADN_INDEX,
139+
),
140+
Container(
141+
name="DATALOADN_32_data_63",
142+
sections=[
143+
Section.Code(
144+
code=Op.DATALOADN[32] + Op.POP + Op.STOP,
145+
),
146+
Section.Data(b"\xda" * 63),
147+
],
148+
validity_error=EOFException.INVALID_DATALOADN_INDEX,
149+
),
150+
Container(
151+
name="DATALOADN_max_imm",
152+
sections=[
153+
Section.Code(
154+
code=Op.DATALOADN[0xFFFF] + Op.POP + Op.STOP,
155+
),
156+
Section.Data(b"\xda" * 32),
157+
],
158+
validity_error=EOFException.INVALID_DATALOADN_INDEX,
159+
),
101160
Container(
102161
name="DATALOADN_max_small_data",
103162
sections=[
@@ -143,14 +202,11 @@ def container_name(c: Container):
143202
VALID,
144203
ids=container_name,
145204
)
146-
def test_legacy_initcode_valid_eof_v1_contract(
205+
def test_valid_containers_with_data_section(
147206
eof_test: EOFTestFiller,
148207
container: Container,
149208
):
150-
"""
151-
Test creating various types of valid EOF V1 contracts using legacy
152-
initcode and a contract creating transaction.
153-
"""
209+
"""Test EOF validation of valid containers with data sections."""
154210
assert container.validity_error is None, (
155211
f"Valid container with validity error: {container.validity_error}"
156212
)
@@ -164,14 +220,11 @@ def test_legacy_initcode_valid_eof_v1_contract(
164220
INVALID,
165221
ids=container_name,
166222
)
167-
def test_legacy_initcode_invalid_eof_v1_contract(
223+
def test_invalid_containers_with_data_section(
168224
eof_test: EOFTestFiller,
169225
container: Container,
170226
):
171-
"""
172-
Test creating various types of valid EOF V1 contracts using legacy
173-
initcode and a contract creating transaction.
174-
"""
227+
"""Test EOF validation of invalid containers with data sections."""
175228
assert container.validity_error is not None, "Invalid container without validity error"
176229
eof_test(
177230
container=container,

tests/osaka/eip7692_eof_v1/eip7480_data_section/test_data_opcodes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
from ethereum_test_specs import EOFStateTestFiller
56
from ethereum_test_tools import Account, Alloc, Environment, StateTestFiller, Transaction
67
from ethereum_test_tools.eof.v1 import Container, Section
78
from ethereum_test_tools.vm.opcode import Opcodes as Op
@@ -14,6 +15,26 @@
1415
pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)
1516

1617

18+
@pytest.mark.parametrize("index", [0, 1, 31, 32, 33, 63, 64])
19+
@pytest.mark.parametrize("suffix_len", [0, 1, 31, 32, 24000])
20+
def test_dataloadn(eof_state_test: EOFStateTestFiller, index: int, suffix_len: int):
21+
"""Basic tests for DATALOADN execution."""
22+
sentinel = 0x8000000000000000000000000000000000000000000000000000000000000001
23+
eof_state_test(
24+
container=Container(
25+
sections=[
26+
Section.Code(
27+
Op.SSTORE(0, Op.DATALOADN[index]) + Op.STOP,
28+
),
29+
Section.Data(
30+
index * b"\xbe" + sentinel.to_bytes(32, byteorder="big") + suffix_len * b"\xaf"
31+
),
32+
],
33+
),
34+
container_post=Account(storage={0: sentinel}),
35+
)
36+
37+
1738
def create_data_test(offset: int, datasize: int):
1839
"""Generate data load operators test cases based on load offset and data section size."""
1940
data = b"".join(i.to_bytes(length=2, byteorder="big") for i in range(1, datasize // 2 + 1))

tests/osaka/eip7692_eof_v1/eof_tracker.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,10 @@
354354

355355
### Validation
356356

357-
- [ ] Valid DATALOADN with various offsets (ethereum/tests: src/EOFTestsFiller/efValidation/dataloadn_Copier.json)
357+
- [x] Valid DATALOADN with various offsets ([`tests/osaka/eip7692_eof_v1/eip7480_data_section/test_data_opcodes.py::test_dataloadn`](./eip7480_data_section/test_data_opcodes/test_dataloadn.md)
358358
- [x] Truncated DATALOADN immediate ([`tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py::test_dataloadn_truncated_immediate`](./eip7480_data_section/test_code_validation/test_dataloadn_truncated_immediate.md)
359-
- [ ] DATALOADN offset out of bounds (ethereum/tests: src/EOFTestsFiller/efValidation/dataloadn_Copier.json)
360-
- [ ] DATALOADN accessing not full word (ethereum/tests: src/EOFTestsFiller/efValidation/dataloadn_Copier.json)
359+
- [x] DATALOADN offset out of bounds ([`tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py::test_invalid_containers_with_data_section`](./eip7480_data_section/test_code_validation/test_invalid_containers_with_data_section.md)
360+
- [x] DATALOADN accessing not full word ([`tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py::test_invalid_containers_with_data_section`](./eip7480_data_section/test_code_validation/test_invalid_containers_with_data_section.md)
361361

362362
## EIP-663: SWAPN, DUPN and EXCHANGE instructions
363363

0 commit comments

Comments
 (0)