From 33ff7261c1abab8bd7672989d206aabfec519fee Mon Sep 17 00:00:00 2001 From: Noa Oved Date: Thu, 31 Oct 2024 14:51:45 +0200 Subject: [PATCH] refactor(blockifier): rename contract class to runnable contract class --- crates/batcher/src/papyrus_state.rs | 15 +++-- .../blockifier/transaction_executor_test.rs | 2 +- .../src/concurrency/versioned_state.rs | 9 ++- .../src/concurrency/versioned_state_test.rs | 21 ++++--- .../src/concurrency/worker_logic_test.rs | 2 +- .../src/execution/contract_class.rs | 62 +++++++++---------- .../src/execution/execution_utils.rs | 26 ++++---- .../syscalls/syscall_tests/library_call.rs | 2 +- crates/blockifier/src/fee/receipt_test.rs | 2 +- crates/blockifier/src/state/cached_state.rs | 16 +++-- .../blockifier/src/state/cached_state_test.rs | 9 +-- crates/blockifier/src/state/global_cache.rs | 8 +-- crates/blockifier/src/state/state_api.rs | 9 ++- crates/blockifier/src/test_utils/contracts.rs | 12 ++-- .../src/test_utils/dict_state_reader.rs | 9 ++- .../src/test_utils/initial_test_state.rs | 4 +- .../src/transaction/account_transaction.rs | 10 +-- .../transaction/account_transactions_test.rs | 6 +- .../blockifier/src/transaction/test_utils.rs | 13 ++-- .../src/transaction/transactions.rs | 4 +- .../src/transaction/transactions_test.rs | 14 ++--- .../src/state_reader/compile.rs | 16 +++-- .../src/state_reader/test_state_reader.rs | 2 +- crates/gateway/src/rpc_state_reader.rs | 15 +++-- crates/gateway/src/rpc_state_reader_test.rs | 4 +- crates/gateway/src/state_reader.rs | 7 ++- crates/gateway/src/state_reader_test_utils.rs | 7 ++- .../src/py_block_executor_test.rs | 5 +- .../native_blockifier/src/py_transaction.rs | 4 +- .../src/state_readers/papyrus_state.rs | 15 +++-- .../src/state_readers/py_state_reader.rs | 17 +++-- .../papyrus_execution/src/execution_utils.rs | 2 +- crates/papyrus_execution/src/lib.rs | 5 +- crates/papyrus_execution/src/state_reader.rs | 2 +- .../src/state_reader_test.rs | 2 +- 35 files changed, 213 insertions(+), 145 deletions(-) diff --git a/crates/batcher/src/papyrus_state.rs b/crates/batcher/src/papyrus_state.rs index 6ef8c8a0d2a..2ee1295f743 100644 --- a/crates/batcher/src/papyrus_state.rs +++ b/crates/batcher/src/papyrus_state.rs @@ -1,6 +1,10 @@ // TODO(yael 22/9/2024): This module is copied from native_blockifier, need to how to share it // between the crates. -use blockifier::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}; +use blockifier::execution::contract_class::{ + ContractClassV0, + ContractClassV1, + RunnableContractClass, +}; use blockifier::state::errors::StateError; use blockifier::state::global_cache::GlobalContractCache; use blockifier::state::state_api::{StateReader, StateResult}; @@ -40,7 +44,7 @@ impl PapyrusReader { fn get_compiled_contract_class_inner( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let state_number = StateNumber(self.latest_block); let class_declaration_block_number = self .reader()? @@ -60,7 +64,7 @@ impl PapyrusReader { inconsistent.", ); - return Ok(ContractClass::V1(ContractClassV1::try_from(casm_contract_class)?)); + return Ok(RunnableContractClass::V1(ContractClassV1::try_from(casm_contract_class)?)); } let v0_contract_class = self @@ -118,7 +122,10 @@ impl StateReader for PapyrusReader { } } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { // Assumption: the global cache is cleared upon reverted blocks. let contract_class = self.global_class_hash_to_class.get(&class_hash); diff --git a/crates/blockifier/src/blockifier/transaction_executor_test.rs b/crates/blockifier/src/blockifier/transaction_executor_test.rs index d739b4662af..a6a20a49b16 100644 --- a/crates/blockifier/src/blockifier/transaction_executor_test.rs +++ b/crates/blockifier/src/blockifier/transaction_executor_test.rs @@ -127,7 +127,7 @@ fn test_declare( version: tx_version, resource_bounds: l1_resource_bounds(0_u8.into(), DEFAULT_STRK_L1_GAS_PRICE.into()), }, - calculate_class_info_for_testing(declared_contract.get_class()), + calculate_class_info_for_testing(declared_contract.get_runnable_class()), ) .into(); tx_executor_test_body(state, block_context, tx, expected_bouncer_weights); diff --git a/crates/blockifier/src/concurrency/versioned_state.rs b/crates/blockifier/src/concurrency/versioned_state.rs index a6edb590ee8..33d97670b9e 100644 --- a/crates/blockifier/src/concurrency/versioned_state.rs +++ b/crates/blockifier/src/concurrency/versioned_state.rs @@ -7,7 +7,7 @@ use starknet_types_core::felt::Felt; use crate::concurrency::versioned_storage::VersionedStorage; use crate::concurrency::TxIndex; -use crate::execution::contract_class::ContractClass; +use crate::execution::contract_class::RunnableContractClass; use crate::state::cached_state::{ContractClassMapping, StateMaps}; use crate::state::errors::StateError; use crate::state::state_api::{StateReader, StateResult, UpdatableState}; @@ -34,7 +34,7 @@ pub struct VersionedState { // the compiled contract classes mapping. Each key with value false, sohuld not apprear // in the compiled contract classes mapping. declared_contracts: VersionedStorage, - compiled_contract_classes: VersionedStorage, + compiled_contract_classes: VersionedStorage, } impl VersionedState { @@ -336,7 +336,10 @@ impl StateReader for VersionedStateProxy { } } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { let mut state = self.state(); match state.compiled_contract_classes.read(self.tx_index, class_hash) { Some(value) => Ok(value), diff --git a/crates/blockifier/src/concurrency/versioned_state_test.rs b/crates/blockifier/src/concurrency/versioned_state_test.rs index 52c5621968d..440b25868c4 100644 --- a/crates/blockifier/src/concurrency/versioned_state_test.rs +++ b/crates/blockifier/src/concurrency/versioned_state_test.rs @@ -79,7 +79,7 @@ fn test_versioned_state_proxy() { let class_hash = class_hash!(27_u8); let another_class_hash = class_hash!(28_u8); let compiled_class_hash = compiled_class_hash!(29_u8); - let contract_class = test_contract.get_class(); + let contract_class = test_contract.get_runnable_class(); // Create the versioned state let cached_state = CachedState::from(DictStateReader { @@ -125,7 +125,8 @@ fn test_versioned_state_proxy() { let class_hash_v7 = class_hash!(28_u8); let class_hash_v10 = class_hash!(29_u8); let compiled_class_hash_v18 = compiled_class_hash!(30_u8); - let contract_class_v11 = FeatureContract::TestContract(CairoVersion::Cairo1).get_class(); + let contract_class_v11 = + FeatureContract::TestContract(CairoVersion::Cairo1).get_runnable_class(); versioned_state_proxys[3].state().apply_writes( 3, @@ -411,7 +412,8 @@ fn test_false_validate_reads_declared_contracts( ..Default::default() }; let version_state_proxy = safe_versioned_state.pin_version(0); - let compiled_contract_calss = FeatureContract::TestContract(CairoVersion::Cairo1).get_class(); + let compiled_contract_calss = + FeatureContract::TestContract(CairoVersion::Cairo1).get_runnable_class(); let class_hash_to_class = HashMap::from([(class_hash!(1_u8), compiled_contract_calss)]); version_state_proxy.state().apply_writes(0, &tx_0_writes, &class_hash_to_class); assert!(!safe_versioned_state.pin_version(1).validate_reads(&tx_1_reads)); @@ -436,7 +438,7 @@ fn test_apply_writes( assert_eq!(transactional_states[0].cache.borrow().writes.class_hashes.len(), 1); // Transaction 0 contract class. - let contract_class_0 = FeatureContract::TestContract(CairoVersion::Cairo1).get_class(); + let contract_class_0 = FeatureContract::TestContract(CairoVersion::Cairo1).get_runnable_class(); assert!(transactional_states[0].class_hash_to_class.borrow().is_empty()); transactional_states[0].set_contract_class(class_hash, contract_class_0.clone()).unwrap(); assert_eq!(transactional_states[0].class_hash_to_class.borrow().len(), 1); @@ -516,7 +518,10 @@ fn test_delete_writes( } // Modify the `class_hash_to_class` member of the CachedState. tx_state - .set_contract_class(feature_contract.get_class_hash(), feature_contract.get_class()) + .set_contract_class( + feature_contract.get_class_hash(), + feature_contract.get_runnable_class(), + ) .unwrap(); safe_versioned_state.pin_version(i).apply_writes( &tx_state.cache.borrow().writes, @@ -575,7 +580,7 @@ fn test_delete_writes_completeness( declared_contracts: HashMap::from([(feature_contract.get_class_hash(), true)]), }; let class_hash_to_class_writes = - HashMap::from([(feature_contract.get_class_hash(), feature_contract.get_class())]); + HashMap::from([(feature_contract.get_class_hash(), feature_contract.get_runnable_class())]); let tx_index = 0; let mut versioned_state_proxy = safe_versioned_state.pin_version(tx_index); @@ -638,9 +643,9 @@ fn test_versioned_proxy_state_flow( transactional_states[3].set_class_hash_at(contract_address, class_hash_3).unwrap(); // Clients contract class values. - let contract_class_0 = FeatureContract::TestContract(CairoVersion::Cairo0).get_class(); + let contract_class_0 = FeatureContract::TestContract(CairoVersion::Cairo0).get_runnable_class(); let contract_class_2 = - FeatureContract::AccountWithLongValidate(CairoVersion::Cairo1).get_class(); + FeatureContract::AccountWithLongValidate(CairoVersion::Cairo1).get_runnable_class(); transactional_states[0].set_contract_class(class_hash, contract_class_0).unwrap(); transactional_states[2].set_contract_class(class_hash, contract_class_2.clone()).unwrap(); diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index 134324d0bf9..53000e205f5 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -560,7 +560,7 @@ fn test_deploy_before_declare( let account_address_1 = account_contract.get_instance_address(1); let test_contract = FeatureContract::TestContract(cairo_version); let test_class_hash = test_contract.get_class_hash(); - let test_class_info = calculate_class_info_for_testing(test_contract.get_class()); + let test_class_info = calculate_class_info_for_testing(test_contract.get_runnable_class()); let test_compiled_class_hash = test_contract.get_compiled_class_hash(); let declare_tx = declare_tx( declare_tx_args! { diff --git a/crates/blockifier/src/execution/contract_class.rs b/crates/blockifier/src/execution/contract_class.rs index d64a0c8c694..a11cd3b42dd 100644 --- a/crates/blockifier/src/execution/contract_class.rs +++ b/crates/blockifier/src/execution/contract_class.rs @@ -21,7 +21,7 @@ use itertools::Itertools; use semver::Version; use serde::de::Error as DeserializationError; use serde::{Deserialize, Deserializer, Serialize}; -use starknet_api::contract_class::{ContractClass as RawContractClass, EntryPointType}; +use starknet_api::contract_class::{ContractClass, EntryPointType}; use starknet_api::core::EntryPointSelector; use starknet_api::deprecated_contract_class::{ ContractClass as DeprecatedContractClass, @@ -62,23 +62,23 @@ pub enum TrackedResource { /// Represents a runnable Starknet contract class (meaning, the program is runnable by the VM). #[derive(Clone, Debug, Eq, PartialEq, derive_more::From)] -pub enum ContractClass { +pub enum RunnableContractClass { V0(ContractClassV0), V1(ContractClassV1), #[cfg(feature = "cairo_native")] V1Native(NativeContractClassV1), } -impl TryFrom for ContractClass { +impl TryFrom for RunnableContractClass { type Error = ProgramError; - fn try_from(raw_contract_class: RawContractClass) -> Result { - let contract_class: ContractClass = match raw_contract_class { - RawContractClass::V0(raw_contract_class) => { - ContractClass::V0(raw_contract_class.try_into()?) + fn try_from(raw_contract_class: ContractClass) -> Result { + let contract_class: RunnableContractClass = match raw_contract_class { + ContractClass::V0(raw_contract_class) => { + RunnableContractClass::V0(raw_contract_class.try_into()?) } - RawContractClass::V1(raw_contract_class) => { - ContractClass::V1(raw_contract_class.try_into()?) + ContractClass::V1(raw_contract_class) => { + RunnableContractClass::V1(raw_contract_class.try_into()?) } }; @@ -86,22 +86,22 @@ impl TryFrom for ContractClass { } } -impl ContractClass { +impl RunnableContractClass { pub fn constructor_selector(&self) -> Option { match self { - ContractClass::V0(class) => class.constructor_selector(), - ContractClass::V1(class) => class.constructor_selector(), + RunnableContractClass::V0(class) => class.constructor_selector(), + RunnableContractClass::V1(class) => class.constructor_selector(), #[cfg(feature = "cairo_native")] - ContractClass::V1Native(class) => class.constructor_selector(), + RunnableContractClass::V1Native(class) => class.constructor_selector(), } } pub fn estimate_casm_hash_computation_resources(&self) -> ExecutionResources { match self { - ContractClass::V0(class) => class.estimate_casm_hash_computation_resources(), - ContractClass::V1(class) => class.estimate_casm_hash_computation_resources(), + RunnableContractClass::V0(class) => class.estimate_casm_hash_computation_resources(), + RunnableContractClass::V1(class) => class.estimate_casm_hash_computation_resources(), #[cfg(feature = "cairo_native")] - ContractClass::V1Native(_) => { + RunnableContractClass::V1Native(_) => { todo!("Use casm to estimate casm hash computation resources") } } @@ -112,12 +112,12 @@ impl ContractClass { visited_pcs: &HashSet, ) -> Result, TransactionExecutionError> { match self { - ContractClass::V0(_) => { + RunnableContractClass::V0(_) => { panic!("get_visited_segments is not supported for v0 contracts.") } - ContractClass::V1(class) => class.get_visited_segments(visited_pcs), + RunnableContractClass::V1(class) => class.get_visited_segments(visited_pcs), #[cfg(feature = "cairo_native")] - ContractClass::V1Native(_) => { + RunnableContractClass::V1Native(_) => { panic!("get_visited_segments is not supported for native contracts.") } } @@ -125,10 +125,10 @@ impl ContractClass { pub fn bytecode_length(&self) -> usize { match self { - ContractClass::V0(class) => class.bytecode_length(), - ContractClass::V1(class) => class.bytecode_length(), + RunnableContractClass::V0(class) => class.bytecode_length(), + RunnableContractClass::V1(class) => class.bytecode_length(), #[cfg(feature = "cairo_native")] - ContractClass::V1Native(_) => { + RunnableContractClass::V1Native(_) => { todo!("implement bytecode_length for native contracts.") } } @@ -137,12 +137,12 @@ impl ContractClass { /// Returns whether this contract should run using Cairo steps or Sierra gas. pub fn tracked_resource(&self, min_sierra_version: &CompilerVersion) -> TrackedResource { match self { - ContractClass::V0(_) => TrackedResource::CairoSteps, - ContractClass::V1(contract_class) => { + RunnableContractClass::V0(_) => TrackedResource::CairoSteps, + RunnableContractClass::V1(contract_class) => { contract_class.tracked_resource(min_sierra_version) } #[cfg(feature = "cairo_native")] - ContractClass::V1Native(_) => TrackedResource::SierraGas, + RunnableContractClass::V1Native(_) => TrackedResource::SierraGas, } } } @@ -530,7 +530,7 @@ fn convert_entry_points_v1(external: &[CasmContractEntryPoint]) -> Vec ContractClass { + pub fn contract_class(&self) -> RunnableContractClass { self.contract_class.clone() } @@ -574,15 +574,15 @@ impl ClassInfo { } pub fn new( - contract_class: &ContractClass, + contract_class: &RunnableContractClass, sierra_program_length: usize, abi_length: usize, ) -> ContractClassResult { let (contract_class_version, condition) = match contract_class { - ContractClass::V0(_) => (0, sierra_program_length == 0), - ContractClass::V1(_) => (1, sierra_program_length > 0), + RunnableContractClass::V0(_) => (0, sierra_program_length == 0), + RunnableContractClass::V1(_) => (1, sierra_program_length > 0), #[cfg(feature = "cairo_native")] - ContractClass::V1Native(_) => (1, sierra_program_length > 0), + RunnableContractClass::V1Native(_) => (1, sierra_program_length > 0), }; if condition { diff --git a/crates/blockifier/src/execution/execution_utils.rs b/crates/blockifier/src/execution/execution_utils.rs index ecd5c20f4b4..44c2abfbc14 100644 --- a/crates/blockifier/src/execution/execution_utils.rs +++ b/crates/blockifier/src/execution/execution_utils.rs @@ -30,7 +30,7 @@ use super::errors::{ }; use super::syscalls::hint_processor::ENTRYPOINT_NOT_FOUND_ERROR; use crate::execution::call_info::{CallInfo, Retdata}; -use crate::execution::contract_class::{ContractClass, TrackedResource}; +use crate::execution::contract_class::{RunnableContractClass, TrackedResource}; use crate::execution::entry_point::{ execute_constructor_entry_point, CallEntryPoint, @@ -54,7 +54,7 @@ pub const SEGMENT_ARENA_BUILTIN_SIZE: usize = 3; /// A wrapper for execute_entry_point_call that performs pre and post-processing. pub fn execute_entry_point_call_wrapper( mut call: CallEntryPoint, - contract_class: ContractClass, + contract_class: RunnableContractClass, state: &mut dyn State, resources: &mut ExecutionResources, context: &mut EntryPointExecutionContext, @@ -118,13 +118,13 @@ pub fn execute_entry_point_call_wrapper( /// Executes a specific call to a contract entry point and returns its output. pub fn execute_entry_point_call( call: CallEntryPoint, - contract_class: ContractClass, + contract_class: RunnableContractClass, state: &mut dyn State, resources: &mut ExecutionResources, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { match contract_class { - ContractClass::V0(contract_class) => { + RunnableContractClass::V0(contract_class) => { deprecated_entry_point_execution::execute_entry_point_call( call, contract_class, @@ -133,15 +133,17 @@ pub fn execute_entry_point_call( context, ) } - ContractClass::V1(contract_class) => entry_point_execution::execute_entry_point_call( - call, - contract_class, - state, - resources, - context, - ), + RunnableContractClass::V1(contract_class) => { + entry_point_execution::execute_entry_point_call( + call, + contract_class, + state, + resources, + context, + ) + } #[cfg(feature = "cairo_native")] - ContractClass::V1Native(contract_class) => { + RunnableContractClass::V1Native(contract_class) => { native_entry_point_execution::execute_entry_point_call( call, contract_class, diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs index 6c2c838be51..4dcf2087edd 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/library_call.rs @@ -149,7 +149,7 @@ fn test_nested_library_call(test_contract: FeatureContract, expected_gas: u64) { }; // The default VersionedConstants is used in the execute_directly call bellow. - let tracked_resource = test_contract.get_class().tracked_resource( + let tracked_resource = test_contract.get_runnable_class().tracked_resource( &VersionedConstants::create_for_testing().min_compiler_version_for_sierra_gas, ); diff --git a/crates/blockifier/src/fee/receipt_test.rs b/crates/blockifier/src/fee/receipt_test.rs index 671b8c32855..ebe9a979eec 100644 --- a/crates/blockifier/src/fee/receipt_test.rs +++ b/crates/blockifier/src/fee/receipt_test.rs @@ -69,7 +69,7 @@ fn test_calculate_tx_gas_usage_basic<'a>( // Declare. for cairo_version in [CairoVersion::Cairo0, CairoVersion::Cairo1] { - let empty_contract = FeatureContract::Empty(cairo_version).get_class(); + let empty_contract = FeatureContract::Empty(cairo_version).get_runnable_class(); let class_info = calculate_class_info_for_testing(empty_contract); let declare_tx_starknet_resources = StarknetResources::new( 0, diff --git a/crates/blockifier/src/state/cached_state.rs b/crates/blockifier/src/state/cached_state.rs index ab51525b8d3..d9a4a598f6f 100644 --- a/crates/blockifier/src/state/cached_state.rs +++ b/crates/blockifier/src/state/cached_state.rs @@ -8,7 +8,7 @@ use starknet_types_core::felt::Felt; use crate::abi::abi_utils::get_fee_token_var_address; use crate::context::TransactionContext; -use crate::execution::contract_class::ContractClass; +use crate::execution::contract_class::RunnableContractClass; use crate::state::errors::StateError; use crate::state::state_api::{State, StateReader, StateResult, UpdatableState}; use crate::transaction::objects::TransactionExecutionInfo; @@ -18,7 +18,7 @@ use crate::utils::{strict_subtract_mappings, subtract_mappings}; #[path = "cached_state_test.rs"] mod test; -pub type ContractClassMapping = HashMap; +pub type ContractClassMapping = HashMap; /// Caches read and write requests. /// @@ -174,7 +174,10 @@ impl StateReader for CachedState { Ok(*class_hash) } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { let mut cache = self.cache.borrow_mut(); let class_hash_to_class = &mut *self.class_hash_to_class.borrow_mut(); @@ -257,7 +260,7 @@ impl State for CachedState { fn set_contract_class( &mut self, class_hash: ClassHash, - contract_class: ContractClass, + contract_class: RunnableContractClass, ) -> StateResult<()> { self.class_hash_to_class.get_mut().insert(class_hash, contract_class); let mut cache = self.cache.borrow_mut(); @@ -493,7 +496,10 @@ impl<'a, S: StateReader + ?Sized> StateReader for MutRefState<'a, S> { self.0.get_class_hash_at(contract_address) } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { self.0.get_compiled_contract_class(class_hash) } diff --git a/crates/blockifier/src/state/cached_state_test.rs b/crates/blockifier/src/state/cached_state_test.rs index de1ad618661..c75b4beb24c 100644 --- a/crates/blockifier/src/state/cached_state_test.rs +++ b/crates/blockifier/src/state/cached_state_test.rs @@ -117,7 +117,7 @@ fn declare_contract() { let mut state = CachedState::from(DictStateReader { ..Default::default() }); let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0); let class_hash = test_contract.get_class_hash(); - let contract_class = test_contract.get_class(); + let contract_class = test_contract.get_runnable_class(); assert_eq!(state.cache.borrow().writes.declared_contracts.get(&class_hash), None); assert_eq!(state.cache.borrow().initial_reads.declared_contracts.get(&class_hash), None); @@ -176,7 +176,7 @@ fn get_contract_class() { let state = test_state(&ChainInfo::create_for_testing(), Fee(0), &[(test_contract, 0)]); assert_eq!( state.get_compiled_contract_class(test_contract.get_class_hash()).unwrap(), - test_contract.get_class() + test_contract.get_runnable_class() ); // Negative flow. @@ -223,7 +223,8 @@ fn cached_state_state_diff_conversion() { // are aligned with. let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0); let test_class_hash = test_contract.get_class_hash(); - let class_hash_to_class = HashMap::from([(test_class_hash, test_contract.get_class())]); + let class_hash_to_class = + HashMap::from([(test_class_hash, test_contract.get_runnable_class())]); let nonce_initial_values = HashMap::new(); @@ -427,7 +428,7 @@ fn test_contract_cache_is_used() { // cache. let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0); let class_hash = test_contract.get_class_hash(); - let contract_class = test_contract.get_class(); + let contract_class = test_contract.get_runnable_class(); let mut reader = DictStateReader::default(); reader.class_hash_to_class.insert(class_hash, contract_class.clone()); let state = CachedState::new(reader); diff --git a/crates/blockifier/src/state/global_cache.rs b/crates/blockifier/src/state/global_cache.rs index 54d71a1fac1..670045fe5f9 100644 --- a/crates/blockifier/src/state/global_cache.rs +++ b/crates/blockifier/src/state/global_cache.rs @@ -3,10 +3,10 @@ use std::sync::{Arc, Mutex, MutexGuard}; use cached::{Cached, SizedCache}; use starknet_api::core::ClassHash; -use crate::execution::contract_class::ContractClass; +use crate::execution::contract_class::RunnableContractClass; // Note: `ContractClassLRUCache` key-value types must align with `ContractClassMapping`. -type ContractClassLRUCache = SizedCache; +type ContractClassLRUCache = SizedCache; pub type LockedContractClassCache<'a> = MutexGuard<'a, ContractClassLRUCache>; #[derive(Debug, Clone)] // Thread-safe LRU cache for contract classes, optimized for inter-language sharing when @@ -23,11 +23,11 @@ impl GlobalContractCache { self.0.lock().expect("Global contract cache is poisoned.") } - pub fn get(&self, class_hash: &ClassHash) -> Option { + pub fn get(&self, class_hash: &ClassHash) -> Option { self.lock().cache_get(class_hash).cloned() } - pub fn set(&self, class_hash: ClassHash, contract_class: ContractClass) { + pub fn set(&self, class_hash: ClassHash, contract_class: RunnableContractClass) { self.lock().cache_set(class_hash, contract_class); } diff --git a/crates/blockifier/src/state/state_api.rs b/crates/blockifier/src/state/state_api.rs index b6c20b2e456..8d430a18929 100644 --- a/crates/blockifier/src/state/state_api.rs +++ b/crates/blockifier/src/state/state_api.rs @@ -7,7 +7,7 @@ use starknet_types_core::felt::Felt; use super::cached_state::{ContractClassMapping, StateMaps}; use crate::abi::abi_utils::get_fee_token_var_address; use crate::abi::sierra_types::next_storage_key; -use crate::execution::contract_class::ContractClass; +use crate::execution::contract_class::RunnableContractClass; use crate::state::errors::StateError; pub type StateResult = Result; @@ -41,7 +41,10 @@ pub trait StateReader { fn get_class_hash_at(&self, contract_address: ContractAddress) -> StateResult; /// Returns the contract class of the given class hash. - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult; + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult; /// Returns the compiled class hash of the given class hash. fn get_compiled_class_hash(&self, class_hash: ClassHash) -> StateResult; @@ -94,7 +97,7 @@ pub trait State: StateReader { fn set_contract_class( &mut self, class_hash: ClassHash, - contract_class: ContractClass, + contract_class: RunnableContractClass, ) -> StateResult<()>; /// Sets the given compiled class hash under the given class hash. diff --git a/crates/blockifier/src/test_utils/contracts.rs b/crates/blockifier/src/test_utils/contracts.rs index 9180885f513..a418a313841 100644 --- a/crates/blockifier/src/test_utils/contracts.rs +++ b/crates/blockifier/src/test_utils/contracts.rs @@ -17,7 +17,7 @@ use strum_macros::EnumIter; use crate::abi::abi_utils::selector_from_name; use crate::abi::constants::CONSTRUCTOR_ENTRY_POINT_NAME; -use crate::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}; +use crate::execution::contract_class::{ContractClassV0, ContractClassV1, RunnableContractClass}; use crate::execution::entry_point::CallEntryPoint; use crate::test_utils::cairo_compile::{cairo0_compile, cairo1_compile}; use crate::test_utils::{get_raw_contract_class, CairoVersion}; @@ -154,7 +154,7 @@ impl FeatureContract { contract_address!(self.get_integer_base() + instance_id_as_u32 + ADDRESS_BIT) } - pub fn get_class(&self) -> ContractClass { + pub fn get_runnable_class(&self) -> RunnableContractClass { match self.cairo_version() { CairoVersion::Cairo0 => ContractClassV0::from_file(&self.get_compiled_path()).into(), CairoVersion::Cairo1 => ContractClassV1::from_file(&self.get_compiled_path()).into(), @@ -316,8 +316,8 @@ impl FeatureContract { entry_point_selector: EntryPointSelector, entry_point_type: EntryPointType, ) -> EntryPointOffset { - match self.get_class() { - ContractClass::V0(class) => { + match self.get_runnable_class() { + RunnableContractClass::V0(class) => { class .entry_points_by_type .get(&entry_point_type) @@ -327,7 +327,7 @@ impl FeatureContract { .unwrap() .offset } - ContractClass::V1(class) => { + RunnableContractClass::V1(class) => { class .entry_points_by_type .get_entry_point(&CallEntryPoint { @@ -339,7 +339,7 @@ impl FeatureContract { .offset } #[cfg(feature = "cairo_native")] - ContractClass::V1Native(_) => { + RunnableContractClass::V1Native(_) => { panic!("Not implemented for cairo native contracts") } } diff --git a/crates/blockifier/src/test_utils/dict_state_reader.rs b/crates/blockifier/src/test_utils/dict_state_reader.rs index 54fcd890e21..469e6cbdb7d 100644 --- a/crates/blockifier/src/test_utils/dict_state_reader.rs +++ b/crates/blockifier/src/test_utils/dict_state_reader.rs @@ -4,7 +4,7 @@ use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; -use crate::execution::contract_class::ContractClass; +use crate::execution::contract_class::RunnableContractClass; use crate::state::cached_state::StorageEntry; use crate::state::errors::StateError; use crate::state::state_api::{StateReader, StateResult}; @@ -15,7 +15,7 @@ pub struct DictStateReader { pub storage_view: HashMap, pub address_to_nonce: HashMap, pub address_to_class_hash: HashMap, - pub class_hash_to_class: HashMap, + pub class_hash_to_class: HashMap, pub class_hash_to_compiled_class_hash: HashMap, } @@ -35,7 +35,10 @@ impl StateReader for DictStateReader { Ok(nonce) } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { let contract_class = self.class_hash_to_class.get(&class_hash).cloned(); match contract_class { Some(contract_class) => Ok(contract_class), diff --git a/crates/blockifier/src/test_utils/initial_test_state.rs b/crates/blockifier/src/test_utils/initial_test_state.rs index 6962244bfc7..82711da2ef3 100644 --- a/crates/blockifier/src/test_utils/initial_test_state.rs +++ b/crates/blockifier/src/test_utils/initial_test_state.rs @@ -49,7 +49,7 @@ pub fn test_state_inner( // Declare and deploy account and ERC20 contracts. let erc20 = FeatureContract::ERC20(erc20_contract_version); - class_hash_to_class.insert(erc20.get_class_hash(), erc20.get_class()); + class_hash_to_class.insert(erc20.get_class_hash(), erc20.get_runnable_class()); address_to_class_hash .insert(chain_info.fee_token_address(&FeeType::Eth), erc20.get_class_hash()); address_to_class_hash @@ -58,7 +58,7 @@ pub fn test_state_inner( // Set up the rest of the requested contracts. for (contract, n_instances) in contract_instances.iter() { let class_hash = contract.get_class_hash(); - class_hash_to_class.insert(class_hash, contract.get_class()); + class_hash_to_class.insert(class_hash, contract.get_runnable_class()); for instance in 0..*n_instances { let instance_address = contract.get_instance_address(instance); address_to_class_hash.insert(instance_address, class_hash); diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 930aa990eb8..76bad0b168a 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -24,7 +24,7 @@ use starknet_types_core::felt::Felt; use crate::abi::abi_utils::selector_from_name; use crate::context::{BlockContext, TransactionContext}; use crate::execution::call_info::CallInfo; -use crate::execution::contract_class::ContractClass; +use crate::execution::contract_class::RunnableContractClass; use crate::execution::entry_point::{CallEntryPoint, CallType, EntryPointExecutionContext}; use crate::execution::stack_trace::extract_trailing_cairo1_revert_trace; use crate::fee::fee_checks::{FeeCheckReportFields, PostExecutionReport}; @@ -959,11 +959,11 @@ impl ValidatableTransaction for AccountTransaction { } } -pub fn is_cairo1(contract_class: &ContractClass) -> bool { +pub fn is_cairo1(contract_class: &RunnableContractClass) -> bool { match contract_class { - ContractClass::V0(_) => false, - ContractClass::V1(_) => true, + RunnableContractClass::V0(_) => false, + RunnableContractClass::V1(_) => true, #[cfg(feature = "cairo_native")] - ContractClass::V1Native(_) => true, + RunnableContractClass::V1Native(_) => true, } } diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index b9ab6a09804..68264ef29c4 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -48,7 +48,7 @@ use crate::abi::abi_utils::{ use crate::check_tx_execution_error_for_invalid_scenario; use crate::context::{BlockContext, TransactionContext}; use crate::execution::call_info::CallInfo; -use crate::execution::contract_class::{ContractClass, ContractClassV1}; +use crate::execution::contract_class::{ContractClassV1, RunnableContractClass}; use crate::execution::entry_point::EntryPointExecutionContext; use crate::execution::syscalls::SyscallSelector; use crate::fee::fee_utils::{get_fee_by_gas_vector, get_sequencer_balance_keys}; @@ -442,7 +442,7 @@ fn test_max_fee_limit_validate( let grindy_validate_account = FeatureContract::AccountWithLongValidate(CairoVersion::Cairo1); let grindy_class_hash = grindy_validate_account.get_class_hash(); let block_info = &block_context.block_info; - let class_info = calculate_class_info_for_testing(grindy_validate_account.get_class()); + let class_info = calculate_class_info_for_testing(grindy_validate_account.get_runnable_class()); // Declare the grindy-validation account. let account_tx = declare_tx( @@ -749,7 +749,7 @@ fn test_fail_declare(block_context: BlockContext, max_fee: Fee) { let TestInitData { mut state, account_address, mut nonce_manager, .. } = create_test_init_data(chain_info, CairoVersion::Cairo0); let class_hash = class_hash!(0xdeadeadeaf72_u128); - let contract_class = ContractClass::V1(ContractClassV1::empty_for_testing()); + let contract_class = RunnableContractClass::V1(ContractClassV1::empty_for_testing()); let next_nonce = nonce_manager.next(account_address); // Cannot fail executing a declare tx unless it's V2 or above, and already declared. diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 0dd1bb6bcd8..01c7573cea4 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -25,7 +25,7 @@ use strum::IntoEnumIterator; use crate::abi::abi_utils::get_fee_token_var_address; use crate::context::{BlockContext, ChainInfo}; -use crate::execution::contract_class::{ClassInfo, ContractClass}; +use crate::execution::contract_class::{ClassInfo, RunnableContractClass}; use crate::state::cached_state::CachedState; use crate::state::state_api::State; use crate::test_utils::contracts::FeatureContract; @@ -259,7 +259,8 @@ pub fn create_account_tx_for_validate_test( } }; let class_hash = declared_contract.get_class_hash(); - let class_info = calculate_class_info_for_testing(declared_contract.get_class()); + let class_info = + calculate_class_info_for_testing(declared_contract.get_runnable_class()); declare_tx( declare_tx_args! { max_fee, @@ -374,12 +375,12 @@ pub fn create_all_resource_bounds( }) } -pub fn calculate_class_info_for_testing(contract_class: ContractClass) -> ClassInfo { +pub fn calculate_class_info_for_testing(contract_class: RunnableContractClass) -> ClassInfo { let sierra_program_length = match contract_class { - ContractClass::V0(_) => 0, - ContractClass::V1(_) => 100, + RunnableContractClass::V0(_) => 0, + RunnableContractClass::V1(_) => 100, #[cfg(feature = "cairo_native")] - ContractClass::V1Native(_) => 100, + RunnableContractClass::V1Native(_) => 100, }; ClassInfo::new(&contract_class, sierra_program_length, 100).unwrap() } diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index 56785195e59..94dad4bfa63 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -18,7 +18,7 @@ use starknet_api::transaction::{ use crate::abi::abi_utils::selector_from_name; use crate::context::{BlockContext, TransactionContext}; use crate::execution::call_info::CallInfo; -use crate::execution::contract_class::{ClassInfo, ContractClass}; +use crate::execution::contract_class::{ClassInfo, RunnableContractClass}; use crate::execution::entry_point::{ CallEntryPoint, CallType, @@ -212,7 +212,7 @@ impl DeclareTransaction { self.tx_hash } - pub fn contract_class(&self) -> ContractClass { + pub fn contract_class(&self) -> RunnableContractClass { self.class_info.contract_class() } diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index ef409f29b4a..ab1e620ea19 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -469,7 +469,7 @@ fn test_invoke_tx( let actual_execution_info = account_tx.execute(state, block_context, true, true).unwrap(); let tracked_resource = account_contract - .get_class() + .get_runnable_class() .tracked_resource(&versioned_constants.min_compiler_version_for_sierra_gas); // Build expected validate call info. @@ -984,7 +984,7 @@ fn test_max_fee_exceeds_balance( // Declare. let contract_to_declare = FeatureContract::Empty(CairoVersion::Cairo1); - let class_info = calculate_class_info_for_testing(contract_to_declare.get_class()); + let class_info = calculate_class_info_for_testing(contract_to_declare.get_runnable_class()); let invalid_tx = declare_tx( declare_tx_args! { class_hash: contract_to_declare.get_class_hash(), @@ -1447,7 +1447,7 @@ fn test_declare_tx( let state = &mut test_state(chain_info, BALANCE, &[(account, 1)]); let class_hash = empty_contract.get_class_hash(); let compiled_class_hash = empty_contract.get_compiled_class_hash(); - let class_info = calculate_class_info_for_testing(empty_contract.get_class()); + let class_info = calculate_class_info_for_testing(empty_contract.get_runnable_class()); let sender_address = account.get_instance_address(0); let mut nonce_manager = NonceManager::default(); let state_changes_for_fee = declare_expected_state_changes_count(tx_version); @@ -1490,7 +1490,7 @@ fn test_declare_tx( account.get_class_hash(), sender_address, account - .get_class() + .get_runnable_class() .tracked_resource(&versioned_constants.min_compiler_version_for_sierra_gas), if tx_version >= TransactionVersion::THREE { user_initial_gas_from_bounds(default_l1_resource_bounds) @@ -1608,7 +1608,7 @@ fn test_declare_tx_v0(default_l1_resource_bounds: ValidResourceBounds) { let state = &mut test_state(chain_info, BALANCE, &[(account, 1)]); let class_hash = empty_contract.get_class_hash(); let compiled_class_hash = empty_contract.get_compiled_class_hash(); - let class_info = calculate_class_info_for_testing(empty_contract.get_class()); + let class_info = calculate_class_info_for_testing(empty_contract.get_runnable_class()); let sender_address = account.get_instance_address(0); let mut nonce_manager = NonceManager::default(); @@ -1686,7 +1686,7 @@ fn test_deploy_account_tx( deployed_account_address, cairo_version, account - .get_class() + .get_runnable_class() .tracked_resource(&versioned_constants.min_compiler_version_for_sierra_gas), user_initial_gas_from_bounds(default_l1_resource_bounds), ); @@ -2211,7 +2211,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { }, accessed_storage_keys: HashSet::from_iter(vec![accessed_storage_key]), tracked_resource: test_contract - .get_class() + .get_runnable_class() .tracked_resource(&versioned_constants.min_compiler_version_for_sierra_gas), ..Default::default() }; diff --git a/crates/blockifier_reexecution/src/state_reader/compile.rs b/crates/blockifier_reexecution/src/state_reader/compile.rs index 96ab2675d17..7422a6e31ce 100644 --- a/crates/blockifier_reexecution/src/state_reader/compile.rs +++ b/crates/blockifier_reexecution/src/state_reader/compile.rs @@ -6,7 +6,11 @@ use std::collections::HashMap; use std::io::{self, Read}; use std::sync::Arc; -use blockifier::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV0Inner}; +use blockifier::execution::contract_class::{ + ContractClassV0, + ContractClassV0Inner, + RunnableContractClass, +}; use blockifier::state::state_api::StateResult; use cairo_lang_starknet_classes::contract_class::ContractEntryPoints; use cairo_lang_utils::bigint::BigUintAsHex; @@ -71,7 +75,9 @@ pub fn decode_reader(bytes: Vec) -> io::Result { } /// Compile a FlattenedSierraClass to a ContractClass V1 (casm) using cairo_lang_starknet_classes. -pub fn sierra_to_contact_class_v1(sierra: FlattenedSierraClass) -> StateResult { +pub fn sierra_to_contact_class_v1( + sierra: FlattenedSierraClass, +) -> StateResult { 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)? @@ -91,16 +97,16 @@ pub fn sierra_to_contact_class_v1(sierra: FlattenedSierraClass) -> StateResult StateResult { +) -> StateResult { let as_str = decode_reader(legacy.program).unwrap(); let program = Program::from_bytes(as_str.as_bytes(), None).unwrap(); let entry_points_by_type = map_entry_points_by_type_legacy(legacy.entry_points_by_type); let inner = Arc::new(ContractClassV0Inner { program, entry_points_by_type }); - Ok(ContractClass::V0(ContractClassV0(inner))) + Ok(RunnableContractClass::V0(ContractClassV0(inner))) } 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 6c30e7321dd..bc120dccdde 100644 --- a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs @@ -3,7 +3,7 @@ use blockifier::blockifier::config::TransactionExecutorConfig; use blockifier::blockifier::transaction_executor::TransactionExecutor; use blockifier::bouncer::BouncerConfig; use blockifier::context::BlockContext; -use blockifier::execution::contract_class::ContractClass as BlockifierContractClass; +use blockifier::execution::contract_class::RunnableContractClass as BlockifierContractClass; use blockifier::state::cached_state::{CachedState, CommitmentStateDiff}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader, StateResult}; diff --git a/crates/gateway/src/rpc_state_reader.rs b/crates/gateway/src/rpc_state_reader.rs index 60fec240bdf..39c325b003f 100644 --- a/crates/gateway/src/rpc_state_reader.rs +++ b/crates/gateway/src/rpc_state_reader.rs @@ -1,5 +1,9 @@ use blockifier::blockifier::block::BlockInfo; -use blockifier::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}; +use blockifier::execution::contract_class::{ + ContractClassV0, + ContractClassV1, + RunnableContractClass, +}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; use papyrus_rpc::CompiledContractClass; @@ -125,7 +129,10 @@ impl BlockifierStateReader for RpcStateReader { } } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { let get_compiled_class_params = GetCompiledContractClassParams { class_hash, block_id: self.block_id }; @@ -134,10 +141,10 @@ impl BlockifierStateReader for RpcStateReader { let contract_class: CompiledContractClass = serde_json::from_value(result).map_err(serde_err_to_state_err)?; match contract_class { - CompiledContractClass::V1(contract_class_v1) => Ok(ContractClass::V1( + CompiledContractClass::V1(contract_class_v1) => Ok(RunnableContractClass::V1( ContractClassV1::try_from(contract_class_v1).map_err(StateError::ProgramError)?, )), - CompiledContractClass::V0(contract_class_v0) => Ok(ContractClass::V0( + CompiledContractClass::V0(contract_class_v0) => Ok(RunnableContractClass::V0( ContractClassV0::try_from(contract_class_v0).map_err(StateError::ProgramError)?, )), } diff --git a/crates/gateway/src/rpc_state_reader_test.rs b/crates/gateway/src/rpc_state_reader_test.rs index 4fa099d00a9..e38405cee84 100644 --- a/crates/gateway/src/rpc_state_reader_test.rs +++ b/crates/gateway/src/rpc_state_reader_test.rs @@ -1,4 +1,4 @@ -use blockifier::execution::contract_class::ContractClass; +use blockifier::execution::contract_class::RunnableContractClass; use blockifier::state::state_api::StateReader; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use papyrus_rpc::CompiledContractClass; @@ -182,7 +182,7 @@ async fn test_get_compiled_contract_class() { .await .unwrap() .unwrap(); - assert_eq!(result, ContractClass::V1(expected_result.try_into().unwrap())); + assert_eq!(result, RunnableContractClass::V1(expected_result.try_into().unwrap())); mock.assert_async().await; } diff --git a/crates/gateway/src/state_reader.rs b/crates/gateway/src/state_reader.rs index 0aa555b0509..993fe4b5d55 100644 --- a/crates/gateway/src/state_reader.rs +++ b/crates/gateway/src/state_reader.rs @@ -1,5 +1,5 @@ use blockifier::blockifier::block::BlockInfo; -use blockifier::execution::contract_class::ContractClass; +use blockifier::execution::contract_class::RunnableContractClass; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; #[cfg(test)] @@ -45,7 +45,10 @@ impl BlockifierStateReader for Box { self.as_ref().get_class_hash_at(contract_address) } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { self.as_ref().get_compiled_contract_class(class_hash) } diff --git a/crates/gateway/src/state_reader_test_utils.rs b/crates/gateway/src/state_reader_test_utils.rs index c080a3e0d79..d2b33bc6a57 100644 --- a/crates/gateway/src/state_reader_test_utils.rs +++ b/crates/gateway/src/state_reader_test_utils.rs @@ -1,6 +1,6 @@ use blockifier::blockifier::block::BlockInfo; use blockifier::context::BlockContext; -use blockifier::execution::contract_class::ContractClass; +use blockifier::execution::contract_class::RunnableContractClass; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; use blockifier::test_utils::contracts::FeatureContract; @@ -44,7 +44,10 @@ impl BlockifierStateReader for TestStateReader { self.blockifier_state_reader.get_class_hash_at(contract_address) } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { self.blockifier_state_reader.get_compiled_contract_class(class_hash) } diff --git a/crates/native_blockifier/src/py_block_executor_test.rs b/crates/native_blockifier/src/py_block_executor_test.rs index 4a62edd47ee..7f6aee1c885 100644 --- a/crates/native_blockifier/src/py_block_executor_test.rs +++ b/crates/native_blockifier/src/py_block_executor_test.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use blockifier::blockifier::transaction_executor::BLOCK_STATE_ACCESS_ERR; -use blockifier::execution::contract_class::{ContractClass, ContractClassV1}; +use blockifier::execution::contract_class::{ContractClassV1, RunnableContractClass}; use blockifier::state::state_api::StateReader; use cached::Cached; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; @@ -20,7 +20,8 @@ use crate::test_utils::MockStorage; fn global_contract_cache_update() { // Initialize executor and set a contract class on the state. let casm = CasmContractClass { compiler_version: "0.1.0".to_string(), ..Default::default() }; - let contract_class = ContractClass::V1(ContractClassV1::try_from(casm.clone()).unwrap()); + let contract_class = + RunnableContractClass::V1(ContractClassV1::try_from(casm.clone()).unwrap()); let class_hash = class_hash!("0x1"); let temp_storage_path = tempfile::tempdir().unwrap().into_path(); diff --git a/crates/native_blockifier/src/py_transaction.rs b/crates/native_blockifier/src/py_transaction.rs index f4c54aa395b..8e04dd5dbf4 100644 --- a/crates/native_blockifier/src/py_transaction.rs +++ b/crates/native_blockifier/src/py_transaction.rs @@ -2,9 +2,9 @@ use std::collections::BTreeMap; use blockifier::execution::contract_class::{ ClassInfo, - ContractClass, ContractClassV0, ContractClassV1, + RunnableContractClass, }; use blockifier::transaction::account_transaction::AccountTransaction; use blockifier::transaction::transaction_execution::Transaction; @@ -170,7 +170,7 @@ impl PyClassInfo { py_class_info: PyClassInfo, tx: &starknet_api::transaction::DeclareTransaction, ) -> NativeBlockifierResult { - let contract_class: ContractClass = match tx { + let contract_class: RunnableContractClass = match tx { starknet_api::transaction::DeclareTransaction::V0(_) | starknet_api::transaction::DeclareTransaction::V1(_) => { ContractClassV0::try_from_json_string(&py_class_info.raw_contract_class)?.into() diff --git a/crates/native_blockifier/src/state_readers/papyrus_state.rs b/crates/native_blockifier/src/state_readers/papyrus_state.rs index 463d242b0cb..bdf38d748cc 100644 --- a/crates/native_blockifier/src/state_readers/papyrus_state.rs +++ b/crates/native_blockifier/src/state_readers/papyrus_state.rs @@ -1,4 +1,8 @@ -use blockifier::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}; +use blockifier::execution::contract_class::{ + ContractClassV0, + ContractClassV1, + RunnableContractClass, +}; use blockifier::state::errors::StateError; use blockifier::state::global_cache::GlobalContractCache; use blockifier::state::state_api::{StateReader, StateResult}; @@ -43,7 +47,7 @@ impl PapyrusReader { fn get_compiled_contract_class_inner( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let state_number = StateNumber(self.latest_block); let class_declaration_block_number = self .reader()? @@ -63,7 +67,7 @@ impl PapyrusReader { inconsistent.", ); - return Ok(ContractClass::V1(ContractClassV1::try_from(casm_contract_class)?)); + return Ok(RunnableContractClass::V1(ContractClassV1::try_from(casm_contract_class)?)); } let v0_contract_class = self @@ -121,7 +125,10 @@ impl StateReader for PapyrusReader { } } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { // Assumption: the global cache is cleared upon reverted blocks. let contract_class = self.global_class_hash_to_class.get(&class_hash); diff --git a/crates/native_blockifier/src/state_readers/py_state_reader.rs b/crates/native_blockifier/src/state_readers/py_state_reader.rs index 35d78eea15b..f379dcb05bf 100644 --- a/crates/native_blockifier/src/state_readers/py_state_reader.rs +++ b/crates/native_blockifier/src/state_readers/py_state_reader.rs @@ -1,4 +1,8 @@ -use blockifier::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}; +use blockifier::execution::contract_class::{ + ContractClassV0, + ContractClassV1, + RunnableContractClass, +}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader, StateResult}; use pyo3::{FromPyObject, PyAny, PyErr, PyObject, PyResult, Python}; @@ -64,8 +68,11 @@ impl StateReader for PyStateReader { .map_err(|err| StateError::StateReadError(err.to_string())) } - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { - Python::with_gil(|py| -> Result { + fn get_compiled_contract_class( + &self, + class_hash: ClassHash, + ) -> StateResult { + Python::with_gil(|py| -> Result { let args = (PyFelt::from(class_hash),); let py_raw_compiled_class: PyRawCompiledClass = self .state_reader_proxy @@ -73,7 +80,7 @@ impl StateReader for PyStateReader { .call_method1("get_raw_compiled_class", args)? .extract()?; - Ok(ContractClass::try_from(py_raw_compiled_class)?) + Ok(RunnableContractClass::try_from(py_raw_compiled_class)?) }) .map_err(|err| { if Python::with_gil(|py| err.is_instance_of::(py)) { @@ -103,7 +110,7 @@ pub struct PyRawCompiledClass { pub version: usize, } -impl TryFrom for ContractClass { +impl TryFrom for RunnableContractClass { type Error = NativeBlockifierError; fn try_from(raw_compiled_class: PyRawCompiledClass) -> NativeBlockifierResult { diff --git a/crates/papyrus_execution/src/execution_utils.rs b/crates/papyrus_execution/src/execution_utils.rs index 439a903c23a..ca9d377519c 100644 --- a/crates/papyrus_execution/src/execution_utils.rs +++ b/crates/papyrus_execution/src/execution_utils.rs @@ -5,9 +5,9 @@ use std::path::PathBuf; // Expose the tool for creating entry point selectors from function names. pub use blockifier::abi::abi_utils::selector_from_name; use blockifier::execution::contract_class::{ - ContractClass as BlockifierContractClass, ContractClassV0, ContractClassV1, + RunnableContractClass as BlockifierContractClass, }; use blockifier::state::cached_state::{CachedState, CommitmentStateDiff, MutRefState}; use blockifier::state::state_api::StateReader; diff --git a/crates/papyrus_execution/src/lib.rs b/crates/papyrus_execution/src/lib.rs index 60305adc9f4..0dd79411ba9 100644 --- a/crates/papyrus_execution/src/lib.rs +++ b/crates/papyrus_execution/src/lib.rs @@ -27,7 +27,10 @@ use blockifier::blockifier::block::{pre_process_block, BlockInfo, GasPrices}; use blockifier::bouncer::BouncerConfig; use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}; use blockifier::execution::call_info::CallExecution; -use blockifier::execution::contract_class::{ClassInfo, ContractClass as BlockifierContractClass}; +use blockifier::execution::contract_class::{ + ClassInfo, + RunnableContractClass as BlockifierContractClass, +}; use blockifier::execution::entry_point::{ CallEntryPoint, CallType as BlockifierCallType, diff --git a/crates/papyrus_execution/src/state_reader.rs b/crates/papyrus_execution/src/state_reader.rs index a15df3c3c83..aac0cfa21c3 100644 --- a/crates/papyrus_execution/src/state_reader.rs +++ b/crates/papyrus_execution/src/state_reader.rs @@ -5,9 +5,9 @@ mod state_reader_test; use std::cell::Cell; use blockifier::execution::contract_class::{ - ContractClass as BlockifierContractClass, ContractClassV0, ContractClassV1, + RunnableContractClass as BlockifierContractClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; diff --git a/crates/papyrus_execution/src/state_reader_test.rs b/crates/papyrus_execution/src/state_reader_test.rs index e3ae9866f94..3a13e2ae6b3 100644 --- a/crates/papyrus_execution/src/state_reader_test.rs +++ b/crates/papyrus_execution/src/state_reader_test.rs @@ -2,9 +2,9 @@ use std::cell::Cell; use assert_matches::assert_matches; use blockifier::execution::contract_class::{ - ContractClass as BlockifierContractClass, ContractClassV0, ContractClassV1, + RunnableContractClass as BlockifierContractClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::StateReader;