Skip to content

Commit a4b68e8

Browse files
shemnonmarioevz
andauthored
new(tests): EOF - EIP-7620: EOFCREATE and RETURNDATA tests (#532)
* EOFCREATE and RETURNDATA tests Tests covering EOFCREATE and RETURNDATA, ported from evmone Signed-off-by: Danno Ferrin <danno@numisight.com> * fix imports Signed-off-by: Danno Ferrin <danno@numisight.com> * review requested changes add canary value Signed-off-by: Danno Ferrin <danno@numisight.com> * reviewer change requests Change all magic numbers for storage into variables. Signed-off-by: Danno Ferrin <danno@numisight.com> * code formatting Signed-off-by: Danno Ferrin <danno@numisight.com> * fix(fw): minor nit * refactor(tests): EIP-7620: fixes --------- Signed-off-by: Danno Ferrin <danno@numisight.com> Co-authored-by: Mario Vega <marioevz@gmail.com>
1 parent 98cb3f0 commit a4b68e8

File tree

13 files changed

+1328
-25
lines changed

13 files changed

+1328
-25
lines changed

src/ethereum_test_tools/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
add_kzg_version,
3737
ceiling_division,
3838
compute_create2_address,
39-
compute_create3_address,
4039
compute_create_address,
40+
compute_eofcreate_address,
4141
copy_opcode_cost,
4242
cost_memory_bytes,
4343
eip_2028_transaction_data_cost,
@@ -119,7 +119,7 @@
119119
"ceiling_division",
120120
"compute_create_address",
121121
"compute_create2_address",
122-
"compute_create3_address",
122+
"compute_eofcreate_address",
123123
"copy_opcode_cost",
124124
"cost_memory_bytes",
125125
"eip_2028_transaction_data_cost",

src/ethereum_test_tools/common/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
add_kzg_version,
2929
ceiling_division,
3030
compute_create2_address,
31-
compute_create3_address,
3231
compute_create_address,
32+
compute_eofcreate_address,
3333
copy_opcode_cost,
3434
cost_memory_bytes,
3535
eip_2028_transaction_data_cost,
@@ -83,7 +83,7 @@
8383
"ceiling_division",
8484
"compute_create_address",
8585
"compute_create2_address",
86-
"compute_create3_address",
86+
"compute_eofcreate_address",
8787
"copy_opcode_cost",
8888
"cost_memory_bytes",
8989
"eip_2028_transaction_data_cost",

src/ethereum_test_tools/common/helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ def copy_opcode_cost(length: int) -> int:
7171
return 3 + (ceiling_division(length, 32) * 3) + cost_memory_bytes(length, 0)
7272

7373

74-
def compute_create3_address(
74+
def compute_eofcreate_address(
7575
address: FixedSizeBytesConvertible,
7676
salt: FixedSizeBytesConvertible,
7777
init_container: BytesConvertible,
7878
) -> Address:
7979
"""
80-
Compute address of the resulting contract created using the `CREATE3`
81-
opcode.
80+
Compute address of the resulting contract created using the `EOFCREATE` opcode.
8281
"""
8382
hash = keccak256(b"\xff" + Address(address) + Hash(salt) + keccak256(Bytes(init_container)))
8483
return Address(hash[-20:])

src/ethereum_test_tools/eof/v1/__init__.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,34 +441,30 @@ def init_container(self) -> Container:
441441
"""
442442
return Container(
443443
sections=[
444-
Section(
445-
kind=SectionKind.CODE,
446-
data=Op.RETURNCONTRACT(0, 0, 0),
444+
Section.Code(
445+
code=Op.RETURNCONTRACT[0](0, 0),
447446
max_stack_height=2,
448447
),
449-
Section(
450-
kind=SectionKind.CONTAINER,
451-
data=bytes(self.deploy_container),
448+
Section.Container(
449+
container=self.deploy_container,
452450
),
453451
],
454452
)
455453

456454
@cached_property
457455
def bytecode(self) -> bytes:
458456
"""
459-
Generate legacy initcode that inits a contract with the specified code.
460-
The initcode can be padded to a specified length for testing purposes.
457+
Generate an EOF container performs `EOFCREATE` with the specified code.
461458
"""
462459
initcode = Container(
463460
sections=[
464-
Section(
465-
data=Op.CREATE3(0, 0, 0, 0, len(self.deploy_container)) + Op.STOP(),
466-
kind=SectionKind.CODE,
461+
Section.Code(
462+
# TODO: Pass calldata
463+
code=Op.EOFCREATE[0](0, 0, 0, 0) + Op.STOP(),
467464
max_stack_height=4,
468465
),
469-
Section(
470-
kind=SectionKind.CONTAINER,
471-
data=self.init_container,
466+
Section.Container(
467+
container=self.init_container,
472468
),
473469
]
474470
)

src/ethereum_test_tools/vm/opcode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,11 +5091,11 @@ class Opcodes(Opcode, Enum):
50915091
50925092
"""
50935093

5094-
CREATE3 = Opcode(0xEC, popped_stack_items=4, pushed_stack_items=1, data_portion_length=1)
5094+
EOFCREATE = Opcode(0xEC, popped_stack_items=4, pushed_stack_items=1, data_portion_length=1)
50955095
"""
50965096
!!! Note: This opcode is under development
50975097
5098-
CREATE3()
5098+
EOFCREATE[initcontainer_index](value, salt, input_offset, input_size)
50995099
----
51005100
51015101
Description

tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_code_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
EOFTestFiller,
1515
TestAddress,
1616
Transaction,
17-
compute_create3_address,
17+
compute_eofcreate_address,
1818
)
1919
from ethereum_test_tools.eof.v1 import Container, Initcode
2020

@@ -103,7 +103,7 @@ def post( # noqa: D103
103103
container: Container,
104104
create3_opcode_contract_address: str,
105105
) -> Dict[Address, Account]:
106-
create_opcode_created_contract_address = compute_create3_address(
106+
create_opcode_created_contract_address = compute_eofcreate_address(
107107
create3_opcode_contract_address,
108108
0,
109109
bytes(create3_init_container.init_container),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
EOFCREATE, RETURNCONTRACT, and container tests
3+
4+
evmone tests not ported
5+
6+
create_tx_with_eof_initcode - This calls it invalid, it is now the way to add EOF contacts to state
7+
eofcreate_extcall_returncontract - per the new initcode mode tests you cannot have RETURNCONTRACT
8+
in a deployed contract
9+
eofcreate_dataloadn_referring_to_auxdata - covered by
10+
tests.prague.eip7480_data_section.test_data_opcodes.test_data_section_succeed
11+
eofcreate_initcontainer_return - RETURN is banned in initcode containers
12+
eofcreate_initcontainer_stop - STOP is banned in initcode containers
13+
All TXCREATE tests - TXCREATE has been removed from Prague
14+
"""
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""
2+
A collection of contracts used in 7620 EOF tests
3+
"""
4+
import itertools
5+
6+
from ethereum_test_tools import Address
7+
from ethereum_test_tools import Opcodes as Op
8+
from ethereum_test_tools import Transaction
9+
from ethereum_test_tools.eof.v1 import Container, Section
10+
from ethereum_test_tools.eof.v1.constants import NON_RETURNING_SECTION
11+
12+
"""Storage addresses for common testing fields"""
13+
_slot = itertools.count()
14+
next(_slot) # don't use slot 0
15+
slot_code_worked = next(_slot)
16+
slot_code_should_fail = next(_slot)
17+
slot_create_address = next(_slot)
18+
slot_calldata = next(_slot)
19+
slot_call_result = next(_slot)
20+
slot_returndata = next(_slot)
21+
slot_returndata_size = next(_slot)
22+
23+
slot_last_slot = next(_slot)
24+
25+
value_code_worked = 0x2015
26+
value_canary_should_not_change = 0x2019
27+
value_canary_to_be_overwritten = 0x2009
28+
value_create_failed = 0
29+
value_call_result_success = 0
30+
31+
smallest_runtime_subcontainer = Container(
32+
name="Runtime Subcontainer",
33+
sections=[
34+
Section.Code(
35+
code=Op.STOP, code_inputs=0, code_outputs=NON_RETURNING_SECTION, max_stack_height=0
36+
)
37+
],
38+
)
39+
40+
smallest_initcode_subcontainer = Container(
41+
name="Initcode Subcontainer",
42+
sections=[
43+
Section.Code(
44+
code=Op.RETURNCONTRACT[0](0, 0),
45+
code_inputs=0,
46+
code_outputs=NON_RETURNING_SECTION,
47+
max_stack_height=2,
48+
),
49+
Section.Container(container=smallest_runtime_subcontainer),
50+
],
51+
)
52+
53+
54+
def fixed_address(index: int) -> Address:
55+
"""
56+
Returns an determinstic address for testing
57+
Parameters
58+
----------
59+
index - how foar off of the initial to create the address
60+
61+
Returns
62+
-------
63+
An address, unique per index and human friendly for testing
64+
65+
"""
66+
return Address(0x7E570000 + index)
67+
68+
69+
default_address = fixed_address(0)
70+
71+
72+
def simple_transaction(
73+
target: Address = default_address, payload: bytes = b"", gas_limit: int = 10_000_000
74+
):
75+
"""
76+
Creates a simple transaction
77+
Parameters
78+
----------
79+
target the target address, defaults to 0x100
80+
payload the payload, defauls to empty
81+
82+
Returns
83+
-------
84+
a transaction instance that can be passed into state_tests
85+
"""
86+
return Transaction(
87+
nonce=1, to=target, gas_limit=gas_limit, gas_price=10, protected=False, data=payload
88+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
EOF V1 Constants used throughout all tests
3+
"""
4+
5+
EOF_FORK_NAME = "Prague"

0 commit comments

Comments
 (0)