Skip to content

Commit 4c3353c

Browse files
chfastmarioevz
andauthored
refactor(tests,tw): EOF - Top-level container must not be truncated (#613)
* feat(tests,tw): Top-level EOF container must not be truncated We are changing the EOF validation API (e.g. eofparse, EOF validation tests): the top-level EOF container must not have truncated/missing data section. This is how you would validate "genesis" EOF containers and is also less confusing for EOF tool users. This change introduces new error kind: `TOPLEVEL_CONTAINER_TRUNCATED` and matches the recent change in evmone. * Update tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_example_valid_invalid.py --------- Co-authored-by: Mario Vega <[email protected]>
1 parent de57ee5 commit 4c3353c

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

src/ethereum_test_tools/exceptions/evmone_exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class EvmoneExceptionMapper:
7070
ExceptionMessage(EOFException.INVALID_MAX_STACK_HEIGHT, "err: invalid_max_stack_height"),
7171
ExceptionMessage(EOFException.INVALID_DATALOADN_INDEX, "err: invalid_dataloadn_index"),
7272
ExceptionMessage(EOFException.TRUNCATED_INSTRUCTION, "err: truncated_instruction"),
73+
ExceptionMessage(
74+
EOFException.TOPLEVEL_CONTAINER_TRUNCATED, "err: toplevel_container_truncated"
75+
),
7376
)
7477

7578
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
@@ -684,6 +684,10 @@ class EOFException(ExceptionBase):
684684
"""
685685
EOF container's code section has truncated instruction.
686686
"""
687+
TOPLEVEL_CONTAINER_TRUNCATED = auto()
688+
"""
689+
Top-level EOF container has data section truncated
690+
"""
687691

688692

689693
"""

tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,6 @@
2727
Section.Data(data="0x00"),
2828
],
2929
),
30-
Container(
31-
# EOF allows truncated data section
32-
name="no_data_section_contents",
33-
sections=[
34-
Section.Code(Op.STOP),
35-
Section.Data(data="0x", custom_size=1),
36-
],
37-
code="ef0001 010004 0200010001 040001 00 00800000 00",
38-
),
39-
Container(
40-
# EOF allows truncated data section
41-
name="data_section_contents_incomplete",
42-
sections=[
43-
Section.Code(Op.STOP),
44-
Section.Data(data="0xAABBCC", custom_size=4),
45-
],
46-
),
4730
Container(
4831
name="max_code_sections",
4932
sections=[
@@ -331,6 +314,23 @@
331314
# TODO the exception must be about code section EOFException.INVALID_CODE_SECTION,
332315
validity_error=EOFException.ZERO_SECTION_SIZE,
333316
),
317+
Container(
318+
name="no_data_section_contents",
319+
sections=[
320+
Section.Code(Op.STOP),
321+
Section.Data(data="0x", custom_size=1),
322+
],
323+
code="ef0001 010004 0200010001 040001 00 00800000 00",
324+
validity_error=EOFException.TOPLEVEL_CONTAINER_TRUNCATED,
325+
),
326+
Container(
327+
name="data_section_contents_incomplete",
328+
sections=[
329+
Section.Code(Op.STOP),
330+
Section.Data(data="0xAABBCC", custom_size=4),
331+
],
332+
validity_error=EOFException.TOPLEVEL_CONTAINER_TRUNCATED,
333+
),
334334
Container(
335335
name="data_section_preceding_code_section",
336336
auto_data_section=False,

tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_example_valid_invalid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
],
5050
),
5151
"ef0001010004020001000304000400008000013050000bad",
52-
None,
53-
id="undersize_data_ok",
52+
EOFException.TOPLEVEL_CONTAINER_TRUNCATED,
53+
id="undersize_data_not_ok_on_toplevel_container",
5454
),
5555
pytest.param(
5656
# Check that EOF1 with too many or too few bytes fails

whitelist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ time15k
343343
timestamp
344344
todo
345345
toml
346+
toplevel
346347
tox
347348
Tox
348349
traceback

0 commit comments

Comments
 (0)