Skip to content

Commit 32217d2

Browse files
committed
new(tests): EOF Validation embedded containers
1 parent 84d28db commit 32217d2

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_subcontainer_validation.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,156 @@ def test_subcontainer_wrong_size(
585585
)
586586

587587

588+
empty_container = Container(
589+
name="embedded_container_zero_container_size",
590+
sections=[
591+
Section.Code(
592+
code=Op.PUSH1[0] + Op.RJUMPI[0] + Op.STOP,
593+
max_stack_height=1,
594+
),
595+
Section.Container(
596+
container=Container(
597+
raw_bytes=([]), # Empty subcontainer
598+
)
599+
),
600+
],
601+
)
602+
603+
604+
@pytest.mark.parametrize(
605+
"truncate_at,exception",
606+
[
607+
pytest.param(-1, None),
608+
pytest.param(12, EOFException.INCOMPLETE_SECTION_NUMBER),
609+
pytest.param(13, EOFException.INCOMPLETE_SECTION_NUMBER),
610+
pytest.param(14, EOFException.MISSING_HEADERS_TERMINATOR),
611+
pytest.param(15, EOFException.INCOMPLETE_SECTION_SIZE),
612+
pytest.param(16, EOFException.INCOMPLETE_SECTION_SIZE),
613+
pytest.param(17, EOFException.INCOMPLETE_SECTION_SIZE),
614+
pytest.param(18, EOFException.MISSING_HEADERS_TERMINATOR),
615+
],
616+
)
617+
def test_truncated_subcontainer(eof_test, truncate_at, exception):
618+
"""Test truncated container in subcontainer header description."""
619+
container = Container(
620+
sections=[
621+
Section.Code(
622+
code=Op.RETURNCODE[0](0, 0),
623+
),
624+
stop_sub_container,
625+
],
626+
kind=ContainerKind.INITCODE,
627+
)
628+
if truncate_at > 0:
629+
container = Container(
630+
raw_bytes=container.bytecode[0:truncate_at],
631+
)
632+
eof_test(container=container, expect_exception=exception)
633+
634+
635+
@pytest.mark.parametrize(
636+
"container,exception",
637+
[
638+
pytest.param(
639+
empty_container,
640+
EOFException.ZERO_SECTION_SIZE,
641+
),
642+
pytest.param(
643+
Container(
644+
name="embedded_container_non_zero_section_size_zero_container_size",
645+
raw_bytes=(
646+
[
647+
0xEF,
648+
0x00,
649+
0x01, # Version: 1
650+
0x01, # Types Length: 4
651+
0x00,
652+
0x04,
653+
0x02, # Code Sections (Length: 1)
654+
0x00,
655+
0x01,
656+
0x00, # Code Section 0 (Length: 6)
657+
0x06,
658+
0x03, # Container Sections (Length: 1)
659+
0x00,
660+
0x01,
661+
0x00, # Container Section 0 (Length: 20)
662+
0x00,
663+
0x00,
664+
0x14,
665+
0xFF, # Data Length: 0
666+
0x00,
667+
0x00,
668+
0x00, # Terminator
669+
# Code Section 0 types
670+
0x00, # Inputs: 0
671+
0x80, # Outputs: 0 (Non-returning function)
672+
0x00, # Max Stack Height: 1
673+
0x01,
674+
# Code Section 0
675+
0x60, # [0] PUSH1(0)
676+
0x00,
677+
0xE1, # [2] RJUMPI(0)
678+
0x00,
679+
0x00,
680+
0x00, # [5] STOP
681+
# --- Error: Invalid Container Content ---#
682+
]
683+
),
684+
),
685+
EOFException.INVALID_SECTION_BODIES_SIZE,
686+
),
687+
pytest.param(
688+
Container(
689+
name="embedded_container_zero_section_size",
690+
raw_bytes=(
691+
[
692+
0xEF,
693+
0x00,
694+
0x01, # Version: 1
695+
0x01, # Types Length: 4
696+
0x00,
697+
0x04,
698+
0x02, # Code Sections (Length: 1)
699+
0x00,
700+
0x01,
701+
0x00, # Code Section 0 (Length: 6)
702+
0x06,
703+
# --- Error: Invalid Container Header (zero section size) ---#
704+
0x03,
705+
0x00,
706+
0x00,
707+
0xFF,
708+
0x00,
709+
0x00,
710+
0x00,
711+
0x00,
712+
0x80,
713+
0x00,
714+
0x01,
715+
0x60,
716+
0x00,
717+
0xE1,
718+
0x00,
719+
0x00,
720+
0x00,
721+
]
722+
),
723+
),
724+
EOFException.ZERO_SECTION_SIZE,
725+
),
726+
],
727+
)
728+
def test_subcontainer_zero_section_size(
729+
eof_test: EOFTestFiller, container: Container, exception: EOFException
730+
):
731+
"""Test subcontainers with declared or non-declared zero section sizes."""
732+
eof_test(
733+
container=container,
734+
expect_exception=exception,
735+
)
736+
737+
588738
deep_container_parametrize = pytest.mark.parametrize(
589739
["deepest_container", "exception"],
590740
[

0 commit comments

Comments
 (0)