Skip to content

Commit 5d50fc2

Browse files
gumb0shemnon
andauthored
fix(tests): EOF - Change container section size to 4 bytes (#1403)
Convert EOF tests to the new spec where the container sizes are 4-byte long. Add a constant, wire it through imports, and use it in list_header. Add new tests with higher 16 bits set in containers size. Add more cases for incomplete container section size. Add case for subcontainer with 2-byte size. Co-authored-by: Danno Ferrin <danno@numisight.com>
1 parent 370572b commit 5d50fc2

File tree

8 files changed

+79
-33
lines changed

8 files changed

+79
-33
lines changed

src/ethereum_test_tools/eof/v1/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Mirror module to import `ethereum_test_types.eof.v1.constants`."""
22

33
from ethereum_test_types.eof.v1.constants import (
4+
HEADER_SECTION_CONTAINER_SIZE_BYTE_LENGTH,
45
HEADER_SECTION_COUNT_BYTE_LENGTH,
56
HEADER_SECTION_KIND_BYTE_LENGTH,
67
HEADER_SECTION_SIZE_BYTE_LENGTH,
@@ -24,6 +25,7 @@
2425
"HEADER_SECTION_COUNT_BYTE_LENGTH",
2526
"HEADER_SECTION_KIND_BYTE_LENGTH",
2627
"HEADER_SECTION_SIZE_BYTE_LENGTH",
28+
"HEADER_SECTION_CONTAINER_SIZE_BYTE_LENGTH",
2729
"MAX_BYTECODE_SIZE",
2830
"MAX_CODE_INPUTS",
2931
"MAX_CODE_OUTPUTS",

src/ethereum_test_types/eof/v1/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from ..constants import EOF_HEADER_TERMINATOR, EOF_MAGIC
2323
from .constants import (
24+
HEADER_SECTION_CONTAINER_SIZE_BYTE_LENGTH,
2425
HEADER_SECTION_COUNT_BYTE_LENGTH,
2526
HEADER_SECTION_KIND_BYTE_LENGTH,
2627
HEADER_SECTION_SIZE_BYTE_LENGTH,
@@ -251,7 +252,12 @@ def list_header(sections: List["Section"]) -> bytes:
251252
if cs.skip_header_listing:
252253
continue
253254
size = cs.custom_size if "custom_size" in cs.model_fields_set else len(cs.data)
254-
h += size.to_bytes(HEADER_SECTION_SIZE_BYTE_LENGTH, "big")
255+
body_size_length = (
256+
HEADER_SECTION_SIZE_BYTE_LENGTH
257+
if cs.kind != SectionKind.CONTAINER
258+
else HEADER_SECTION_CONTAINER_SIZE_BYTE_LENGTH
259+
)
260+
h += size.to_bytes(body_size_length, "big")
255261

256262
return h
257263

src/ethereum_test_types/eof/v1/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
HEADER_SECTION_SIZE_BYTE_LENGTH = 2
3535

36+
HEADER_SECTION_CONTAINER_SIZE_BYTE_LENGTH = 4
37+
3638
TYPES_INPUTS_BYTE_LENGTH = 1
3739

3840
TYPES_OUTPUTS_BYTE_LENGTH = 1

src/ethereum_test_types/tests/test_eof_v1.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Section.Container("0x0B"),
3838
],
3939
),
40-
"ef0001 01 0004 02 0001 0001 03 0001 0001 ff 0000 00 00800000 0A 0B",
40+
"ef0001 01 0004 02 0001 0001 03 0001 00000001 ff 0000 00 00800000 0A 0B",
4141
),
4242
(
4343
"Single code section, single container section, single data",
@@ -48,7 +48,7 @@
4848
Section.Data("0x0C"),
4949
],
5050
),
51-
"ef0001 01 0004 02 0001 0001 03 0001 0001 ff 0001 00 00800000 0A 0B 0C",
51+
"ef0001 01 0004 02 0001 0001 03 0001 00000001 ff 0001 00 00800000 0A 0B 0C",
5252
),
5353
(
5454
"Single code section, single container section, single data 2",
@@ -59,7 +59,7 @@
5959
Section.Container("0x0B"),
6060
],
6161
),
62-
"ef0001 01 0004 02 0001 0001 03 0001 0001 ff 0001 00 00800000 0A 0B 0C",
62+
"ef0001 01 0004 02 0001 0001 03 0001 00000001 ff 0001 00 00800000 0A 0B 0C",
6363
),
6464
(
6565
"Single code section, multiple container section, single data",
@@ -71,7 +71,7 @@
7171
Section.Container("0x0D"),
7272
],
7373
),
74-
"ef0001 01 0004 02 0001 0001 03 0002 0001 0001 ff 0001 00 00800000 0A 0B 0D 0C",
74+
"ef0001 01 0004 02 0001 0001 03 0002 00000001 00000001 ff 0001 00 00800000 0A 0B 0D 0C",
7575
),
7676
(
7777
"Single code section, multiple container sections",
@@ -82,7 +82,7 @@
8282
Section.Container("0x00"),
8383
],
8484
),
85-
"ef0001 01 0004 02 0001 0001 03 0002 0002 0001 ff 0000 00 00800000 00 0001 00",
85+
"ef0001 01 0004 02 0001 0001 03 0002 00000002 00000001 ff 0000 00 00800000 00 0001 00",
8686
),
8787
(
8888
"No code section",
@@ -188,7 +188,7 @@
188188
),
189189
],
190190
),
191-
"ef0001 01 0004 02 0001 0001 03 0001 0014 ff 0000 00 00800000 00"
191+
"ef0001 01 0004 02 0001 0001 03 0001 00000014 ff 0000 00 00800000 00"
192192
"ef0001 01 0004 02 0001 0001 ff 0000 00 00800000 01",
193193
),
194194
(
@@ -785,7 +785,7 @@
785785
020001 # One code segment
786786
0006 # code seg 0: 6 bytes
787787
030001 # One container segment
788-
0014 # container seg 0: 20 bytes
788+
00000014 # container seg 0: 20 bytes
789789
ff0000 # Zero byte data segment
790790
00 # End of header
791791
0080 0002 # Types section
@@ -815,7 +815,7 @@
815815
020001 # One code segment
816816
000b # code seg 0: 11 bytes
817817
030001 # One container segment
818-
0014 # container seg 0: 20 bytes
818+
00000014 # container seg 0: 20 bytes
819819
ff0000 # Zero byte data segment
820820
00 # End of header
821821
0080 0002 # Types section

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_container_validation.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -338,32 +338,59 @@ def test_valid_containers(
338338
),
339339
Container(
340340
name="incomplete_container_section_size_2",
341-
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0002 0001",
341+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 0000",
342342
validity_error=EOFException.INCOMPLETE_SECTION_SIZE,
343343
),
344344
Container(
345345
name="incomplete_container_section_size_3",
346-
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0002 0001 00",
346+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 000000",
347+
validity_error=EOFException.INCOMPLETE_SECTION_SIZE,
348+
),
349+
Container(
350+
name="incomplete_container_section_size_4",
351+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0002 00000001",
352+
validity_error=EOFException.INCOMPLETE_SECTION_SIZE,
353+
),
354+
Container(
355+
name="incomplete_container_section_size_5",
356+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0002 00000001 00",
357+
validity_error=EOFException.INCOMPLETE_SECTION_SIZE,
358+
),
359+
Container(
360+
name="incomplete_container_section_size_6",
361+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0002 00000001 0000",
362+
validity_error=EOFException.INCOMPLETE_SECTION_SIZE,
363+
),
364+
Container(
365+
name="incomplete_container_section_size_7",
366+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0002 00000001 000000",
347367
validity_error=EOFException.INCOMPLETE_SECTION_SIZE,
348368
),
349369
Container(
350370
name="zero_size_container_section",
351-
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 0000 ff 0000 00 00800000 00",
371+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 00000000 ff 0000 00 00800000 00",
352372
validity_error=EOFException.ZERO_SECTION_SIZE,
353373
),
374+
Container(
375+
name="container_section_size_2bytes",
376+
raw_bytes="ef00 01 01 0004 02 0001 000b 03 0001 0014 ff 0000 00 00800004"
377+
"6000600060006000ec0000"
378+
"ef00 01 01 0004 02 0001 0001 ff 0000 00 00800000 fe",
379+
validity_error=EOFException.MISSING_DATA_SECTION,
380+
),
354381
Container(
355382
name="truncated_header_data_section_with_container_section",
356-
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 0001",
383+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 00000001",
357384
validity_error=EOFException.MISSING_HEADERS_TERMINATOR,
358385
),
359386
Container(
360387
name="no_data_section_size_with_container_section",
361-
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 0001 ff",
388+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 00000001 ff",
362389
validity_error=EOFException.MISSING_HEADERS_TERMINATOR,
363390
),
364391
Container(
365392
name="data_section_size_incomplete_with_container_section",
366-
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 0001 ff 00",
393+
raw_bytes="ef00 01 01 0004 02 0001 0001 03 0001 00000001 ff 00",
367394
validity_error=EOFException.INCOMPLETE_SECTION_SIZE,
368395
),
369396
Container(
@@ -793,7 +820,7 @@ def test_valid_containers(
793820
],
794821
auto_sort_sections=AutoSection.ONLY_BODY,
795822
expected_bytecode=(
796-
"ef00 01 01 0004 02 0001 0015 03 0001 0014 ff 0001 03 0001 0014 00"
823+
"ef00 01 01 0004 02 0001 0015 03 0001 00000014 ff 0001 03 0001 00000014 00"
797824
"00800005 6000600060006000ec00 6000600060006000ec01 00"
798825
"ef00 01 01 0004 02 0001 0001 ff 0000 00 00800000 fe"
799826
"ef00 01 01 0004 02 0001 0001 ff 0000 00 00800000 fe"
@@ -811,7 +838,7 @@ def test_valid_containers(
811838
],
812839
skip_join_concurrent_sections_in_header=True,
813840
expected_bytecode=(
814-
"ef00 01 01 0004 02 0001 0015 03 0001 0014 03 0001 0014 ff 0001 00"
841+
"ef00 01 01 0004 02 0001 0015 03 0001 00000014 03 0001 00000014 ff 0001 00"
815842
"00800005 6000600060006000ec00 6000600060006000ec01 00"
816843
"ef00 01 01 0004 02 0001 0001 ff 0000 00 00800000 fe"
817844
"ef00 01 01 0004 02 0001 0001 ff 0000 00 00800000 fe"
@@ -832,7 +859,7 @@ def test_valid_containers(
832859
],
833860
skip_join_concurrent_sections_in_header=True,
834861
expected_bytecode=(
835-
"ef00 01 01 0004 02 0001 000b 03 0001 0014 03 0001 0014 ff 0001 00"
862+
"ef00 01 01 0004 02 0001 000b 03 0001 00000014 03 0001 00000014 ff 0001 00"
836863
"00800004 6000600060006000ec00 00"
837864
"ef00 01 01 0004 02 0001 0001 ff 0000 00 00800000 fe"
838865
"aa"
@@ -917,8 +944,8 @@ def test_valid_containers(
917944
),
918945
],
919946
auto_type_section=AutoSection.NONE,
920-
expected_bytecode="ef0001 020001 0001 030001 0032 ff0000 00 fe"
921-
"ef0001 010004 020001 0006 030001 0014 ff0000 00 00800002 60006000ee00"
947+
expected_bytecode="ef0001 020001 0001 030001 00000034 ff0000 00 fe"
948+
"ef0001 010004 020001 0006 030001 00000014 ff0000 00 00800002 60006000ee00"
922949
"ef0001 010004 020001 0001 ff0000 00 0080000000",
923950
validity_error=[EOFException.MISSING_TYPE_HEADER, EOFException.UNEXPECTED_HEADER_KIND],
924951
),

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_section_size.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class SectionSize(IntEnum):
2626
OVERSIZE = 100
2727
HUGE = 0x8000
2828
MAX = 0xFFFF
29+
CONTAINER_BIG = 0x00010000
30+
CONTAINER_MAX = 0xFFFFFFFF
2931

3032
def __str__(self) -> str:
3133
"""Return string representation of the section kind."""
@@ -98,7 +100,14 @@ def __str__(self) -> str:
98100
SectionKind.CONTAINER, SectionSize.HUGE, EOFException.INVALID_SECTION_BODIES_SIZE
99101
),
100102
pytest.param(
101-
SectionKind.CONTAINER, SectionSize.MAX, EOFException.INVALID_SECTION_BODIES_SIZE
103+
SectionKind.CONTAINER,
104+
SectionSize.CONTAINER_BIG,
105+
EOFException.INVALID_SECTION_BODIES_SIZE,
106+
),
107+
pytest.param(
108+
SectionKind.CONTAINER,
109+
SectionSize.CONTAINER_MAX,
110+
EOFException.INVALID_SECTION_BODIES_SIZE,
102111
),
103112
],
104113
)
@@ -108,7 +117,7 @@ def test_section_size(
108117
section_kind: SectionKind,
109118
exception: EOFExceptionInstanceOrList,
110119
):
111-
"""Test custom_size is auto, more or less then the actual size of the section."""
120+
"""Test custom_size is auto, more or less than the actual size of the section."""
112121
eof_code = Container()
113122

114123
if section_size != SectionSize.NORMAL and section_kind == SectionKind.TYPE:

tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_initcode_aborts(
142142
Size of the factory portion of test_eofcreate_deploy_sizes, but as the runtime code is dynamic, we
143143
have to use a pre-calculated size
144144
"""
145-
factory_size = 74
145+
factory_size = 78
146146

147147

148148
@pytest.mark.parametrize(
@@ -206,7 +206,7 @@ def test_eofcreate_deploy_sizes(
206206
"factory_size is wrong, expected factory_size is %d, calculated is %d"
207207
% (
208208
factory_size,
209-
len(factory_container),
209+
len(factory_container) - len(runtime_container),
210210
)
211211
)
212212

tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_subcontainer_validation.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
754754
abort_sub_container,
755755
],
756756
expected_bytecode="""
757-
ef0001010004020001000b0300010014ff0000000080000436600060ff6000ec005000ef000101000402
757+
ef0001010004020001000b03000100000014ff0000000080000436600060ff6000ec005000ef000101000402
758758
00010001ff00000000800000fe""",
759759
),
760760
id="eofcreate_0",
@@ -766,8 +766,8 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
766766
abort_sub_container,
767767
],
768768
expected_bytecode="""
769-
ef000101000402000100060300010014ff000000008000016000e0000000ef00010100040200010001ff
770-
00000000800000fe""",
769+
ef0001010004020001000603000100000014ff000000008000016000e0000000ef000101000402000100
770+
01ff00000000800000fe""",
771771
# Originally this test was "valid" because it was created
772772
# before "orphan subcontainer" rule was introduced.
773773
validity_error=EOFException.ORPHAN_SUBCONTAINER,
@@ -782,8 +782,8 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
782782
Section.Data(custom_size=2),
783783
],
784784
expected_bytecode="""
785-
ef000101000402000100060300010014ff000200008000016000e0000000ef00010100040200010001ff
786-
00000000800000fe""",
785+
ef0001010004020001000603000100000014ff000200008000016000e0000000ef000101000402000100
786+
01ff00000000800000fe""",
787787
# Originally this test was "valid" but against the current spec
788788
# it contains two errors: data section truncated and orphan subcontainer.
789789
validity_error=EOFException.TOPLEVEL_CONTAINER_TRUNCATED,
@@ -798,8 +798,8 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
798798
Section.Data("aabb"),
799799
],
800800
expected_bytecode="""
801-
ef000101000402000100060300010014ff000200008000016000e0000000ef00010100040200010001ff
802-
00000000800000feaabb""",
801+
ef0001010004020001000603000100000014ff000200008000016000e0000000ef000101000402000100
802+
01ff00000000800000feaabb""",
803803
# Originally this test was "valid" because it was created
804804
# before "orphan subcontainer" rule was introduced.
805805
validity_error=EOFException.ORPHAN_SUBCONTAINER,
@@ -832,7 +832,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
832832
]
833833
+ 2 * [abort_sub_container],
834834
expected_bytecode="""
835-
ef0001010004020001000b03000200140014ff0000000080000436600060ff6000ec015000ef00010100
835+
ef0001010004020001000b0300020000001400000014ff0000000080000436600060ff6000ec015000ef00010100
836836
040200010001ff00000000800000feef00010100040200010001ff00000000800000fe""",
837837
# Originally this test was "valid" because it was created
838838
# before "orphan subcontainer" rule was introduced.
@@ -848,7 +848,7 @@ def test_wide_container(eof_test: EOFTestFiller, width: int, exception: EOFExcep
848848
Section.Container(Container.Code(Op.PUSH0 + Op.PUSH0 + Op.RETURN)),
849849
],
850850
expected_bytecode="""
851-
ef0001010004020001000603000200140016ff000000008000016000e0000000ef000101000402000100
851+
ef000101000402000100060300020000001400000016ff000000008000016000e0000000ef000101000402000100
852852
01ff00000000800000feef00010100040200010003ff000000008000025f5ff3""",
853853
# Originally this test was "valid" because it was created
854854
# before "orphan subcontainer" rule was introduced.

0 commit comments

Comments
 (0)