Skip to content

Commit 62d2563

Browse files
pdobaczspencer-tb
andauthored
new(tests): EIP-7873 TXCREATE execution tests - 1st batch (#1413)
* fix(tests): Fix existing tests for eof-devnet-1 TXCREATE change * new(tests): EIP-7873 TXCREATE execution tests - 1st batch * new(tests): Allow TXCREATE in legacy (#7) * fix(fw): expose Container.hash property * Apply code review suggestion - import helpers * fix(fw): Include initcodes field Co-authored-by: spencer-tb <spencer.taylor-brown@ethereum.org> * fix(tests): adjust EIP-7873 test to new container size --------- Co-authored-by: spencer-tb <spencer.taylor-brown@ethereum.org>
1 parent e2809d9 commit 62d2563

File tree

12 files changed

+1558
-4
lines changed

12 files changed

+1558
-4
lines changed

src/ethereum_test_fixtures/blockchain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class FixtureTransaction(TransactionFixtureConverter, TransactionGeneric[ZeroPad
321321
"""Representation of an Ethereum transaction within a test Fixture."""
322322

323323
authorization_list: List[FixtureAuthorizationTuple] | None = None
324+
initcodes: List[Bytes] | None = None
324325

325326
@classmethod
326327
def from_transaction(cls, tx: Transaction) -> "FixtureTransaction":

src/ethereum_test_fixtures/state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class FixtureTransaction(TransactionFixtureConverter):
4343
data: List[Bytes]
4444
access_lists: List[List[AccessList] | None] | None = None
4545
authorization_list: List[FixtureAuthorizationTuple] | None = None
46+
initcodes: List[Bytes] | None = None
4647
max_fee_per_blob_gas: ZeroPaddedHexNumber | None = None
4748
blob_versioned_hashes: Sequence[Hash] | None = None
4849
sender: Address | None = None

src/ethereum_test_types/eof/v1/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
to_string_ser_schema,
1313
)
1414

15-
from ethereum_test_base_types import Bytes
15+
from ethereum_test_base_types import Bytes, Hash
1616
from ethereum_test_base_types.conversions import BytesConvertible
1717
from ethereum_test_base_types.pydantic import CopyValidateModel
1818
from ethereum_test_exceptions.exceptions import EOFExceptionInstanceOrList
@@ -468,6 +468,11 @@ def Init( # noqa: N802
468468
],
469469
)
470470

471+
@cached_property
472+
def hash(self) -> Hash:
473+
"""Returns hash of the container bytecode."""
474+
return Bytes(self.bytecode).keccak256()
475+
471476
def __bytes__(self) -> bytes:
472477
"""Return bytecode of the container."""
473478
return self.bytecode

src/ethereum_test_types/types.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ class Transaction(
669669

670670
authorization_list: List[AuthorizationTuple] | None = None
671671

672+
initcodes: List[Bytes] | None = None
673+
672674
secret_key: Hash | None = None
673675
error: List[TransactionException] | TransactionException | None = Field(None, exclude=True)
674676

@@ -710,7 +712,9 @@ def model_post_init(self, __context):
710712

711713
if "ty" not in self.model_fields_set:
712714
# Try to deduce transaction type from included fields
713-
if self.authorization_list is not None:
715+
if self.initcodes is not None:
716+
self.ty = 6
717+
elif self.authorization_list is not None:
714718
self.ty = 4
715719
elif self.max_fee_per_blob_gas is not None or self.blob_versioned_hashes is not None:
716720
self.ty = 3
@@ -758,6 +762,11 @@ def model_post_init(self, __context):
758762
if self.ty != 4:
759763
assert self.authorization_list is None, "authorization_list must be None"
760764

765+
if self.ty == 6 and self.initcodes is None:
766+
self.initcodes = []
767+
if self.ty != 6:
768+
assert self.initcodes is None, "initcodes must be None"
769+
761770
if "nonce" not in self.model_fields_set and self.sender is not None:
762771
self.nonce = HexNumber(self.sender.get_nonce())
763772

@@ -911,7 +920,21 @@ def get_rlp_signing_fields(self) -> List[str]:
911920
the transaction type.
912921
"""
913922
field_list: List[str]
914-
if self.ty == 4:
923+
if self.ty == 6:
924+
# EIP-7873: https://eips.ethereum.org/EIPS/eip-7873
925+
field_list = [
926+
"chain_id",
927+
"nonce",
928+
"max_priority_fee_per_gas",
929+
"max_fee_per_gas",
930+
"gas_limit",
931+
"to",
932+
"value",
933+
"data",
934+
"access_list",
935+
"initcodes",
936+
]
937+
elif self.ty == 4:
915938
# EIP-7702: https://eips.ethereum.org/EIPS/eip-7702
916939
field_list = [
917940
"chain_id",

src/ethereum_test_vm/opcode.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5117,6 +5117,35 @@ class Opcodes(Opcode, Enum):
51175117
51185118
"""
51195119

5120+
TXCREATE = Opcode(
5121+
0xED,
5122+
popped_stack_items=5,
5123+
pushed_stack_items=1,
5124+
kwargs=["tx_initcode_hash", "salt", "input_offset", "input_size", "value"],
5125+
)
5126+
"""
5127+
!!! Note: This opcode is under development
5128+
5129+
TXCREATE (tx_initcode_hash, salt, input_offset, input_size, value)
5130+
----
5131+
5132+
Description
5133+
----
5134+
5135+
Inputs
5136+
----
5137+
5138+
Outputs
5139+
----
5140+
5141+
Fork
5142+
----
5143+
5144+
Gas
5145+
----
5146+
5147+
"""
5148+
51205149
RETURNCODE = Opcode(
51215150
0xEE,
51225151
popped_stack_items=2,
@@ -5869,7 +5898,6 @@ class UndefinedOpcodes(Opcode, Enum):
58695898
OPCODE_E9 = Opcode(0xE9)
58705899
OPCODE_EA = Opcode(0xEA)
58715900
OPCODE_EB = Opcode(0xEB)
5872-
OPCODE_ED = Opcode(0xED)
58735901
OPCODE_EF = Opcode(0xEF)
58745902
OPCODE_F6 = Opcode(0xF6)
58755903
OPCODE_FC = Opcode(0xFC)

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/opcodes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
Op.DATACOPY,
3232
# EIP-7620 EOF Create and Return Contract operation
3333
Op.EOFCREATE,
34+
# EIP-7873 TXCREATE and InitcodeTransaction
35+
Op.TXCREATE,
36+
# EIP-7620 EOF Create and Return Contract operation
3437
Op.RETURNCODE,
3538
# Non-deprecated Legacy Opcodes
3639
Op.STOP,

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_opcodes_in_legacy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
pytest.param(Op.DATASIZE, id="DATASIZE"),
4949
pytest.param(Op.DATACOPY(0, 0, 32), id="DATACOPY"),
5050
pytest.param(Op.EOFCREATE[0](0, 0, 0, 0), id="EOFCREATE"),
51+
# pytest.param(Op.TXCREATE(0, 0, 0, 0, 0), id="TXCREATE"), not EOF-only anymore
5152
pytest.param(Op.RETURNCODE[0], id="RETURNCODE"),
5253
]
5354

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
abstract: Test cases for
3+
[EIP-7873: TXCREATE and InitcodeTransaction](https://eips.ethereum.org/EIPS/eip-7873).
4+
""" # noqa: E501
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""EOF V1 Constants used throughout all tests."""
2+
3+
TXCREATE_FAILURE = 0

0 commit comments

Comments
 (0)