30
30
)
31
31
32
32
from . 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
34
34
from .blocks import Block , Header , Log , Receipt , Withdrawal , encode_receipt
35
35
from .bloom import logs_bloom
36
36
from .exceptions import (
@@ -582,6 +582,7 @@ def process_system_transaction(
582
582
target_address : Address ,
583
583
system_contract_code : Bytes ,
584
584
data : Bytes ,
585
+ change_tracker : Optional [StateChangeTracker ] = None ,
585
586
) -> MessageCallOutput :
586
587
"""
587
588
Process a system transaction with the given code.
@@ -639,6 +640,7 @@ def process_system_transaction(
639
640
disable_precompiles = False ,
640
641
warm_code_addresses = set (),
641
642
parent_evm = None ,
643
+ change_tracker = change_tracker ,
642
644
)
643
645
644
646
system_tx_output = process_message_call (system_tx_message )
@@ -650,6 +652,7 @@ def process_checked_system_transaction(
650
652
block_env : vm .BlockEnvironment ,
651
653
target_address : Address ,
652
654
data : Bytes ,
655
+ change_tracker : Optional [StateChangeTracker ] = None ,
653
656
) -> MessageCallOutput :
654
657
"""
655
658
Process a system transaction and raise an error if the contract does not
@@ -682,6 +685,7 @@ def process_checked_system_transaction(
682
685
target_address ,
683
686
system_contract_code ,
684
687
data ,
688
+ change_tracker ,
685
689
)
686
690
687
691
if system_tx_output .error :
@@ -697,6 +701,7 @@ def process_unchecked_system_transaction(
697
701
block_env : vm .BlockEnvironment ,
698
702
target_address : Address ,
699
703
data : Bytes ,
704
+ change_tracker : Optional [StateChangeTracker ] = None ,
700
705
) -> MessageCallOutput :
701
706
"""
702
707
Process a system transaction without checking if the contract contains code
@@ -722,6 +727,7 @@ def process_unchecked_system_transaction(
722
727
target_address ,
723
728
system_contract_code ,
724
729
data ,
730
+ change_tracker ,
725
731
)
726
732
727
733
@@ -759,16 +765,23 @@ def apply_body(
759
765
# Initialize Block Access List state change tracker
760
766
change_tracker = StateChangeTracker (block_output .block_access_list_builder )
761
767
768
+ # Set system transaction index for pre-execution system contracts
769
+ # Using len(transactions) + 1 as specified
770
+ system_tx_index = len (transactions ) + 1
771
+ set_system_transaction_index (change_tracker , system_tx_index )
772
+
762
773
process_unchecked_system_transaction (
763
774
block_env = block_env ,
764
775
target_address = BEACON_ROOTS_ADDRESS ,
765
776
data = block_env .parent_beacon_block_root ,
777
+ change_tracker = change_tracker ,
766
778
)
767
779
768
780
process_unchecked_system_transaction (
769
781
block_env = block_env ,
770
782
target_address = HISTORY_STORAGE_ADDRESS ,
771
783
data = block_env .block_hashes [- 1 ], # The parent hash
784
+ change_tracker = change_tracker ,
772
785
)
773
786
774
787
for i , tx in enumerate (map (decode_transaction , transactions )):
@@ -777,9 +790,13 @@ def apply_body(
777
790
778
791
process_withdrawals (block_env , block_output , withdrawals , change_tracker )
779
792
793
+ # Set system transaction index for post-execution system contracts
794
+ set_system_transaction_index (change_tracker , system_tx_index )
795
+
780
796
process_general_purpose_requests (
781
797
block_env = block_env ,
782
798
block_output = block_output ,
799
+ change_tracker = change_tracker ,
783
800
)
784
801
785
802
return block_output
@@ -788,6 +805,7 @@ def apply_body(
788
805
def process_general_purpose_requests (
789
806
block_env : vm .BlockEnvironment ,
790
807
block_output : vm .BlockOutput ,
808
+ change_tracker : StateChangeTracker ,
791
809
) -> None :
792
810
"""
793
811
Process all the requests in the block.
@@ -809,6 +827,7 @@ def process_general_purpose_requests(
809
827
block_env = block_env ,
810
828
target_address = WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS ,
811
829
data = b"" ,
830
+ change_tracker = change_tracker ,
812
831
)
813
832
814
833
if len (system_withdrawal_tx_output .return_data ) > 0 :
@@ -820,6 +839,7 @@ def process_general_purpose_requests(
820
839
block_env = block_env ,
821
840
target_address = CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS ,
822
841
data = b"" ,
842
+ change_tracker = change_tracker ,
823
843
)
824
844
825
845
if len (system_consolidation_tx_output .return_data ) > 0 :
@@ -1022,9 +1042,9 @@ def increase_recipient_balance(recipient: Account) -> None:
1022
1042
1023
1043
modify_state (block_env .state , wd .address , increase_recipient_balance )
1024
1044
1025
- # Track balance change for BAL
1045
+ # Track balance change for BAL (withdrawals are tracked as system contract changes)
1026
1046
new_balance = get_account (block_env .state , wd .address ).balance
1027
- change_tracker . track_balance_change (wd .address , U256 (new_balance ), block_env .state )
1047
+ track_balance_change (change_tracker , wd .address , U256 (new_balance ), block_env .state )
1028
1048
1029
1049
if account_exists_and_is_empty (block_env .state , wd .address ):
1030
1050
destroy_account (block_env .state , wd .address )
0 commit comments