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 (
@@ -590,6 +590,7 @@ def process_system_transaction(
590
590
target_address : Address ,
591
591
system_contract_code : Bytes ,
592
592
data : Bytes ,
593
+ change_tracker : Optional [StateChangeTracker ] = None ,
593
594
) -> MessageCallOutput :
594
595
"""
595
596
Process a system transaction with the given code.
@@ -646,6 +647,7 @@ def process_system_transaction(
646
647
accessed_storage_keys = set (),
647
648
disable_precompiles = False ,
648
649
parent_evm = None ,
650
+ change_tracker = change_tracker ,
649
651
)
650
652
651
653
system_tx_output = process_message_call (system_tx_message )
@@ -657,6 +659,7 @@ def process_checked_system_transaction(
657
659
block_env : vm .BlockEnvironment ,
658
660
target_address : Address ,
659
661
data : Bytes ,
662
+ change_tracker : Optional [StateChangeTracker ] = None ,
660
663
) -> MessageCallOutput :
661
664
"""
662
665
Process a system transaction and raise an error if the contract does not
@@ -689,6 +692,7 @@ def process_checked_system_transaction(
689
692
target_address ,
690
693
system_contract_code ,
691
694
data ,
695
+ change_tracker ,
692
696
)
693
697
694
698
if system_tx_output .error :
@@ -704,6 +708,7 @@ def process_unchecked_system_transaction(
704
708
block_env : vm .BlockEnvironment ,
705
709
target_address : Address ,
706
710
data : Bytes ,
711
+ change_tracker : Optional [StateChangeTracker ] = None ,
707
712
) -> MessageCallOutput :
708
713
"""
709
714
Process a system transaction without checking if the contract contains code
@@ -729,6 +734,7 @@ def process_unchecked_system_transaction(
729
734
target_address ,
730
735
system_contract_code ,
731
736
data ,
737
+ change_tracker ,
732
738
)
733
739
734
740
@@ -766,16 +772,23 @@ def apply_body(
766
772
# Initialize Block Access List state change tracker
767
773
change_tracker = StateChangeTracker (block_output .block_access_list_builder )
768
774
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
+
769
780
process_unchecked_system_transaction (
770
781
block_env = block_env ,
771
782
target_address = BEACON_ROOTS_ADDRESS ,
772
783
data = block_env .parent_beacon_block_root ,
784
+ change_tracker = change_tracker ,
773
785
)
774
786
775
787
process_unchecked_system_transaction (
776
788
block_env = block_env ,
777
789
target_address = HISTORY_STORAGE_ADDRESS ,
778
790
data = block_env .block_hashes [- 1 ], # The parent hash
791
+ change_tracker = change_tracker ,
779
792
)
780
793
781
794
for i , tx in enumerate (map (decode_transaction , transactions )):
@@ -784,9 +797,13 @@ def apply_body(
784
797
785
798
process_withdrawals (block_env , block_output , withdrawals , change_tracker )
786
799
800
+ # Set system transaction index for post-execution system contracts
801
+ set_system_transaction_index (change_tracker , system_tx_index )
802
+
787
803
process_general_purpose_requests (
788
804
block_env = block_env ,
789
805
block_output = block_output ,
806
+ change_tracker = change_tracker ,
790
807
)
791
808
792
809
return block_output
@@ -795,6 +812,7 @@ def apply_body(
795
812
def process_general_purpose_requests (
796
813
block_env : vm .BlockEnvironment ,
797
814
block_output : vm .BlockOutput ,
815
+ change_tracker : StateChangeTracker ,
798
816
) -> None :
799
817
"""
800
818
Process all the requests in the block.
@@ -816,6 +834,7 @@ def process_general_purpose_requests(
816
834
block_env = block_env ,
817
835
target_address = WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS ,
818
836
data = b"" ,
837
+ change_tracker = change_tracker ,
819
838
)
820
839
821
840
if len (system_withdrawal_tx_output .return_data ) > 0 :
@@ -827,6 +846,7 @@ def process_general_purpose_requests(
827
846
block_env = block_env ,
828
847
target_address = CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS ,
829
848
data = b"" ,
849
+ change_tracker = change_tracker ,
830
850
)
831
851
832
852
if len (system_consolidation_tx_output .return_data ) > 0 :
@@ -1029,9 +1049,9 @@ def increase_recipient_balance(recipient: Account) -> None:
1029
1049
1030
1050
modify_state (block_env .state , wd .address , increase_recipient_balance )
1031
1051
1032
- # Track balance change for BAL
1052
+ # Track balance change for BAL (withdrawals are tracked as system contract changes)
1033
1053
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 )
1035
1055
1036
1056
if account_exists_and_is_empty (block_env .state , wd .address ):
1037
1057
destroy_account (block_env .state , wd .address )
0 commit comments