1717
1818from ethereum_rlp import rlp
1919from ethereum_types .bytes import Bytes
20- from ethereum_types .numeric import U64 , U256 , Uint
20+ from ethereum_types .numeric import U64 , U256 , Uint , ulen
2121
2222from ethereum .crypto .hash import Hash32 , keccak256
2323from ethereum .exceptions import (
3333from .block_access_lists .builder import build
3434from .block_access_lists .rlp_utils import compute_block_access_list_hash
3535from .block_access_lists .tracker import (
36- StateChangeTracker ,
3736 set_transaction_index ,
3837 track_balance_change ,
3938)
@@ -250,11 +249,8 @@ def state_transition(chain: BlockChain, block: Block) -> None:
250249 block_logs_bloom = logs_bloom (block_output .block_logs )
251250 withdrawals_root = root (block_output .withdrawals_trie )
252251 requests_hash = compute_requests_hash (block_output .requests )
253-
254- # Build and validate Block Access List
255- computed_block_access_list = build (block_output .block_access_list_builder )
256252 computed_block_access_list_hash = compute_block_access_list_hash (
257- computed_block_access_list
253+ block_output . block_access_list
258254 )
259255
260256 if block_output .block_gas_used != block .header .gas_used :
@@ -596,7 +592,6 @@ def process_system_transaction(
596592 target_address : Address ,
597593 system_contract_code : Bytes ,
598594 data : Bytes ,
599- change_tracker : Optional [StateChangeTracker ] = None ,
600595) -> MessageCallOutput :
601596 """
602597 Process a system transaction with the given code.
@@ -615,8 +610,6 @@ def process_system_transaction(
615610 Code of the contract to call.
616611 data :
617612 Data to pass to the contract.
618- change_tracker :
619- The state change tracker instance.
620613
621614 Returns
622615 -------
@@ -654,7 +647,6 @@ def process_system_transaction(
654647 accessed_storage_keys = set (),
655648 disable_precompiles = False ,
656649 parent_evm = None ,
657- change_tracker = change_tracker ,
658650 )
659651
660652 system_tx_output = process_message_call (system_tx_message )
@@ -666,7 +658,6 @@ def process_checked_system_transaction(
666658 block_env : vm .BlockEnvironment ,
667659 target_address : Address ,
668660 data : Bytes ,
669- change_tracker : Optional [StateChangeTracker ] = None ,
670661) -> MessageCallOutput :
671662 """
672663 Process a system transaction and raise an error if the contract does not
@@ -680,8 +671,6 @@ def process_checked_system_transaction(
680671 Address of the contract to call.
681672 data :
682673 Data to pass to the contract.
683- change_tracker :
684- The state change tracker instance.
685674
686675 Returns
687676 -------
@@ -701,7 +690,6 @@ def process_checked_system_transaction(
701690 target_address ,
702691 system_contract_code ,
703692 data ,
704- change_tracker ,
705693 )
706694
707695 if system_tx_output .error :
@@ -717,7 +705,6 @@ def process_unchecked_system_transaction(
717705 block_env : vm .BlockEnvironment ,
718706 target_address : Address ,
719707 data : Bytes ,
720- change_tracker : Optional [StateChangeTracker ] = None ,
721708) -> MessageCallOutput :
722709 """
723710 Process a system transaction without checking if the contract contains code
@@ -745,7 +732,6 @@ def process_unchecked_system_transaction(
745732 target_address ,
746733 system_contract_code ,
747734 data ,
748- change_tracker ,
749735 )
750736
751737
@@ -780,44 +766,39 @@ def apply_body(
780766 """
781767 block_output = vm .BlockOutput ()
782768
783- # Initialize Block Access List state change tracker
784- change_tracker = StateChangeTracker (block_output .block_access_list_builder )
785-
786769 # Set system transaction index for pre-execution system contracts
787770 # EIP-7928: System contracts use bal_index 0
788- set_transaction_index (change_tracker , 0 )
771+ set_transaction_index (block_env . state . change_tracker , Uint ( 0 ) )
789772
790773 process_unchecked_system_transaction (
791774 block_env = block_env ,
792775 target_address = BEACON_ROOTS_ADDRESS ,
793776 data = block_env .parent_beacon_block_root ,
794- change_tracker = change_tracker ,
795777 )
796778
797779 process_unchecked_system_transaction (
798780 block_env = block_env ,
799781 target_address = HISTORY_STORAGE_ADDRESS ,
800782 data = block_env .block_hashes [- 1 ], # The parent hash
801- change_tracker = change_tracker ,
802783 )
803784
804- # EIP-7928: Transactions use bal_index 1 to len(transactions)
805785 for i , tx in enumerate (map (decode_transaction , transactions )):
806- set_transaction_index (change_tracker , i + 1 )
807786 process_transaction (
808- block_env , block_output , tx , Uint (i ), change_tracker
787+ block_env , block_output , tx , Uint (i )
809788 )
810789
811790 # EIP-7928: Post-execution uses bal_index len(transactions) + 1
812- post_execution_index = len (transactions ) + 1
813- set_transaction_index (change_tracker , post_execution_index )
791+ post_execution_index = ulen (transactions ) + Uint ( 1 )
792+ set_transaction_index (block_env . state . change_tracker , post_execution_index )
814793
815- process_withdrawals (block_env , block_output , withdrawals , change_tracker )
794+ process_withdrawals (block_env , block_output , withdrawals )
816795
817796 process_general_purpose_requests (
818797 block_env = block_env ,
819798 block_output = block_output ,
820- change_tracker = change_tracker ,
799+ )
800+ block_output .block_access_list = build (
801+ block_env .state .change_tracker .block_access_list_builder
821802 )
822803
823804 return block_output
@@ -826,7 +807,6 @@ def apply_body(
826807def process_general_purpose_requests (
827808 block_env : vm .BlockEnvironment ,
828809 block_output : vm .BlockOutput ,
829- change_tracker : StateChangeTracker ,
830810) -> None :
831811 """
832812 Process all the requests in the block.
@@ -837,8 +817,6 @@ def process_general_purpose_requests(
837817 The execution environment for the Block.
838818 block_output :
839819 The block output for the current block.
840- change_tracker :
841- The state change tracker instance.
842820 """
843821 # Requests are to be in ascending order of request type
844822 deposit_requests = parse_deposit_requests (block_output )
@@ -850,7 +828,6 @@ def process_general_purpose_requests(
850828 block_env = block_env ,
851829 target_address = WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS ,
852830 data = b"" ,
853- change_tracker = change_tracker ,
854831 )
855832
856833 if len (system_withdrawal_tx_output .return_data ) > 0 :
@@ -862,7 +839,6 @@ def process_general_purpose_requests(
862839 block_env = block_env ,
863840 target_address = CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS ,
864841 data = b"" ,
865- change_tracker = change_tracker ,
866842 )
867843
868844 if len (system_consolidation_tx_output .return_data ) > 0 :
@@ -877,7 +853,6 @@ def process_transaction(
877853 block_output : vm .BlockOutput ,
878854 tx : Transaction ,
879855 index : Uint ,
880- change_tracker : StateChangeTracker ,
881856) -> None :
882857 """
883858 Execute a transaction against the provided environment.
@@ -901,9 +876,10 @@ def process_transaction(
901876 Transaction to execute.
902877 index:
903878 Index of the transaction in the block.
904- change_tracker :
905- The state change tracker instance.
906879 """
880+ # EIP-7928: Transactions use bal_index 1 to len(transactions)
881+ set_transaction_index (block_env .state .change_tracker , index + Uint (1 ))
882+
907883 trie_set (
908884 block_output .transactions_trie ,
909885 rlp .encode (index ),
@@ -933,7 +909,7 @@ def process_transaction(
933909 effective_gas_fee = tx .gas * effective_gas_price
934910
935911 gas = tx .gas - intrinsic_gas
936- increment_nonce (block_env .state , sender , change_tracker )
912+ increment_nonce (block_env .state , sender )
937913
938914 sender_balance_after_gas_fee = (
939915 Uint (sender_account .balance ) - effective_gas_fee - blob_gas_fee
@@ -942,7 +918,6 @@ def process_transaction(
942918 block_env .state ,
943919 sender ,
944920 U256 (sender_balance_after_gas_fee ),
945- change_tracker ,
946921 )
947922
948923 access_list_addresses = set ()
@@ -980,7 +955,6 @@ def process_transaction(
980955 )
981956
982957 message = prepare_message (block_env , tx_env , tx )
983- message .change_tracker = change_tracker
984958
985959 tx_output = process_message_call (message )
986960
@@ -1010,7 +984,7 @@ def process_transaction(
1010984 block_env .state , sender
1011985 ).balance + U256 (gas_refund_amount )
1012986 set_account_balance (
1013- block_env .state , sender , sender_balance_after_refund , change_tracker
987+ block_env .state , sender , sender_balance_after_refund
1014988 )
1015989
1016990 # transfer miner fees
@@ -1022,7 +996,6 @@ def process_transaction(
1022996 block_env .state ,
1023997 block_env .coinbase ,
1024998 coinbase_balance_after_mining_fee ,
1025- change_tracker ,
1026999 )
10271000 elif account_exists_and_is_empty (block_env .state , block_env .coinbase ):
10281001 destroy_account (block_env .state , block_env .coinbase )
@@ -1053,7 +1026,6 @@ def process_withdrawals(
10531026 block_env : vm .BlockEnvironment ,
10541027 block_output : vm .BlockOutput ,
10551028 withdrawals : Tuple [Withdrawal , ...],
1056- change_tracker : StateChangeTracker ,
10571029) -> None :
10581030 """
10591031 Increase the balance of the withdrawing account.
@@ -1074,7 +1046,9 @@ def increase_recipient_balance(recipient: Account) -> None:
10741046 # Track balance change for BAL
10751047 # (withdrawals are tracked as system contract changes)
10761048 new_balance = get_account (block_env .state , wd .address ).balance
1077- track_balance_change (change_tracker , wd .address , U256 (new_balance ))
1049+ track_balance_change (
1050+ block_env .state .change_tracker , wd .address , U256 (new_balance )
1051+ )
10781052
10791053 if account_exists_and_is_empty (block_env .state , wd .address ):
10801054 destroy_account (block_env .state , wd .address )
0 commit comments