@@ -7,11 +7,11 @@ use revm::{
77 bytecode:: Bytecode ,
88 context:: { cfg:: CfgEnv , ContextTr } ,
99 context_interface:: { block:: BlobExcessGasAndPrice , result:: HaltReason } ,
10- database:: { states:: bundle_state:: BundleRetention , EmptyDB , State } ,
10+ database:: { bal :: BalDatabase , states:: bundle_state:: BundleRetention , EmptyDB , State } ,
1111 handler:: EvmTr ,
1212 inspector:: inspectors:: TracerEip3155 ,
1313 primitives:: { hardfork:: SpecId , hex, Address , HashMap , U256 } ,
14- state:: AccountInfo ,
14+ state:: { bal :: Bal , AccountInfo } ,
1515 Context , Database , ExecuteCommitEvm , ExecuteEvm , InspectEvm , MainBuilder , MainContext ,
1616} ;
1717use serde_json:: json;
@@ -21,6 +21,7 @@ use statetest_types::blockchain::{
2121use std:: collections:: BTreeMap ;
2222use std:: fs;
2323use std:: path:: { Path , PathBuf } ;
24+ use std:: sync:: Arc ;
2425use std:: time:: Instant ;
2526use thiserror:: Error ;
2627use walkdir:: { DirEntry , WalkDir } ;
@@ -646,7 +647,7 @@ fn execute_blockchain_test(
646647 }
647648
648649 // Create database with initial state
649- let mut state = State :: builder ( ) . build ( ) ;
650+ let mut state = BalDatabase :: new ( State :: builder ( ) . build ( ) ) ;
650651
651652 // Capture pre-state for debug info
652653 let mut pre_state_debug = HashMap :: new ( ) ;
@@ -659,6 +660,7 @@ fn execute_blockchain_test(
659660 nonce : account. nonce ,
660661 code_hash : revm:: primitives:: keccak256 ( & account. code ) ,
661662 code : Some ( Bytecode :: new_raw ( account. code . clone ( ) ) ) ,
663+ storage_id : None ,
662664 } ;
663665
664666 // Store for debug info
@@ -715,6 +717,14 @@ fn execute_blockchain_test(
715717 this_excess_blob_gas = None ;
716718 }
717719
720+ let bal_test = block
721+ . block_access_list
722+ . as_ref ( )
723+ . and_then ( |bal| Bal :: try_from ( bal. clone ( ) ) . ok ( ) )
724+ . map ( Arc :: new) ;
725+
726+ state = state. with_bal_option ( bal_test) . reset_bal_index ( ) ;
727+
718728 // Create EVM context for each transaction to ensure fresh state access
719729 let evm_context = Context :: mainnet ( )
720730 . with_block ( & block_env)
@@ -800,6 +810,9 @@ fn execute_blockchain_test(
800810 }
801811 } ;
802812
813+ // bump bal index
814+ evm. db_mut ( ) . bump_bal_index ( ) ;
815+
803816 // If JSON output requested, output transaction details
804817 let execution_result = if json_output {
805818 evm. inspect_tx ( tx_env. clone ( ) )
@@ -909,6 +922,9 @@ fn execute_blockchain_test(
909922 }
910923 }
911924
925+ // bump bal index
926+ evm. db_mut ( ) . bump_bal_index ( ) ;
927+
912928 // uncle rewards are not implemented yet
913929 post_block:: post_block_transition (
914930 & mut evm,
@@ -922,6 +938,19 @@ fn execute_blockchain_test(
922938 . block_hashes
923939 . insert ( block_env. number . to :: < u64 > ( ) , block_hash. unwrap_or_default ( ) ) ;
924940
941+ if let Some ( bal) = state. bal_state . bal_builder . take ( ) {
942+ if let Some ( state_bal) = state. bal_state . bal . as_ref ( ) {
943+ if & bal != state_bal. as_ref ( ) {
944+ println ! ( "Bal mismatch" ) ;
945+ println ! ( "Test bal" ) ;
946+ state_bal. pretty_print ( ) ;
947+ println ! ( "Bal:" ) ;
948+ bal. pretty_print ( ) ;
949+ return Err ( TestExecutionError :: BalMismatchError ) ;
950+ }
951+ }
952+ }
953+
925954 parent_block_hash = block_hash;
926955 if let Some ( excess_blob_gas) = this_excess_blob_gas {
927956 parent_excess_blob_gas = excess_blob_gas;
@@ -975,7 +1004,8 @@ fn fork_to_spec_id(fork: ForkSpec) -> SpecId {
9751004 ForkSpec :: Cancun | ForkSpec :: ShanghaiToCancunAtTime15k => SpecId :: CANCUN ,
9761005 ForkSpec :: Prague | ForkSpec :: CancunToPragueAtTime15k => SpecId :: PRAGUE ,
9771006 ForkSpec :: Osaka | ForkSpec :: PragueToOsakaAtTime15k => SpecId :: OSAKA ,
978- _ => SpecId :: OSAKA , // For any unknown forks, use latest available
1007+ ForkSpec :: Amsterdam => SpecId :: AMSTERDAM ,
1008+ _ => SpecId :: AMSTERDAM , // For any unknown forks, use latest available
9791009 }
9801010}
9811011
@@ -1080,6 +1110,9 @@ pub enum TestExecutionError {
10801110 gas_used : u64 ,
10811111 } ,
10821112
1113+ #[ error( "BAL error" ) ]
1114+ BalMismatchError ,
1115+
10831116 #[ error(
10841117 "Post-state validation failed for {address:?}.{field}: expected {expected}, got {actual}"
10851118 ) ]
0 commit comments