@@ -9,26 +9,18 @@ use blockifier::blockifier::config::{
99 ContractClassManagerConfig ,
1010} ;
1111use blockifier:: context:: ChainInfo ;
12- use blockifier:: state:: cached_state:: CommitmentStateDiff ;
1312use blockifier:: state:: contract_class_manager:: ContractClassManager ;
14- use starknet_api:: block:: { BlockInfo , BlockNumber , StarknetVersion } ;
15- use starknet_api:: block_hash:: block_hash_calculator:: {
16- calculate_block_commitments,
17- calculate_block_hash,
18- PartialBlockHashComponents ,
19- TransactionHashingData ,
20- } ;
13+ use starknet_api:: block:: BlockNumber ;
14+ #[ cfg( feature = "cairo_native" ) ]
15+ use starknet_api:: block_hash:: block_hash_calculator:: TransactionHashingData ;
2116#[ cfg( feature = "cairo_native" ) ]
2217use starknet_api:: contract_class:: SierraVersion ;
2318
2419use crate :: errors:: { RPCStateReaderError , ReexecutionError , ReexecutionResult } ;
2520use crate :: state_reader:: config:: RpcStateReaderConfig ;
2621use crate :: state_reader:: reexecution_state_reader:: { BlockReexecutor , ReexecuteBlockOutcome } ;
27- use crate :: state_reader:: rpc_objects:: BlockHeader ;
2822use crate :: state_reader:: rpc_state_reader:: RpcBlockReexecutor ;
29- use crate :: utils:: { compare_state_diffs, get_chain_info} ;
30- // Block hash comparison is only valid for Starknet v0.14.0 and later.
31- const MIN_VERSION_FOR_BLOCK_HASH_COMPARISON : & str = "0.14.0" ;
23+ use crate :: utils:: { compare_block_hash, compare_state_diffs, get_chain_info} ;
3224
3325struct ReplayCounters {
3426 matched : AtomicU64 ,
@@ -351,62 +343,6 @@ fn compare_tx_hashing_data(
351343 false
352344}
353345
354- /// Computes the block hash from the reexecution output and compares it against the expected hash
355- /// from the chain. Returns `true` if they match, or if the block predates v0.14.0 (skipped).
356- ///
357- /// Uses the state root from the RPC block header (`new_root`) since the blockifier does not
358- /// compute state roots. If the state diff already matched, the state root should also match.
359- ///
360- /// Note: Blocks before v0.14.0 may include deprecated (Cairo 0) declared classes which are not
361- /// represented in [`CommitmentStateDiff`]; those blocks skip hash comparison below.
362- async fn compare_block_hash (
363- txs_hashing_data : Vec < TransactionHashingData > ,
364- actual_state_diff : CommitmentStateDiff ,
365- block_header : & BlockHeader ,
366- block_number : BlockNumber ,
367- ) -> ReexecutionResult < bool > {
368- let starknet_version: StarknetVersion = block_header. starknet_version . clone ( ) . try_into ( ) ?;
369-
370- let min_version: StarknetVersion =
371- MIN_VERSION_FOR_BLOCK_HASH_COMPARISON . try_into ( ) . expect ( "Invalid min version constant." ) ;
372- if starknet_version < min_version {
373- tracing:: debug!(
374- "Block {block_number}: skipping block hash comparison (version {} < {})." ,
375- block_header. starknet_version,
376- MIN_VERSION_FOR_BLOCK_HASH_COMPARISON
377- ) ;
378- return Ok ( true ) ;
379- }
380-
381- let ( commitments, _measurements) = calculate_block_commitments (
382- & txs_hashing_data,
383- actual_state_diff. into ( ) ,
384- block_header. l1_da_mode ,
385- & starknet_version,
386- )
387- . await ;
388-
389- let block_info: BlockInfo = block_header. clone ( ) . try_into ( ) ?;
390- let partial_block_hash_components = PartialBlockHashComponents :: new ( & block_info, commitments) ;
391-
392- let computed_hash = calculate_block_hash (
393- & partial_block_hash_components,
394- block_header. new_root ,
395- block_header. parent_hash ,
396- ) ?;
397-
398- if computed_hash == block_header. block_hash {
399- Ok ( true )
400- } else {
401- tracing:: warn!(
402- "Block hash mismatch for block {block_number}.\n expected: {}\n actual: {}" ,
403- block_header. block_hash,
404- computed_hash,
405- ) ;
406- Ok ( false )
407- }
408- }
409-
410346fn is_block_not_found ( err : & ReexecutionError ) -> bool {
411347 matches ! ( err, ReexecutionError :: Rpc ( RPCStateReaderError :: BlockNotFound ( _) ) )
412348}
0 commit comments