From 98b76eeb4f62d9a6e53356cd74b9fc8953c1b3bd Mon Sep 17 00:00:00 2001 From: Brecht Devos Date: Fri, 25 Jul 2025 12:02:24 +0200 Subject: [PATCH 1/2] Implement EIP-7814 --- src/ethereum/osaka/fork.py | 1 + src/ethereum/osaka/vm/__init__.py | 1 + .../osaka/vm/instructions/__init__.py | 2 ++ src/ethereum/osaka/vm/instructions/block.py | 29 +++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/src/ethereum/osaka/fork.py b/src/ethereum/osaka/fork.py index 22c07e0ae8..74a9a8dd15 100644 --- a/src/ethereum/osaka/fork.py +++ b/src/ethereum/osaka/fork.py @@ -921,6 +921,7 @@ def process_transaction( blob_versioned_hashes=blob_versioned_hashes, authorizations=authorizations, index_in_block=index, + transactions_root=root(block_output.transactions_trie), tx_hash=get_transaction_hash(encode_transaction(tx)), traces=[], ) diff --git a/src/ethereum/osaka/vm/__init__.py b/src/ethereum/osaka/vm/__init__.py index df75f66a6e..ea956b9d95 100644 --- a/src/ethereum/osaka/vm/__init__.py +++ b/src/ethereum/osaka/vm/__init__.py @@ -107,6 +107,7 @@ class TransactionEnvironment: blob_versioned_hashes: Tuple[VersionedHash, ...] authorizations: Tuple[Authorization, ...] index_in_block: Optional[Uint] + transactions_root: Hash32 tx_hash: Optional[Hash32] traces: List[dict] diff --git a/src/ethereum/osaka/vm/instructions/__init__.py b/src/ethereum/osaka/vm/instructions/__init__.py index 9cc30668e7..322ef5cbcf 100644 --- a/src/ethereum/osaka/vm/instructions/__init__.py +++ b/src/ethereum/osaka/vm/instructions/__init__.py @@ -100,6 +100,7 @@ class Ops(enum.Enum): BASEFEE = 0x48 BLOBHASH = 0x49 BLOBBASEFEE = 0x4A + TXROOT = 0x4B # Control Flow Ops STOP = 0x00 @@ -252,6 +253,7 @@ class Ops(enum.Enum): Ops.PREVRANDAO: block_instructions.prev_randao, Ops.GASLIMIT: block_instructions.gas_limit, Ops.CHAINID: block_instructions.chain_id, + Ops.TXROOT: block_instructions.tx_root, Ops.MLOAD: memory_instructions.mload, Ops.MSTORE: memory_instructions.mstore, Ops.MSTORE8: memory_instructions.mstore8, diff --git a/src/ethereum/osaka/vm/instructions/block.py b/src/ethereum/osaka/vm/instructions/block.py index 80644000fd..369ed9318f 100644 --- a/src/ethereum/osaka/vm/instructions/block.py +++ b/src/ethereum/osaka/vm/instructions/block.py @@ -253,3 +253,32 @@ def chain_id(evm: Evm) -> None: # PROGRAM COUNTER evm.pc += Uint(1) + + +def tx_root(evm: Evm) -> None: + """ + Push the incremental transactions root of this block onto the stack. + + Parameters + ---------- + evm : + The current EVM frame. + + Raises + ------ + :py:class:`~ethereum.osaka.vm.exceptions.StackOverflowError` + If `len(stack)` is equal to `1024`. + :py:class:`~ethereum.osaka.vm.exceptions.OutOfGasError` + If `evm.gas_left` is less than `2`. + """ + # STACK + pass + + # GAS + charge_gas(evm, GAS_BASE) + + # OPERATION + push(evm.stack, U256.from_be_bytes(evm.message.tx_env.transactions_root)) + + # PROGRAM COUNTER + evm.pc += Uint(1) From 52b65ab868940926d870d1a2db0fd9c862174c01 Mon Sep 17 00:00:00 2001 From: Brecht Devos Date: Fri, 25 Jul 2025 13:04:01 +0200 Subject: [PATCH 2/2] exclude current transaction --- src/ethereum/osaka/fork.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ethereum/osaka/fork.py b/src/ethereum/osaka/fork.py index 74a9a8dd15..b0db4145da 100644 --- a/src/ethereum/osaka/fork.py +++ b/src/ethereum/osaka/fork.py @@ -852,11 +852,6 @@ def process_transaction( index: Index of the transaction in the block. """ - trie_set( - block_output.transactions_trie, - rlp.encode(index), - encode_transaction(tx), - ) intrinsic_gas, calldata_floor_gas_cost = validate_transaction(tx) @@ -989,6 +984,12 @@ def process_transaction( receipt, ) + trie_set( + block_output.transactions_trie, + rlp.encode(index), + encode_transaction(tx), + ) + block_output.block_logs += tx_output.logs