diff --git a/src/ethereum/osaka/fork.py b/src/ethereum/osaka/fork.py index 22c07e0ae8..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) @@ -921,6 +916,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=[], ) @@ -988,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 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)