Skip to content

Commit

Permalink
Fuzzing related findings
Browse files Browse the repository at this point in the history
A collection of fuzzing related updates to the test
* Activate functions validation tests, and move to 4750 dir
* Add terminal opcode to some tests so they have only one error
* Tests found via fuzzing coverage
  * subcontainer wrong size
  * subcontainer wrong eof version
  * EOFCREATE nonexistant container
  * Many CALLF test covered by inactive 4750 checks

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon committed Aug 21, 2024
1 parent 632d151 commit bce1e1d
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 292 deletions.
3 changes: 3 additions & 0 deletions src/ethereum_test_exceptions/evmone_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class EvmoneExceptionMapper:
),
ExceptionMessage(EOFException.STACK_HEIGHT_MISMATCH, "err: stack_height_mismatch"),
ExceptionMessage(EOFException.TOO_MANY_CONTAINERS, "err: too_many_container_sections"),
ExceptionMessage(
EOFException.INVALID_CODE_SECTION_INDEX, "err: invalid_code_section_index"
),
)

def __init__(self) -> None:
Expand Down
4 changes: 4 additions & 0 deletions src/ethereum_test_exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ class EOFException(ExceptionBase):
"""
EOF container header has too many sub-containers.
"""
INVALID_CODE_SECTION_INDEX = auto()
"""
CALLF Operation referes to a non-existent code section
"""


"""
Expand Down
189 changes: 0 additions & 189 deletions tests/prague/eip7692_eof_v1/eip3540_eof_v1/code_validation_function.py

This file was deleted.

101 changes: 5 additions & 96 deletions tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_code_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,111 +2,20 @@
EOF V1 Code Validation tests
"""

from typing import Dict, List

import pytest

from ethereum_test_tools import (
EOA,
Account,
Address,
Alloc,
Environment,
EOFTestFiller,
Transaction,
compute_eofcreate_address,
)
from ethereum_test_tools.eof.v1 import Container, Initcode
from ethereum_test_tools import EOFTestFiller
from ethereum_test_tools.eof.v1 import Container

from .. import EOF_FORK_NAME

# from .code_validation import INVALID as INVALID_CODE
# from .code_validation import VALID as VALID_CODE
# from .code_validation_function import INVALID as INVALID_FN
# from .code_validation_function import VALID as VALID_FN
# from .code_validation_jump import INVALID as INVALID_RJUMP
# from .code_validation_jump import VALID as VALID_RJUMP
from .container import INVALID as INVALID_CONTAINERS
from .container import VALID as VALID_CONTAINERS

# from .tests_execution_function import VALID as VALID_EXEC_FN

ALL_VALID = VALID_CONTAINERS
ALL_INVALID = INVALID_CONTAINERS
# ALL_VALID = (
# VALID_CONTAINERS + VALID_CODE + VALID_RJUMP + VALID_FN + VALID_EXEC_FN
# )
# ALL_INVALID = INVALID_CONTAINERS + INVALID_CODE + INVALID_RJUMP + INVALID_FN
from .container import INVALID, VALID

REFERENCE_SPEC_GIT_PATH = "EIPS/eip-3540.md"
REFERENCE_SPEC_VERSION = "8dcb0a8c1c0102c87224308028632cc986a61183"

pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)


@pytest.fixture
def env(): # noqa: D103
return Environment()


@pytest.fixture
def sender(pre: Alloc): # noqa: D103
return pre.fund_eoa()


@pytest.fixture
def create3_init_container(container: Container) -> Initcode: # noqa: D103
return Initcode(deploy_container=container)


@pytest.fixture
def create3_opcode_contract_address( # noqa: D103
pre: Alloc,
create3_init_container: Initcode,
) -> Address:
return pre.deploy_contract(create3_init_container, address=Address(0x300))


@pytest.fixture
def txs( # noqa: D103
sender: EOA,
create3_opcode_contract_address: Address,
) -> List[Transaction]:
return [
Transaction(
to=create3_opcode_contract_address,
gas_limit=100000000,
gas_price=10,
# data=initcode,
protected=False,
sender=sender,
)
]


@pytest.fixture
def post( # noqa: D103
create3_init_container: Initcode,
container: Container,
create3_opcode_contract_address: Address,
) -> Dict[Address, Account]:
create_opcode_created_contract_address = compute_eofcreate_address(
create3_opcode_contract_address,
0,
bytes(create3_init_container.init_container),
)

new_account = Account(code=container)

# Do not expect to create account if it is invalid
if hasattr(new_account, "code") and container.validity_error != "":
return {}
else:
return {
create_opcode_created_contract_address: new_account,
}


def container_name(c: Container):
"""
Return the name of the container for use in pytest ids.
Expand All @@ -119,7 +28,7 @@ def container_name(c: Container):

@pytest.mark.parametrize(
"container",
ALL_VALID,
VALID,
ids=container_name,
)
def test_legacy_initcode_valid_eof_v1_contract(
Expand All @@ -140,7 +49,7 @@ def test_legacy_initcode_valid_eof_v1_contract(

@pytest.mark.parametrize(
"container",
ALL_INVALID,
INVALID,
ids=container_name,
)
def test_legacy_initcode_invalid_eof_v1_contract(
Expand Down
Loading

0 comments on commit bce1e1d

Please sign in to comment.