Skip to content

Commit

Permalink
fix(fw): Fix EOF exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jun 20, 2024
1 parent 544780b commit 15f8fe2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
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),
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
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ incrementing
ini
init
initcode
initcontainer
instantiation
io
islice
Expand Down

0 comments on commit 15f8fe2

Please sign in to comment.