diff --git a/crates/blockifier_reexecution/src/state_reader/compile.rs b/crates/blockifier_reexecution/src/state_reader/compile.rs index 4088dcea60..7e1f8b901e 100644 --- a/crates/blockifier_reexecution/src/state_reader/compile.rs +++ b/crates/blockifier_reexecution/src/state_reader/compile.rs @@ -10,7 +10,7 @@ use cairo_lang_starknet_classes::contract_class::ContractEntryPoints; use cairo_lang_utils::bigint::BigUintAsHex; use flate2::bufread; use serde::Deserialize; -use starknet_api::contract_class::{ContractClass, EntryPointType}; +use starknet_api::contract_class::{ContractClass, EntryPointType, SierraVersion}; use starknet_api::core::EntryPointSelector; use starknet_api::deprecated_contract_class::{ ContractClass as DeprecatedContractClass, @@ -72,8 +72,11 @@ pub fn decode_reader(bytes: Vec) -> io::Result { Ok(s) } -/// Compile a FlattenedSierraClass to a ContractClass V1 (casm) using cairo_lang_starknet_classes. -pub fn sierra_to_contact_class_v1(sierra: FlattenedSierraClass) -> StateResult { +/// Compile a FlattenedSierraClass to a versioned ContractClass V1 (casm) using +/// cairo_lang_starknet_classes. +pub fn sierra_to_versioned_contract_class_v1( + sierra: FlattenedSierraClass, +) -> StateResult<(ContractClass, SierraVersion)> { let middle_sierra: MiddleSierraContractClass = { let v = serde_json::to_value(sierra).map_err(serde_err_to_state_err); serde_json::from_value(v?).map_err(serde_err_to_state_err)? @@ -86,6 +89,11 @@ pub fn sierra_to_contact_class_v1(sierra: FlattenedSierraClass) -> StateResult>(); + + let sierra_version = SierraVersion::extract_from_program(&sierra_program_values).unwrap(); + let casm = cairo_lang_starknet_classes::casm_contract_class::CasmContractClass::from_contract_class( sierra, @@ -94,7 +102,7 @@ pub fn sierra_to_contact_class_v1(sierra: FlattenedSierraClass) -> StateResult StateResult { match self.get_contract_class(&class_hash)? { StarknetContractClass::Sierra(sierra) => { - Ok(sierra_to_contact_class_v1(sierra).unwrap().try_into().unwrap()) + let (casm, _) = sierra_to_versioned_contract_class_v1(sierra).unwrap(); + Ok(casm.try_into().unwrap()) } StarknetContractClass::Legacy(legacy) => { Ok(legacy_to_contract_class_v0(legacy).unwrap().try_into().unwrap()) diff --git a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs index d6bd84f237..05203c9010 100644 --- a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs @@ -12,7 +12,10 @@ use starknet_api::core::ClassHash; use starknet_api::transaction::{Transaction, TransactionHash}; use starknet_core::types::ContractClass as StarknetContractClass; -use crate::state_reader::compile::{legacy_to_contract_class_v0, sierra_to_contact_class_v1}; +use crate::state_reader::compile::{ + legacy_to_contract_class_v0, + sierra_to_versioned_contract_class_v1, +}; use crate::state_reader::errors::{ReexecutionError, ReexecutionResult}; pub trait ReexecutionStateReader { @@ -24,14 +27,10 @@ pub trait ReexecutionStateReader { let abi_length = sierra.abi.len(); let sierra_length = sierra.sierra_program.len(); - let sierra_version = SierraVersion::extract_from_program(&sierra.sierra_program)?; + let (contract_class, sierra_version) = + sierra_to_versioned_contract_class_v1(sierra)?; - Ok(ClassInfo::new( - &sierra_to_contact_class_v1(sierra)?, - sierra_length, - abi_length, - sierra_version, - )?) + Ok(ClassInfo::new(&contract_class, sierra_length, abi_length, sierra_version)?) } StarknetContractClass::Legacy(legacy) => { let abi_length = diff --git a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs index a17432379a..3158aea484 100644 --- a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs @@ -32,7 +32,10 @@ use starknet_gateway::rpc_state_reader::RpcStateReader; use starknet_types_core::felt::Felt; use crate::retry_request; -use crate::state_reader::compile::{legacy_to_contract_class_v0, sierra_to_contact_class_v1}; +use crate::state_reader::compile::{ + legacy_to_contract_class_v0, + sierra_to_versioned_contract_class_v1, +}; use crate::state_reader::errors::ReexecutionResult; use crate::state_reader::offline_state_reader::SerializableDataNextBlock; use crate::state_reader::reexecution_state_reader::{ @@ -131,7 +134,8 @@ impl StateReader for TestStateReader { match contract_class { StarknetContractClass::Sierra(sierra) => { - Ok(sierra_to_contact_class_v1(sierra).unwrap().try_into().unwrap()) + let (casm, _) = sierra_to_versioned_contract_class_v1(sierra).unwrap(); + Ok(RunnableCompiledClass::try_from(casm).unwrap()) } StarknetContractClass::Legacy(legacy) => { Ok(legacy_to_contract_class_v0(legacy).unwrap().try_into().unwrap())