Skip to content

Commit

Permalink
EOFCREATE and RETURNDATA tests
Browse files Browse the repository at this point in the history
Tests covering EOFCREATE and RETURNDATA, ported from evmone

Signed-off-by: Danno Ferrin <danno@numisight.com>
  • Loading branch information
shemnon committed Apr 29, 2024
1 parent 4783e6e commit b4beca6
Show file tree
Hide file tree
Showing 13 changed files with 1,147 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/ethereum_test_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
add_kzg_version,
ceiling_division,
compute_create2_address,
compute_create3_address,
compute_create_address,
compute_eofcreate_address,
copy_opcode_cost,
cost_memory_bytes,
eip_2028_transaction_data_cost,
Expand Down Expand Up @@ -110,7 +110,7 @@
"ceiling_division",
"compute_create_address",
"compute_create2_address",
"compute_create3_address",
"compute_eofcreate_address",
"copy_opcode_cost",
"cost_memory_bytes",
"eip_2028_transaction_data_cost",
Expand Down
4 changes: 2 additions & 2 deletions src/ethereum_test_tools/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
add_kzg_version,
ceiling_division,
compute_create2_address,
compute_create3_address,
compute_create_address,
compute_eofcreate_address,
copy_opcode_cost,
cost_memory_bytes,
eip_2028_transaction_data_cost,
Expand Down Expand Up @@ -77,7 +77,7 @@
"ceiling_division",
"compute_create_address",
"compute_create2_address",
"compute_create3_address",
"compute_eofcreate_address",
"copy_opcode_cost",
"cost_memory_bytes",
"eip_2028_transaction_data_cost",
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum_test_tools/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def copy_opcode_cost(length: int) -> int:
return 3 + (ceiling_division(length, 32) * 3) + cost_memory_bytes(length, 0)


def compute_create3_address(
def compute_eofcreate_address(
address: FixedSizeBytesConvertible,
salt: FixedSizeBytesConvertible,
init_container: BytesConvertible,
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum_test_tools/eof/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def bytecode(self) -> bytes:
initcode = Container(
sections=[
Section(
data=Op.CREATE3(0, 0, 0, 0, len(self.deploy_container)) + Op.STOP(),
data=Op.EOFCREATE(0, 0, 0, 0, len(self.deploy_container)) + Op.STOP(),
kind=SectionKind.CODE,
max_stack_height=4,
),
Expand Down
4 changes: 2 additions & 2 deletions src/ethereum_test_tools/vm/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5014,11 +5014,11 @@ class Opcodes(Opcode, Enum):
"""

CREATE3 = Opcode(0xEC, popped_stack_items=4, pushed_stack_items=1, data_portion_length=1)
EOFCREATE = Opcode(0xEC, popped_stack_items=4, pushed_stack_items=1, data_portion_length=1)
"""
!!! Note: This opcode is under development
CREATE3()
EOFCREATE[ initcontainer_index](value, salt, input_offset, input_size)
----
Description
Expand Down
4 changes: 2 additions & 2 deletions tests/prague/eip3540_eof_v1/test_code_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
EOFTestFiller,
TestAddress,
Transaction,
compute_create3_address,
compute_eofcreate_address,
)
from ethereum_test_tools.eof.v1 import Container, Initcode

Expand Down Expand Up @@ -103,7 +103,7 @@ def post( # noqa: D103
container: Container,
create3_opcode_contract_address: str,
) -> Dict[Address, Account]:
create_opcode_created_contract_address = compute_create3_address(
create_opcode_created_contract_address = compute_eofcreate_address(
create3_opcode_contract_address,
0,
bytes(create3_init_container.init_container),
Expand Down
16 changes: 16 additions & 0 deletions tests/prague/eip7620_eof_create/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
EOFCREATE, RETURNCONTRACT, and container tests
tests.prague.eip7480_data_section.test_data_opcodes.test_data_section_succeed
evmone tests not ported
create_tx_with_eof_initcode - This calls it invalid, it is now the way to add EOF contacts to state
eofcreate_extcall_returncontract - per the new initcode mode tests you cannot have RETURNCONTRACT
in a deployed contract
eofcreate_dataloadn_referring_to_auxdata - covered by
tests.prague.eip7480_data_section.test_data_opcodes.test_data_section_succeed
eofcreate_initcontainer_return - RETURN is banned in initcode containers
eofcreate_initcontainer_stop - STOP is banned in initcode containers
All TXCREATE tests - TXCREATE has been removed from Prague
"""
67 changes: 67 additions & 0 deletions tests/prague/eip7620_eof_create/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
A collection of contracts used in 7620 EOF tests
"""
from ethereum_test_tools import Address
from ethereum_test_tools import Opcodes as Op
from ethereum_test_tools import Transaction
from ethereum_test_tools.eof.v1 import Container, Section
from ethereum_test_tools.eof.v1.constants import NON_RETURNING_SECTION

smallest_runtime_subcontainer = Container(
name="Runtime Subcontainer",
sections=[
Section.Code(
code=Op.STOP, code_inputs=0, code_outputs=NON_RETURNING_SECTION, max_stack_height=0
)
],
)

smallest_initcode_subcontainer = Container(
name="Initcode Subcontainer",
sections=[
Section.Code(
code=Op.RETURNCONTRACT[0](0, 0),
code_inputs=0,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=2,
),
Section.Container(container=smallest_runtime_subcontainer),
],
)


def fixed_address(index: int) -> Address:
"""
Returns an determinstic address for testing
Parameters
----------
index - how foar off of the initial to create the address
Returns
-------
An address, unique per index and human friendly for testing
"""
return Address(0x7E570000 + index)


default_address = fixed_address(0)


def simple_transaction(
target: Address = default_address, payload: bytes = b"", gas_limit: int = 10_000_000
):
"""
Creates a simple transaction
Parameters
----------
target the target address, defaults to 0x100
payload the payload, defauls to empty
Returns
-------
a transaction instance that can be passed into state_tests
"""
return Transaction(
nonce=1, to=target, gas_limit=gas_limit, gas_price=10, protected=False, data=payload
)
5 changes: 5 additions & 0 deletions tests/prague/eip7620_eof_create/spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
EOF V1 Constants used throughout all tests
"""

EOF_FORK_NAME = "Prague"
Loading

0 comments on commit b4beca6

Please sign in to comment.