Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use blockifier::state::state_reader_and_contract_manager::{
FetchCompiledClasses,
StateReaderAndContractManager,
};
use blockifier::state::utils::get_compiled_class_hash_v2 as default_get_compiled_class_hash_v2;
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockHash, BlockHashAndNumber, BlockInfo, BlockNumber, StarknetVersion};
Expand All @@ -31,7 +32,6 @@ use crate::errors::ReexecutionResult;
use crate::state_reader::reexecution_state_reader::{
ConsecutiveReexecutionStateReaders,
ReexecutionStateReader,
DUMMY_COMPILED_CLASS_HASH,
};
use crate::state_reader::rpc_state_reader::StarknetContractClassMapping;
use crate::utils::get_chain_info;
Expand Down Expand Up @@ -110,12 +110,16 @@ impl From<SerializableOfflineReexecutionData> for OfflineReexecutionData {
.api_txs_to_blockifier_txs_next_block(transactions_next_block)
.expect("Failed to convert starknet-api transactions to blockifier transactions.");

// Disable casm hash migration for reexecution.
let mut versioned_constants = VersionedConstants::get(&starknet_version).unwrap().clone();
versioned_constants.enable_casm_hash_migration = false;

Self {
offline_state_reader_prev_block,
block_context_next_block: BlockContext::new(
block_info_next_block,
get_chain_info(&chain_id),
VersionedConstants::get(&starknet_version).unwrap().clone(),
versioned_constants,
BouncerConfig::max(),
),
transactions_next_block,
Expand Down Expand Up @@ -171,23 +175,16 @@ impl StateReader for OfflineStateReader {
}
}

/// Returns a dummy compiled class hash for reexecution purposes.
///
/// This method is required since v0.14.1 for checking if compiled class hashes
/// need to be migrated from v1 to v2 format.
/// In reexecution we use a dummy value for both get_compiled_class_hash and
/// get_compiled_class_hash_v2, to avoid the migration process.
fn get_compiled_class_hash(&self, _class_hash: ClassHash) -> StateResult<CompiledClassHash> {
Ok(DUMMY_COMPILED_CLASS_HASH)
unimplemented!("The offline state reader does not support get_compiled_class_hash.")
}

/// returns the same value as get_compiled_class_hash, to avoid the migration process.
fn get_compiled_class_hash_v2(
&self,
class_hash: ClassHash,
_compiled_class: &RunnableCompiledClass,
compiled_class: &RunnableCompiledClass,
) -> StateResult<CompiledClassHash> {
self.get_compiled_class_hash(class_hash)
default_get_compiled_class_hash_v2(self, class_hash, compiled_class)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ use blockifier::transaction::account_transaction::ExecutionFlags;
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
use starknet_api::block::{BlockHash, BlockNumber};
use starknet_api::contract_class::{ClassInfo, SierraVersion};
use starknet_api::core::{ClassHash, CompiledClassHash};
use starknet_api::core::ClassHash;
use starknet_api::state::SierraContractClass;
use starknet_api::test_utils::MAX_FEE;
use starknet_api::transaction::{Transaction, TransactionHash};
use starknet_core::types::{ContractClass as StarknetContractClass, Felt};
use starknet_core::types::ContractClass as StarknetContractClass;

use crate::assert_eq_state_diff;
use crate::compile::{legacy_to_contract_class_v0, sierra_to_versioned_contract_class_v1};
use crate::errors::ReexecutionResult;
use crate::utils::contract_class_to_compiled_classes;

pub const DUMMY_COMPILED_CLASS_HASH: CompiledClassHash = CompiledClassHash(Felt::ONE);

pub trait ReexecutionStateReader {
fn get_contract_class(&self, class_hash: &ClassHash) -> StateResult<StarknetContractClass>;

Expand Down
27 changes: 13 additions & 14 deletions crates/blockifier_reexecution/src/state_reader/rpc_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use blockifier::state::state_reader_and_contract_manager::{
FetchCompiledClasses,
StateReaderAndContractManager,
};
use blockifier::state::utils::get_compiled_class_hash_v2 as default_get_compiled_class_hash_v2;
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
use serde::Serialize;
use serde_json::{json, Value};
Expand Down Expand Up @@ -54,7 +55,6 @@ use crate::state_reader::offline_state_reader::{
use crate::state_reader::reexecution_state_reader::{
ConsecutiveReexecutionStateReaders,
ReexecutionStateReader,
DUMMY_COMPILED_CLASS_HASH,
};
use crate::utils::{
disjoint_hashmap_union,
Expand Down Expand Up @@ -156,23 +156,16 @@ impl StateReader for RpcStateReader {
}
}

/// Returns a dummy compiled class hash for reexecution purposes.
///
/// This method is required since v0.14.1 for checking if compiled class hashes
/// need to be migrated from v1 to v2 format.
/// In reexecution we use a dummy value for both get_compiled_class_hash and
/// get_compiled_class_hash_v2, to avoid the migration process.
fn get_compiled_class_hash(&self, _class_hash: ClassHash) -> StateResult<CompiledClassHash> {
Ok(DUMMY_COMPILED_CLASS_HASH)
unimplemented!("The rpc state reader does not support get_compiled_class_hash.")
}

/// returns the same value as get_compiled_class_hash, to avoid the migration process.
fn get_compiled_class_hash_v2(
&self,
class_hash: ClassHash,
_compiled_class: &RunnableCompiledClass,
compiled_class: &RunnableCompiledClass,
) -> StateResult<CompiledClassHash> {
self.get_compiled_class_hash(class_hash)
default_get_compiled_class_hash_v2(self, class_hash, compiled_class)
}
}

Expand Down Expand Up @@ -291,15 +284,19 @@ impl RpcStateReader {
.collect::<Result<_, _>>()
}

pub fn get_versioned_constants(&self) -> ReexecutionResult<&'static VersionedConstants> {
Ok(VersionedConstants::get(&self.get_starknet_version()?)?)
pub fn get_versioned_constants(&self) -> ReexecutionResult<VersionedConstants> {
let mut vc = VersionedConstants::get(&self.get_starknet_version()?)?.clone();
// Casm hash migration is not supported. It requires compiled class hashes, and the
// reexecution state readers do not have them.
vc.enable_casm_hash_migration = false;
Ok(vc)
}

pub fn get_block_context(&self) -> ReexecutionResult<BlockContext> {
Ok(BlockContext::new(
self.get_block_info()?,
get_chain_info(&self.chain_id),
self.get_versioned_constants()?.clone(),
self.get_versioned_constants()?,
BouncerConfig::max(),
))
}
Expand Down Expand Up @@ -330,6 +327,8 @@ impl RpcStateReader {
)?)
}

/// Get the commitment state diff of the current block.
/// Note: the commitment state diff does not include migrated_compiled_classes.
pub fn get_state_diff(&self) -> ReexecutionResult<CommitmentStateDiff> {
let raw_statediff =
&retry_request!(self.retry_config, || self.rpc_state_reader.send_rpc_request(
Expand Down