Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(tests): EOF - EIP-7620: EOFCREATE and RETURNCONTRACT container validation tests #640

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- ✨ Add tests for [EIP-7069: EOF - Revamped CALL instructions](https://eips.ethereum.org/EIPS/eip-7069) ([#595](https://github.com/ethereum/execution-spec-tests/pull/595)).
- 🐞 Fix typos in self-destruct collision test from erroneous pytest parametrization ([#608](https://github.com/ethereum/execution-spec-tests/pull/608)).
- ✨ Add tests for [EIP-3540: EOF - EVM Object Format v1](https://eips.ethereum.org/EIPS/eip-3540) ([#634](https://github.com/ethereum/execution-spec-tests/pull/634)).
- ✨ Add tests for [EIP-7620: EOF Contract Creation](https://eips.ethereum.org/EIPS/eip-7620) ([#532](https://github.com/ethereum/execution-spec-tests/pull/532), [#640](https://github.com/ethereum/execution-spec-tests/pull/640)).

### πŸ› οΈ Framework

Expand Down
64 changes: 32 additions & 32 deletions src/ethereum_test_tools/exceptions/evmone_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ class ExceptionMessage:
"""Defines a mapping between an exception and a message."""

exception: EOFException
message: str
message: str = ""

def __post_init__(self):
"""
Set the default error message if none provided.
"""
assert isinstance(self.exception, EOFException), "exception must be an EOFException"
# default message is "err: <exception_name in lowercase>"
if not self.message:
self.message = f"err: {self.exception.name.lower()}"


class EvmoneExceptionMapper:
Expand All @@ -33,46 +42,37 @@ class EvmoneExceptionMapper:
EOFException.MISSING_HEADERS_TERMINATOR, "err: section_headers_not_terminated"
),
ExceptionMessage(EOFException.INVALID_VERSION, "err: eof_version_unknown"),
ExceptionMessage(
EOFException.INVALID_NON_RETURNING_FLAG, "err: invalid_non_returning_flag"
),
ExceptionMessage(EOFException.INVALID_NON_RETURNING_FLAG),
ExceptionMessage(EOFException.INVALID_MAGIC, "err: invalid_prefix"),
ExceptionMessage(
EOFException.INVALID_FIRST_SECTION_TYPE, "err: invalid_first_section_type"
),
ExceptionMessage(
EOFException.INVALID_SECTION_BODIES_SIZE, "err: invalid_section_bodies_size"
),
ExceptionMessage(EOFException.INVALID_TYPE_SECTION_SIZE, "err: invalid_type_section_size"),
ExceptionMessage(EOFException.INCOMPLETE_SECTION_SIZE, "err: incomplete_section_size"),
ExceptionMessage(EOFException.INCOMPLETE_SECTION_NUMBER, "err: incomplete_section_number"),
ExceptionMessage(EOFException.TOO_MANY_CODE_SECTIONS, "err: too_many_code_sections"),
ExceptionMessage(EOFException.ZERO_SECTION_SIZE, "err: zero_section_size"),
ExceptionMessage(EOFException.INVALID_FIRST_SECTION_TYPE),
ExceptionMessage(EOFException.INVALID_SECTION_BODIES_SIZE),
ExceptionMessage(EOFException.INVALID_TYPE_SECTION_SIZE),
ExceptionMessage(EOFException.INCOMPLETE_SECTION_SIZE),
ExceptionMessage(EOFException.INCOMPLETE_SECTION_NUMBER),
ExceptionMessage(EOFException.TOO_MANY_CODE_SECTIONS),
ExceptionMessage(EOFException.ZERO_SECTION_SIZE),
ExceptionMessage(EOFException.MISSING_DATA_SECTION, "err: data_section_missing"),
ExceptionMessage(EOFException.UNDEFINED_INSTRUCTION, "err: undefined_instruction"),
ExceptionMessage(
EOFException.INPUTS_OUTPUTS_NUM_ABOVE_LIMIT, "err: inputs_outputs_num_above_limit"
),
ExceptionMessage(EOFException.UNREACHABLE_INSTRUCTIONS, "err: unreachable_instructions"),
ExceptionMessage(EOFException.INVALID_RJUMP_DESTINATION, "err: invalid_rjump_destination"),
ExceptionMessage(EOFException.UNREACHABLE_CODE_SECTIONS, "err: unreachable_code_sections"),
ExceptionMessage(EOFException.STACK_UNDERFLOW, "err: stack_underflow"),
ExceptionMessage(
EOFException.MAX_STACK_HEIGHT_ABOVE_LIMIT, "err: max_stack_height_above_limit"
),
ExceptionMessage(EOFException.UNDEFINED_INSTRUCTION),
ExceptionMessage(EOFException.INPUTS_OUTPUTS_NUM_ABOVE_LIMIT),
ExceptionMessage(EOFException.UNREACHABLE_INSTRUCTIONS),
ExceptionMessage(EOFException.INVALID_RJUMP_DESTINATION),
ExceptionMessage(EOFException.UNREACHABLE_CODE_SECTIONS),
ExceptionMessage(EOFException.STACK_UNDERFLOW),
ExceptionMessage(EOFException.MAX_STACK_HEIGHT_ABOVE_LIMIT),
ExceptionMessage(
EOFException.STACK_HIGHER_THAN_OUTPUTS, "err: stack_higher_than_outputs_required"
),
ExceptionMessage(
EOFException.JUMPF_DESTINATION_INCOMPATIBLE_OUTPUTS,
"err: jumpf_destination_incompatible_outputs",
),
ExceptionMessage(EOFException.INVALID_MAX_STACK_HEIGHT, "err: invalid_max_stack_height"),
ExceptionMessage(EOFException.INVALID_DATALOADN_INDEX, "err: invalid_dataloadn_index"),
ExceptionMessage(EOFException.TRUNCATED_INSTRUCTION, "err: truncated_instruction"),
ExceptionMessage(
EOFException.TOPLEVEL_CONTAINER_TRUNCATED, "err: toplevel_container_truncated"
),
ExceptionMessage(EOFException.INVALID_MAX_STACK_HEIGHT),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what this maps to? "eofexception.invalid_max_stack_height"?

ExceptionMessage(EOFException.INVALID_DATALOADN_INDEX),
ExceptionMessage(EOFException.TRUNCATED_INSTRUCTION),
ExceptionMessage(EOFException.TOPLEVEL_CONTAINER_TRUNCATED),
ExceptionMessage(EOFException.INVALID_CONTAINER_SECTION_INDEX),
ExceptionMessage(EOFException.EOFCREATE_RUNTIME_CONTAINER),
ExceptionMessage(EOFException.RETURNCONTRACT_INITCONTAINER),
)

def __init__(self) -> None:
Expand Down
12 changes: 12 additions & 0 deletions src/ethereum_test_tools/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,18 @@ class EOFException(ExceptionBase):
"""
Top-level EOF container has data section truncated
"""
INVALID_CONTAINER_SECTION_INDEX = auto()
"""
EOFCREATE or RETURNCONTRACT has invalid section index.
"""
EOFCREATE_RUNTIME_CONTAINER = auto()
"""
EOFCREATE tries to initialize a container using a runtime container.
"""
RETURNCONTRACT_INITCONTAINER = auto()
"""
RETURNCONTRACT tries to return an init-container.
"""


"""
Expand Down
4 changes: 1 addition & 3 deletions src/ethereum_test_tools/vm/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5249,9 +5249,7 @@ class Opcodes(Opcode, Enum):

"""

RETURNCONTRACT = Opcode(
0xEE, popped_stack_items=2, pushed_stack_items=1, data_portion_length=1
)
RETURNCONTRACT = Opcode(0xEE, popped_stack_items=2, data_portion_length=1)
"""
!!! Note: This opcode is under development

Expand Down
Loading