3030)
3131
3232from . import vm
33- from .block_access_lists import StateChangeTracker , compute_bal_hash , build
33+ from .block_access_lists import StateChangeTracker , compute_bal_hash , build , set_system_transaction_index , track_balance_change
3434from .blocks import Block , Header , Log , Receipt , Withdrawal , encode_receipt
3535from .bloom import logs_bloom
3636from .exceptions import (
@@ -590,6 +590,7 @@ def process_system_transaction(
590590 target_address : Address ,
591591 system_contract_code : Bytes ,
592592 data : Bytes ,
593+ change_tracker : Optional [StateChangeTracker ] = None ,
593594) -> MessageCallOutput :
594595 """
595596 Process a system transaction with the given code.
@@ -646,6 +647,7 @@ def process_system_transaction(
646647 accessed_storage_keys = set (),
647648 disable_precompiles = False ,
648649 parent_evm = None ,
650+ change_tracker = change_tracker ,
649651 )
650652
651653 system_tx_output = process_message_call (system_tx_message )
@@ -657,6 +659,7 @@ def process_checked_system_transaction(
657659 block_env : vm .BlockEnvironment ,
658660 target_address : Address ,
659661 data : Bytes ,
662+ change_tracker : Optional [StateChangeTracker ] = None ,
660663) -> MessageCallOutput :
661664 """
662665 Process a system transaction and raise an error if the contract does not
@@ -689,6 +692,7 @@ def process_checked_system_transaction(
689692 target_address ,
690693 system_contract_code ,
691694 data ,
695+ change_tracker ,
692696 )
693697
694698 if system_tx_output .error :
@@ -704,6 +708,7 @@ def process_unchecked_system_transaction(
704708 block_env : vm .BlockEnvironment ,
705709 target_address : Address ,
706710 data : Bytes ,
711+ change_tracker : Optional [StateChangeTracker ] = None ,
707712) -> MessageCallOutput :
708713 """
709714 Process a system transaction without checking if the contract contains code
@@ -729,6 +734,7 @@ def process_unchecked_system_transaction(
729734 target_address ,
730735 system_contract_code ,
731736 data ,
737+ change_tracker ,
732738 )
733739
734740
@@ -766,16 +772,23 @@ def apply_body(
766772 # Initialize Block Access List state change tracker
767773 change_tracker = StateChangeTracker (block_output .block_access_list_builder )
768774
775+ # Set system transaction index for pre-execution system contracts
776+ # Using len(transactions) + 1 as specified
777+ system_tx_index = len (transactions ) + 1
778+ set_system_transaction_index (change_tracker , system_tx_index )
779+
769780 process_unchecked_system_transaction (
770781 block_env = block_env ,
771782 target_address = BEACON_ROOTS_ADDRESS ,
772783 data = block_env .parent_beacon_block_root ,
784+ change_tracker = change_tracker ,
773785 )
774786
775787 process_unchecked_system_transaction (
776788 block_env = block_env ,
777789 target_address = HISTORY_STORAGE_ADDRESS ,
778790 data = block_env .block_hashes [- 1 ], # The parent hash
791+ change_tracker = change_tracker ,
779792 )
780793
781794 for i , tx in enumerate (map (decode_transaction , transactions )):
@@ -784,9 +797,13 @@ def apply_body(
784797
785798 process_withdrawals (block_env , block_output , withdrawals , change_tracker )
786799
800+ # Set system transaction index for post-execution system contracts
801+ set_system_transaction_index (change_tracker , system_tx_index )
802+
787803 process_general_purpose_requests (
788804 block_env = block_env ,
789805 block_output = block_output ,
806+ change_tracker = change_tracker ,
790807 )
791808
792809 return block_output
@@ -795,6 +812,7 @@ def apply_body(
795812def process_general_purpose_requests (
796813 block_env : vm .BlockEnvironment ,
797814 block_output : vm .BlockOutput ,
815+ change_tracker : StateChangeTracker ,
798816) -> None :
799817 """
800818 Process all the requests in the block.
@@ -816,6 +834,7 @@ def process_general_purpose_requests(
816834 block_env = block_env ,
817835 target_address = WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS ,
818836 data = b"" ,
837+ change_tracker = change_tracker ,
819838 )
820839
821840 if len (system_withdrawal_tx_output .return_data ) > 0 :
@@ -827,6 +846,7 @@ def process_general_purpose_requests(
827846 block_env = block_env ,
828847 target_address = CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS ,
829848 data = b"" ,
849+ change_tracker = change_tracker ,
830850 )
831851
832852 if len (system_consolidation_tx_output .return_data ) > 0 :
@@ -1029,9 +1049,9 @@ def increase_recipient_balance(recipient: Account) -> None:
10291049
10301050 modify_state (block_env .state , wd .address , increase_recipient_balance )
10311051
1032- # Track balance change for BAL
1052+ # Track balance change for BAL (withdrawals are tracked as system contract changes)
10331053 new_balance = get_account (block_env .state , wd .address ).balance
1034- change_tracker . track_balance_change (wd .address , U256 (new_balance ), block_env .state )
1054+ track_balance_change (change_tracker , wd .address , U256 (new_balance ), block_env .state )
10351055
10361056 if account_exists_and_is_empty (block_env .state , wd .address ):
10371057 destroy_account (block_env .state , wd .address )
0 commit comments