Skip to content

Commit

Permalink
fix(tests): EOF - EIP-3540: update validation tests for recent spec (e…
Browse files Browse the repository at this point in the history
…thereum#558)

- EOF can have truncated data (these are valid containers).
- Properly specify non-returning code section.
  • Loading branch information
chfast authored May 28, 2024
1 parent ddae720 commit 98cb3f0
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MAX_CODE_INPUTS,
MAX_CODE_OUTPUTS,
MAX_OPERAND_STACK_HEIGHT,
NON_RETURNING_SECTION,
)
from ethereum_test_tools.exceptions import EOFException
from ethereum_test_tools.vm.opcode import Opcodes as Op
Expand All @@ -19,10 +20,31 @@
Container(
name="single_code_single_data_section",
sections=[
Section.Code(code=Op.ADDRESS + Op.POP + Op.STOP, code_outputs=128, max_stack_height=1),
Section.Code(
code=Op.ADDRESS + Op.POP + Op.STOP,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=1,
),
Section.Data(data="0xef"),
],
),
Container(
# EOF allows truncated data section
name="no_data_section_contents",
sections=[
Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION),
Section.Data(data="0x", custom_size=1),
],
code="ef0001 010004 0200010001 040001 00 00800000 00",
),
Container(
# EOF allows truncated data section
name="data_section_contents_incomplete",
sections=[
Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION),
Section.Data(data="0xAABBCC", custom_size=4),
],
),
# TODO this is the only valid code I managed to produce
# somehow if code is 00 byte it gets rejected
# also if max_stack_height and code_outputs are not set it gets rejected
Expand Down Expand Up @@ -300,28 +322,11 @@
name="no_section_terminator_4a",
header_terminator=bytes(),
sections=[
Section.Code(Op.STOP),
Section.Code(Op.STOP, code_outputs=NON_RETURNING_SECTION),
Section.Data(data="0xAABBCCDD"),
],
# TODO the exception must be about terminator
validity_error=EOFException.INVALID_SECTION_BODIES_SIZE,
),
Container(
name="no_data_section_contents",
sections=[
Section.Code(Op.STOP),
Section.Data(data="0x", custom_size=1),
],
# TODO: maybe it should detect that it is the data body that is wrong
validity_error=EOFException.INVALID_SECTION_BODIES_SIZE,
),
Container(
name="data_section_contents_incomplete",
sections=[
Section.Code(Op.STOP),
Section.Data(data="0xAABBCC", custom_size=4),
],
validity_error=EOFException.INVALID_SECTION_BODIES_SIZE,
# TODO: The error of this validation can be random.
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
),
Container(
name="trailing_bytes_after_data_section",
Expand Down

0 comments on commit 98cb3f0

Please sign in to comment.