diff --git a/crates/blockifier/src/blockifier/transaction_executor.rs b/crates/blockifier/src/blockifier/transaction_executor.rs index af9d216e1bc..01be23df90c 100644 --- a/crates/blockifier/src/blockifier/transaction_executor.rs +++ b/crates/blockifier/src/blockifier/transaction_executor.rs @@ -161,7 +161,7 @@ impl TransactionExecutor { .block_state .as_ref() .expect(BLOCK_STATE_ACCESS_ERR) - .get_compiled_contract_class(*class_hash)?; + .get_compiled_class(*class_hash)?; Ok((*class_hash, contract_class.get_visited_segments(class_visited_pcs)?)) }) .collect::>()?; diff --git a/crates/blockifier/src/bouncer.rs b/crates/blockifier/src/bouncer.rs index 414fff93a9b..7788b06be06 100644 --- a/crates/blockifier/src/bouncer.rs +++ b/crates/blockifier/src/bouncer.rs @@ -551,7 +551,7 @@ pub fn get_casm_hash_calculation_resources( let mut casm_hash_computation_resources = ExecutionResources::default(); for class_hash in executed_class_hashes { - let class = state_reader.get_compiled_contract_class(*class_hash)?; + let class = state_reader.get_compiled_class(*class_hash)?; casm_hash_computation_resources += &class.estimate_casm_hash_computation_resources(); } diff --git a/crates/blockifier/src/concurrency/versioned_state.rs b/crates/blockifier/src/concurrency/versioned_state.rs index 33d97670b9e..1d3c9a9270a 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::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; 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,14 +336,11 @@ impl StateReader for VersionedStateProxy { } } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_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), - None => match state.initial_state.get_compiled_contract_class(class_hash) { + None => match state.initial_state.get_compiled_class(class_hash) { Ok(initial_value) => { state.declared_contracts.set_initial_value(class_hash, true); state diff --git a/crates/blockifier/src/concurrency/versioned_state_test.rs b/crates/blockifier/src/concurrency/versioned_state_test.rs index 991723acfba..c817263ddc2 100644 --- a/crates/blockifier/src/concurrency/versioned_state_test.rs +++ b/crates/blockifier/src/concurrency/versioned_state_test.rs @@ -97,12 +97,9 @@ fn test_versioned_state_proxy() { versioned_state_proxys[5].get_compiled_class_hash(class_hash).unwrap(), compiled_class_hash ); - assert_eq!( - versioned_state_proxys[7].get_compiled_contract_class(class_hash).unwrap(), - contract_class - ); + assert_eq!(versioned_state_proxys[7].get_compiled_class(class_hash).unwrap(), contract_class); assert_matches!( - versioned_state_proxys[7].get_compiled_contract_class(another_class_hash).unwrap_err(), + versioned_state_proxys[7].get_compiled_class(another_class_hash).unwrap_err(), StateError::UndeclaredClassHash(class_hash) if another_class_hash == class_hash ); @@ -197,7 +194,7 @@ fn test_versioned_state_proxy() { compiled_class_hash_v18 ); assert_eq!( - versioned_state_proxys[15].get_compiled_contract_class(class_hash).unwrap(), + versioned_state_proxys[15].get_compiled_class(class_hash).unwrap(), contract_class_v11 ); } @@ -321,7 +318,7 @@ fn test_validate_reads( assert!(transactional_state.cache.borrow().initial_reads.declared_contracts.is_empty()); assert_matches!( - transactional_state.get_compiled_contract_class(class_hash), + transactional_state.get_compiled_class(class_hash), Err(StateError::UndeclaredClassHash(err_class_hash)) if err_class_hash == class_hash ); @@ -440,10 +437,7 @@ fn test_apply_writes( &HashMap::default(), ); assert!(transactional_states[1].get_class_hash_at(contract_address).unwrap() == class_hash_0); - assert!( - transactional_states[1].get_compiled_contract_class(class_hash).unwrap() - == contract_class_0 - ); + assert!(transactional_states[1].get_compiled_class(class_hash).unwrap() == contract_class_0); } #[rstest] @@ -659,7 +653,5 @@ fn test_versioned_proxy_state_flow( .commit_chunk_and_recover_block_state(4, HashMap::new()); assert!(modified_block_state.get_class_hash_at(contract_address).unwrap() == class_hash_3); - assert!( - modified_block_state.get_compiled_contract_class(class_hash).unwrap() == contract_class_2 - ); + assert!(modified_block_state.get_compiled_class(class_hash).unwrap() == contract_class_2); } diff --git a/crates/blockifier/src/execution/contract_class.rs b/crates/blockifier/src/execution/contract_class.rs index c1c6eec8044..cf3d7289f9b 100644 --- a/crates/blockifier/src/execution/contract_class.rs +++ b/crates/blockifier/src/execution/contract_class.rs @@ -37,7 +37,7 @@ use crate::execution::entry_point::CallEntryPoint; use crate::execution::errors::PreExecutionError; use crate::execution::execution_utils::{poseidon_hash_many_cost, sn_api_to_cairo_vm_program}; #[cfg(feature = "cairo_native")] -use crate::execution::native::contract_class::NativeContractClassV1; +use crate::execution::native::contract_class::NativeCompiledClassV1; use crate::transaction::errors::TransactionExecutionError; use crate::versioned_constants::CompilerVersion; @@ -58,16 +58,17 @@ pub enum TrackedResource { SierraGas, // AKA Sierra mode. } -/// Represents a runnable Starknet contract class (meaning, the program is runnable by the VM). +/// Represents a runnable Starknet compiled class. +/// Meaning, the program is runnable by the VM (or natively). #[derive(Clone, Debug, Eq, PartialEq, derive_more::From)] -pub enum RunnableContractClass { - V0(ContractClassV0), - V1(ContractClassV1), +pub enum RunnableCompiledClass { + V0(CompiledClassV0), + V1(CompiledClassV1), #[cfg(feature = "cairo_native")] - V1Native(NativeContractClassV1), + V1Native(NativeCompiledClassV1), } -impl TryFrom for RunnableContractClass { +impl TryFrom for RunnableCompiledClass { type Error = ProgramError; fn try_from(raw_contract_class: ContractClass) -> Result { @@ -80,7 +81,7 @@ impl TryFrom for RunnableContractClass { } } -impl RunnableContractClass { +impl RunnableCompiledClass { pub fn constructor_selector(&self) -> Option { match self { Self::V0(class) => class.constructor_selector(), @@ -156,16 +157,16 @@ impl RunnableContractClass { // Note: when deserializing from a SN API class JSON string, the ABI field is ignored // by serde, since it is not required for execution. #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] -pub struct ContractClassV0(pub Arc); -impl Deref for ContractClassV0 { - type Target = ContractClassV0Inner; +pub struct CompiledClassV0(pub Arc); +impl Deref for CompiledClassV0 { + type Target = CompiledClassV0Inner; fn deref(&self) -> &Self::Target { &self.0 } } -impl ContractClassV0 { +impl CompiledClassV0 { fn constructor_selector(&self) -> Option { Some(self.entry_points_by_type[&EntryPointType::Constructor].first()?.selector) } @@ -201,24 +202,24 @@ impl ContractClassV0 { TrackedResource::CairoSteps } - pub fn try_from_json_string(raw_contract_class: &str) -> Result { - let contract_class: ContractClassV0Inner = serde_json::from_str(raw_contract_class)?; - Ok(ContractClassV0(Arc::new(contract_class))) + pub fn try_from_json_string(raw_contract_class: &str) -> Result { + let contract_class: CompiledClassV0Inner = serde_json::from_str(raw_contract_class)?; + Ok(CompiledClassV0(Arc::new(contract_class))) } } #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] -pub struct ContractClassV0Inner { +pub struct CompiledClassV0Inner { #[serde(deserialize_with = "deserialize_program")] pub program: Program, pub entry_points_by_type: HashMap>, } -impl TryFrom for ContractClassV0 { +impl TryFrom for CompiledClassV0 { type Error = ProgramError; fn try_from(class: DeprecatedContractClass) -> Result { - Ok(Self(Arc::new(ContractClassV0Inner { + Ok(Self(Arc::new(CompiledClassV0Inner { program: sn_api_to_cairo_vm_program(class.program)?, entry_points_by_type: class.entry_points_by_type, }))) @@ -227,12 +228,12 @@ impl TryFrom for ContractClassV0 { // V1. -/// Represents a runnable Cario (Cairo 1) Starknet contract class (meaning, the program is runnable +/// Represents a runnable Cario (Cairo 1) Starknet compiled class (meaning, the program is runnable /// by the VM). We wrap the actual class in an Arc to avoid cloning the program when cloning the /// class. #[derive(Clone, Debug, Eq, PartialEq)] -pub struct ContractClassV1(pub Arc); -impl Deref for ContractClassV1 { +pub struct CompiledClassV1(pub Arc); +impl Deref for CompiledClassV1 { type Target = ContractClassV1Inner; fn deref(&self) -> &Self::Target { @@ -240,7 +241,7 @@ impl Deref for ContractClassV1 { } } -impl ContractClassV1 { +impl CompiledClassV1 { pub fn constructor_selector(&self) -> Option { self.0.entry_points_by_type.constructor.first().map(|ep| ep.selector) } @@ -286,9 +287,9 @@ impl ContractClassV1 { get_visited_segments(&self.bytecode_segment_lengths, &mut reversed_visited_pcs, &mut 0) } - pub fn try_from_json_string(raw_contract_class: &str) -> Result { + pub fn try_from_json_string(raw_contract_class: &str) -> Result { let casm_contract_class: CasmContractClass = serde_json::from_str(raw_contract_class)?; - let contract_class = ContractClassV1::try_from(casm_contract_class)?; + let contract_class = CompiledClassV1::try_from(casm_contract_class)?; Ok(contract_class) } @@ -413,7 +414,7 @@ impl HasSelector for EntryPointV1 { } } -impl TryFrom for ContractClassV1 { +impl TryFrom for CompiledClassV1 { type Error = ProgramError; fn try_from(class: CasmContractClass) -> Result { @@ -466,7 +467,7 @@ impl TryFrom for ContractClassV1 { Version::parse(&class.compiler_version) .unwrap_or_else(|_| panic!("Invalid version: '{}'", class.compiler_version)), ); - Ok(ContractClassV1(Arc::new(ContractClassV1Inner { + Ok(CompiledClassV1(Arc::new(ContractClassV1Inner { program, entry_points_by_type, hints: string_to_hint, diff --git a/crates/blockifier/src/execution/contract_class_test.rs b/crates/blockifier/src/execution/contract_class_test.rs index 6dcfd7411e2..bbf9bedc6c2 100644 --- a/crates/blockifier/src/execution/contract_class_test.rs +++ b/crates/blockifier/src/execution/contract_class_test.rs @@ -5,12 +5,12 @@ use assert_matches::assert_matches; use cairo_lang_starknet_classes::NestedIntList; use rstest::rstest; -use crate::execution::contract_class::{ContractClassV1, ContractClassV1Inner}; +use crate::execution::contract_class::{CompiledClassV1, ContractClassV1Inner}; use crate::transaction::errors::TransactionExecutionError; #[rstest] fn test_get_visited_segments() { - let test_contract = ContractClassV1(Arc::new(ContractClassV1Inner { + let test_contract = CompiledClassV1(Arc::new(ContractClassV1Inner { program: Default::default(), entry_points_by_type: Default::default(), hints: Default::default(), diff --git a/crates/blockifier/src/execution/deprecated_entry_point_execution.rs b/crates/blockifier/src/execution/deprecated_entry_point_execution.rs index fd4084682db..bee02bedd5f 100644 --- a/crates/blockifier/src/execution/deprecated_entry_point_execution.rs +++ b/crates/blockifier/src/execution/deprecated_entry_point_execution.rs @@ -14,7 +14,7 @@ use starknet_api::hash::StarkHash; use super::execution_utils::SEGMENT_ARENA_BUILTIN_SIZE; use crate::execution::call_info::{CallExecution, CallInfo, ChargedResources}; -use crate::execution::contract_class::{ContractClassV0, TrackedResource}; +use crate::execution::contract_class::{CompiledClassV0, TrackedResource}; use crate::execution::deprecated_syscalls::hint_processor::DeprecatedSyscallHintProcessor; use crate::execution::entry_point::{ CallEntryPoint, @@ -44,12 +44,12 @@ pub const CAIRO0_BUILTINS_NAMES: [BuiltinName; 6] = [ /// Executes a specific call to a contract entry point and returns its output. pub fn execute_entry_point_call( call: CallEntryPoint, - contract_class: ContractClassV0, + compiled_class: CompiledClassV0, state: &mut dyn State, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { let VmExecutionContext { mut runner, mut syscall_handler, initial_syscall_ptr, entry_point_pc } = - initialize_execution_context(&call, contract_class, state, context)?; + initialize_execution_context(&call, compiled_class, state, context)?; let (implicit_args, args) = prepare_call_arguments( &call, @@ -67,13 +67,13 @@ pub fn execute_entry_point_call( pub fn initialize_execution_context<'a>( call: &CallEntryPoint, - contract_class: ContractClassV0, + compiled_class: CompiledClassV0, state: &'a mut dyn State, context: &'a mut EntryPointExecutionContext, ) -> Result, PreExecutionError> { // Verify use of cairo0 builtins only. let program_builtins: HashSet<&BuiltinName> = - HashSet::from_iter(contract_class.program.iter_builtins()); + HashSet::from_iter(compiled_class.program.iter_builtins()); let unsupported_builtins = &program_builtins - &HashSet::from_iter(CAIRO0_BUILTINS_NAMES.iter()); if !unsupported_builtins.is_empty() { @@ -83,14 +83,14 @@ pub fn initialize_execution_context<'a>( } // Resolve initial PC from EP indicator. - let entry_point_pc = resolve_entry_point_pc(call, &contract_class)?; + let entry_point_pc = resolve_entry_point_pc(call, &compiled_class)?; // Instantiate Cairo runner. let proof_mode = false; let trace_enabled = false; let allow_missing_builtins = false; let program_base = None; let mut runner = - CairoRunner::new(&contract_class.program, LayoutName::starknet, proof_mode, trace_enabled)?; + CairoRunner::new(&compiled_class.program, LayoutName::starknet, proof_mode, trace_enabled)?; runner.initialize_builtins(allow_missing_builtins)?; runner.initialize_segments(program_base); @@ -110,7 +110,7 @@ pub fn initialize_execution_context<'a>( pub fn resolve_entry_point_pc( call: &CallEntryPoint, - contract_class: &ContractClassV0, + compiled_class: &CompiledClassV0, ) -> Result { if call.entry_point_type == EntryPointType::Constructor && call.entry_point_selector != selector_from_name(CONSTRUCTOR_ENTRY_POINT_NAME) @@ -118,7 +118,7 @@ pub fn resolve_entry_point_pc( return Err(PreExecutionError::InvalidConstructorEntryPointName); } - let entry_points_of_same_type = &contract_class.entry_points_by_type[&call.entry_point_type]; + let entry_points_of_same_type = &compiled_class.entry_points_by_type[&call.entry_point_type]; let filtered_entry_points: Vec<_> = entry_points_of_same_type .iter() .filter(|ep| ep.selector == call.entry_point_selector) diff --git a/crates/blockifier/src/execution/deprecated_syscalls/mod.rs b/crates/blockifier/src/execution/deprecated_syscalls/mod.rs index ff0741948fd..8a15ad92244 100644 --- a/crates/blockifier/src/execution/deprecated_syscalls/mod.rs +++ b/crates/blockifier/src/execution/deprecated_syscalls/mod.rs @@ -653,7 +653,7 @@ pub fn replace_class( syscall_handler: &mut DeprecatedSyscallHintProcessor<'_>, ) -> DeprecatedSyscallResult { // Ensure the class is declared (by reading it). - syscall_handler.state.get_compiled_contract_class(request.class_hash)?; + syscall_handler.state.get_compiled_class(request.class_hash)?; syscall_handler.state.set_class_hash_at(syscall_handler.storage_address, request.class_hash)?; Ok(ReplaceClassResponse {}) diff --git a/crates/blockifier/src/execution/entry_point.rs b/crates/blockifier/src/execution/entry_point.rs index 048023e0c1d..56f3cc05bcf 100644 --- a/crates/blockifier/src/execution/entry_point.rs +++ b/crates/blockifier/src/execution/entry_point.rs @@ -147,7 +147,7 @@ impl CallEntryPoint { } // Add class hash to the call, that will appear in the output (call info). self.class_hash = Some(class_hash); - let contract_class = state.get_compiled_contract_class(class_hash)?; + let compiled_Class = state.get_compiled_class(class_hash)?; context.revert_infos.0.push(EntryPointRevertInfo::new( self.storage_address, @@ -157,7 +157,7 @@ impl CallEntryPoint { )); // This is the last operation of this function. - execute_entry_point_call_wrapper(self, contract_class, state, context, remaining_gas) + execute_entry_point_call_wrapper(self, compiled_Class, state, context, remaining_gas) } /// Similar to `execute`, but returns an error if the outer call is reverted. @@ -406,11 +406,10 @@ pub fn execute_constructor_entry_point( remaining_gas: &mut u64, ) -> ConstructorEntryPointExecutionResult { // Ensure the class is declared (by reading it). - let contract_class = - state.get_compiled_contract_class(ctor_context.class_hash).map_err(|error| { - ConstructorEntryPointExecutionError::new(error.into(), &ctor_context, None) - })?; - let Some(constructor_selector) = contract_class.constructor_selector() else { + let compiled_class = state.get_compiled_class(ctor_context.class_hash).map_err(|error| { + ConstructorEntryPointExecutionError::new(error.into(), &ctor_context, None) + })?; + let Some(constructor_selector) = compiled_class.constructor_selector() else { // Contract has no constructor. return handle_empty_constructor(&ctor_context, calldata, *remaining_gas) .map_err(|error| ConstructorEntryPointExecutionError::new(error, &ctor_context, None)); diff --git a/crates/blockifier/src/execution/entry_point_execution.rs b/crates/blockifier/src/execution/entry_point_execution.rs index 070e55be8a5..f1bf7ef01fa 100644 --- a/crates/blockifier/src/execution/entry_point_execution.rs +++ b/crates/blockifier/src/execution/entry_point_execution.rs @@ -14,7 +14,7 @@ use starknet_api::execution_resources::GasAmount; use starknet_types_core::felt::Felt; use crate::execution::call_info::{CallExecution, CallInfo, ChargedResources, Retdata}; -use crate::execution::contract_class::{ContractClassV1, EntryPointV1, TrackedResource}; +use crate::execution::contract_class::{CompiledClassV1, EntryPointV1, TrackedResource}; use crate::execution::entry_point::{ CallEntryPoint, EntryPointExecutionContext, @@ -57,7 +57,7 @@ pub struct CallResult { /// Executes a specific call to a contract entry point and returns its output. pub fn execute_entry_point_call( call: CallEntryPoint, - contract_class: ContractClassV1, + compiled_class: CompiledClassV1, state: &mut dyn State, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { @@ -74,7 +74,7 @@ pub fn execute_entry_point_call( initial_syscall_ptr, entry_point, program_extra_data_length, - } = initialize_execution_context(call, &contract_class, state, context)?; + } = initialize_execution_context(call, &compiled_class, state, context)?; let args = prepare_call_arguments( &syscall_handler.base.call, @@ -86,7 +86,7 @@ pub fn execute_entry_point_call( let n_total_args = args.len(); // Execute. - let bytecode_length = contract_class.bytecode_length(); + let bytecode_length = compiled_class.bytecode_length(); let program_segment_size = bytecode_length + program_extra_data_length; run_entry_point(&mut runner, &mut syscall_handler, entry_point, args, program_segment_size)?; @@ -142,17 +142,17 @@ fn register_visited_pcs( pub fn initialize_execution_context<'a>( call: CallEntryPoint, - contract_class: &'a ContractClassV1, + compiled_class: &'a CompiledClassV1, state: &'a mut dyn State, context: &'a mut EntryPointExecutionContext, ) -> Result, PreExecutionError> { - let entry_point = contract_class.get_entry_point(&call)?; + let entry_point = compiled_class.get_entry_point(&call)?; // Instantiate Cairo runner. let proof_mode = false; let trace_enabled = true; let mut runner = CairoRunner::new( - &contract_class.0.program, + &compiled_class.0.program, LayoutName::starknet, proof_mode, trace_enabled, @@ -162,7 +162,7 @@ pub fn initialize_execution_context<'a>( let mut read_only_segments = ReadOnlySegments::default(); let program_extra_data_length = prepare_program_extra_data( &mut runner, - contract_class, + compiled_class, &mut read_only_segments, &context.versioned_constants().os_constants.gas_costs, )?; @@ -174,7 +174,7 @@ pub fn initialize_execution_context<'a>( context, initial_syscall_ptr, call, - &contract_class.hints, + &compiled_class.hints, read_only_segments, ); @@ -189,7 +189,7 @@ pub fn initialize_execution_context<'a>( fn prepare_program_extra_data( runner: &mut CairoRunner, - contract_class: &ContractClassV1, + contract_class: &CompiledClassV1, read_only_segments: &mut ReadOnlySegments, gas_costs: &GasCosts, ) -> Result { diff --git a/crates/blockifier/src/execution/execution_utils.rs b/crates/blockifier/src/execution/execution_utils.rs index d2c0b9aeaf3..b5526f24903 100644 --- a/crates/blockifier/src/execution/execution_utils.rs +++ b/crates/blockifier/src/execution/execution_utils.rs @@ -52,12 +52,12 @@ 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: RunnableContractClass, + compiled_class: RunnableContractClass, state: &mut dyn State, context: &mut EntryPointExecutionContext, remaining_gas: &mut u64, ) -> EntryPointExecutionResult { - let contract_tracked_resource = contract_class.tracked_resource( + let contract_tracked_resource = compiled_class.tracked_resource( &context.versioned_constants().min_compiler_version_for_sierra_gas, context.tx_context.tx_info.gas_mode(), ); @@ -81,7 +81,7 @@ pub fn execute_entry_point_call_wrapper( }; let orig_call = call.clone(); - let res = execute_entry_point_call(call, contract_class, state, context); + let res = execute_entry_point_call(call, compiled_class, state, context); let current_tracked_resource = context.tracked_resource_stack.pop().expect("Unexpected empty tracked resource."); @@ -120,37 +120,37 @@ 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: RunnableContractClass, + compiled_class: RunnableContractClass, state: &mut dyn State, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { - match contract_class { - RunnableContractClass::V0(contract_class) => { + match compiled_class { + RunnableContractClass::V0(compiled_class) => { deprecated_entry_point_execution::execute_entry_point_call( call, - contract_class, + compiled_class, state, context, ) } - RunnableContractClass::V1(contract_class) => { - entry_point_execution::execute_entry_point_call(call, contract_class, state, context) + RunnableContractClass::V1(compiled_class) => { + entry_point_execution::execute_entry_point_call(call, compiled_class, state, context) } #[cfg(feature = "cairo_native")] - RunnableContractClass::V1Native(contract_class) => { + RunnableContractClass::V1Native(compiled_class) => { if context.tracked_resource_stack.last() == Some(&TrackedResource::CairoSteps) { // We cannot run native with cairo steps as the tracked resources (it's a vm // resouorce). entry_point_execution::execute_entry_point_call( call, - contract_class.casm(), + compiled_class.casm(), state, context, ) } else { native_entry_point_execution::execute_entry_point_call( call, - contract_class, + compiled_class, state, context, ) diff --git a/crates/blockifier/src/execution/native/contract_class.rs b/crates/blockifier/src/execution/native/contract_class.rs index 2e85feb4f2f..6139e02fcaf 100644 --- a/crates/blockifier/src/execution/native/contract_class.rs +++ b/crates/blockifier/src/execution/native/contract_class.rs @@ -4,30 +4,30 @@ use std::sync::Arc; use cairo_native::executor::AotContractExecutor; use starknet_api::core::EntryPointSelector; -use crate::execution::contract_class::{ContractClassV1, EntryPointV1}; +use crate::execution::contract_class::{CompiledClassV1, EntryPointV1}; use crate::execution::entry_point::CallEntryPoint; use crate::execution::errors::PreExecutionError; #[derive(Clone, Debug, PartialEq, Eq)] -pub struct NativeContractClassV1(pub Arc); -impl Deref for NativeContractClassV1 { - type Target = NativeContractClassV1Inner; +pub struct NativeCompiledClassV1(pub Arc); +impl Deref for NativeCompiledClassV1 { + type Target = NativeCompiledClassV1Inner; fn deref(&self) -> &Self::Target { &self.0 } } -impl NativeContractClassV1 { +impl NativeCompiledClassV1 { pub(crate) fn constructor_selector(&self) -> Option { self.casm.constructor_selector() } - /// Initialize a compiled contract class for native. + /// Initialize a compiled class for native. /// /// executor must be derived from sierra_program which in turn must be derived from /// sierra_contract_class. - pub fn new(executor: AotContractExecutor, casm: ContractClassV1) -> NativeContractClassV1 { - let contract = NativeContractClassV1Inner::new(executor, casm); + pub fn new(executor: AotContractExecutor, casm: CompiledClassV1) -> NativeCompiledClassV1 { + let contract = NativeCompiledClassV1Inner::new(executor, casm); Self(Arc::new(contract)) } @@ -39,29 +39,29 @@ impl NativeContractClassV1 { self.casm.get_entry_point(call) } - pub fn casm(&self) -> ContractClassV1 { + pub fn casm(&self) -> CompiledClassV1 { self.casm.clone() } } #[derive(Debug)] -pub struct NativeContractClassV1Inner { +pub struct NativeCompiledClassV1Inner { pub executor: AotContractExecutor, - casm: ContractClassV1, + casm: CompiledClassV1, } -impl NativeContractClassV1Inner { - fn new(executor: AotContractExecutor, casm: ContractClassV1) -> Self { - NativeContractClassV1Inner { executor, casm } +impl NativeCompiledClassV1Inner { + fn new(executor: AotContractExecutor, casm: CompiledClassV1) -> Self { + NativeCompiledClassV1Inner { executor, casm } } } -// The location where the compiled contract is loaded into memory will not +// The location where the compiled class is loaded into memory will not // be the same therefore we exclude it from the comparison. -impl PartialEq for NativeContractClassV1Inner { +impl PartialEq for NativeCompiledClassV1Inner { fn eq(&self, other: &Self) -> bool { self.casm == other.casm } } -impl Eq for NativeContractClassV1Inner {} +impl Eq for NativeCompiledClassV1Inner {} diff --git a/crates/blockifier/src/execution/native/entry_point_execution.rs b/crates/blockifier/src/execution/native/entry_point_execution.rs index 34b3460c678..719bbc775eb 100644 --- a/crates/blockifier/src/execution/native/entry_point_execution.rs +++ b/crates/blockifier/src/execution/native/entry_point_execution.rs @@ -11,18 +11,18 @@ use crate::execution::entry_point::{ EntryPointExecutionResult, }; use crate::execution::errors::{EntryPointExecutionError, PostExecutionError}; -use crate::execution::native::contract_class::NativeContractClassV1; +use crate::execution::native::contract_class::NativeCompiledClassV1; use crate::execution::native::syscall_handler::NativeSyscallHandler; use crate::state::state_api::State; // todo(rodrigo): add an `entry point not found` test for Native pub fn execute_entry_point_call( call: CallEntryPoint, - contract_class: NativeContractClassV1, + compiled_class: NativeCompiledClassV1, state: &mut dyn State, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { - let entry_point = contract_class.get_entry_point(&call)?; + let entry_point = compiled_class.get_entry_point(&call)?; let mut syscall_handler: NativeSyscallHandler<'_> = NativeSyscallHandler::new(call, state, context); @@ -39,7 +39,7 @@ pub fn execute_entry_point_call( mul_mod: gas_costs.mul_mod_gas_cost, }; - let execution_result = contract_class.executor.run( + let execution_result = compiled_class.executor.run( entry_point.selector.0, &syscall_handler.base.call.calldata.0.clone(), syscall_handler.base.call.initial_gas, diff --git a/crates/blockifier/src/execution/syscalls/syscall_base.rs b/crates/blockifier/src/execution/syscalls/syscall_base.rs index ade9cb398cf..7a4b02fc38c 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_base.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_base.rs @@ -156,9 +156,9 @@ impl<'state> SyscallHandlerBase<'state> { pub fn replace_class(&mut self, class_hash: ClassHash) -> SyscallResult<()> { // Ensure the class is declared (by reading it), and of type V1. - let class = self.state.get_compiled_contract_class(class_hash)?; + let compiled_class = self.state.get_compiled_class(class_hash)?; - if !is_cairo1(&class) { + if !is_cairo1(&compiled_class) { return Err(SyscallExecutionError::ForbiddenClassReplacement { class_hash }); } self.state.set_class_hash_at(self.call.storage_address, class_hash)?; diff --git a/crates/blockifier/src/state/cached_state.rs b/crates/blockifier/src/state/cached_state.rs index dbb84243e7e..059387c51b7 100644 --- a/crates/blockifier/src/state/cached_state.rs +++ b/crates/blockifier/src/state/cached_state.rs @@ -8,7 +8,7 @@ use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; use crate::context::TransactionContext; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; 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. /// @@ -85,8 +85,7 @@ impl CachedState { /// * Nonce: read previous before incrementing. /// * Class hash: Deploy: verify the address is not occupied; Replace class: verify the /// contract is deployed before running any code. - /// * Compiled class hash: verify the class is not declared through - /// `get_compiled_contract_class`. + /// * Compiled class hash: verify the class is not declared through `get_compiled_class`. /// /// TODO(Noa, 30/07/23): Consider adding DB getters in bulk (via a DB read transaction). fn update_initial_values_of_write_only_access(&mut self) -> StateResult<()> { @@ -174,17 +173,14 @@ impl StateReader for CachedState { Ok(*class_hash) } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_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(); if let std::collections::hash_map::Entry::Vacant(vacant_entry) = class_hash_to_class.entry(class_hash) { - match self.state.get_compiled_contract_class(class_hash) { + match self.state.get_compiled_class(class_hash) { Err(StateError::UndeclaredClassHash(class_hash)) => { cache.set_declared_contract_initial_value(class_hash, false); cache.set_compiled_class_hash_initial_value( @@ -260,7 +256,7 @@ impl State for CachedState { fn set_contract_class( &mut self, class_hash: ClassHash, - contract_class: RunnableContractClass, + contract_class: RunnableCompiledClass, ) -> StateResult<()> { self.class_hash_to_class.get_mut().insert(class_hash, contract_class); let mut cache = self.cache.borrow_mut(); @@ -528,11 +524,8 @@ 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 { - self.0.get_compiled_contract_class(class_hash) + fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { + self.0.get_compiled_class(class_hash) } fn get_compiled_class_hash(&self, class_hash: ClassHash) -> StateResult { diff --git a/crates/blockifier/src/state/cached_state_test.rs b/crates/blockifier/src/state/cached_state_test.rs index bcc91ab2f57..20f191a99cc 100644 --- a/crates/blockifier/src/state/cached_state_test.rs +++ b/crates/blockifier/src/state/cached_state_test.rs @@ -115,7 +115,7 @@ fn declare_contract() { // Reading an undeclared contract class. assert_matches!( - state.get_compiled_contract_class(class_hash).unwrap_err(), + state.get_compiled_class(class_hash).unwrap_err(), StateError::UndeclaredClassHash(undeclared_class_hash) if undeclared_class_hash == class_hash ); @@ -166,14 +166,14 @@ fn get_contract_class() { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0); 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(), + state.get_compiled_class(test_contract.get_class_hash()).unwrap(), test_contract.get_runnable_class() ); // Negative flow. let missing_class_hash = class_hash!("0x101"); assert_matches!( - state.get_compiled_contract_class(missing_class_hash).unwrap_err(), + state.get_compiled_class(missing_class_hash).unwrap_err(), StateError::UndeclaredClassHash(undeclared) if undeclared == missing_class_hash ); } @@ -261,7 +261,7 @@ fn cached_state_state_diff_conversion() { let class_hash = FeatureContract::Empty(CairoVersion::Cairo0).get_class_hash(); let compiled_class_hash = compiled_class_hash!(1_u8); // Cache the initial read value, as in regular declare flow. - state.get_compiled_contract_class(class_hash).unwrap_err(); + state.get_compiled_class(class_hash).unwrap_err(); state.set_compiled_class_hash(class_hash, compiled_class_hash).unwrap(); // Write the initial value using key contract_address1. @@ -309,7 +309,7 @@ fn create_state_changes_for_test( state.increment_nonce(contract_address2).unwrap(); // Fill the initial read value, as in regular flow. - state.get_compiled_contract_class(class_hash).unwrap_err(); + state.get_compiled_class(class_hash).unwrap_err(); state.set_compiled_class_hash(class_hash, compiled_class_hash).unwrap(); // Assign the existing value to the storage (this shouldn't be considered a change). @@ -500,7 +500,7 @@ fn test_contract_cache_is_used() { assert!(state.class_hash_to_class.borrow().get(&class_hash).is_none()); // Check state uses the cache. - assert_eq!(state.get_compiled_contract_class(class_hash).unwrap(), contract_class); + assert_eq!(state.get_compiled_class(class_hash).unwrap(), contract_class); assert_eq!(state.class_hash_to_class.borrow().get(&class_hash).unwrap(), &contract_class); } diff --git a/crates/blockifier/src/state/global_cache.rs b/crates/blockifier/src/state/global_cache.rs index 040b1163375..f26d4ab39d4 100644 --- a/crates/blockifier/src/state/global_cache.rs +++ b/crates/blockifier/src/state/global_cache.rs @@ -8,7 +8,7 @@ use starknet_api::core::ClassHash; use starknet_api::state::SierraContractClass; #[cfg(feature = "cairo_native")] -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; type ContractClassLRUCache = SizedCache; pub type LockedContractClassCache<'a, T> = MutexGuard<'a, ContractClassLRUCache>; @@ -53,18 +53,18 @@ impl GlobalContractCache { #[cfg(feature = "cairo_native")] pub struct GlobalContractCacheManager { - pub casm_cache: GlobalContractCache, + pub casm_cache: GlobalContractCache, pub native_cache: GlobalContractCache, pub sierra_cache: GlobalContractCache>, } #[cfg(feature = "cairo_native")] impl GlobalContractCacheManager { - pub fn get_casm(&self, class_hash: &ClassHash) -> Option { + pub fn get_casm(&self, class_hash: &ClassHash) -> Option { self.casm_cache.get(class_hash) } - pub fn set_casm(&self, class_hash: ClassHash, contract_class: RunnableContractClass) { + pub fn set_casm(&self, class_hash: ClassHash, contract_class: RunnableCompiledClass) { self.casm_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 2b4464d6ab1..96e24c1e1a3 100644 --- a/crates/blockifier/src/state/state_api.rs +++ b/crates/blockifier/src/state/state_api.rs @@ -6,7 +6,7 @@ use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; use super::cached_state::{ContractClassMapping, StateMaps}; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::state::errors::StateError; pub type StateResult = Result; @@ -39,11 +39,8 @@ pub trait StateReader { /// Default: 0 (uninitialized class hash) for an uninitialized contract address. 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; + /// Returns the compiled class of the given class hash. + fn get_compiled_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; @@ -96,7 +93,7 @@ pub trait State: StateReader { fn set_contract_class( &mut self, class_hash: ClassHash, - contract_class: RunnableContractClass, + contract_class: RunnableCompiledClass, ) -> 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 7a4bb8fa93d..c3d4ea4ce26 100644 --- a/crates/blockifier/src/test_utils/contracts.rs +++ b/crates/blockifier/src/test_utils/contracts.rs @@ -12,10 +12,10 @@ use starknet_types_core::felt::Felt; use strum::IntoEnumIterator; use strum_macros::EnumIter; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::execution::entry_point::CallEntryPoint; #[cfg(feature = "cairo_native")] -use crate::execution::native::contract_class::NativeContractClassV1; +use crate::execution::native::contract_class::NativeCompiledClassV1; #[cfg(feature = "cairo_native")] use crate::test_utils::cairo_compile::starknet_compile; use crate::test_utils::cairo_compile::{cairo0_compile, cairo1_compile}; @@ -185,12 +185,12 @@ impl FeatureContract { } } - pub fn get_runnable_class(&self) -> RunnableContractClass { + pub fn get_runnable_class(&self) -> RunnableCompiledClass { #[cfg(feature = "cairo_native")] if CairoVersion::Native == self.cairo_version() { let native_contract_class = - NativeContractClassV1::compile_or_get_cached(&self.get_compiled_path()); - return RunnableContractClass::V1Native(native_contract_class); + NativeCompiledClassV1::compile_or_get_cached(&self.get_compiled_path()); + return RunnableCompiledClass::V1Native(native_contract_class); } self.get_class().try_into().unwrap() @@ -365,7 +365,7 @@ impl FeatureContract { entry_point_type: EntryPointType, ) -> EntryPointOffset { match self.get_runnable_class() { - RunnableContractClass::V0(class) => { + RunnableCompiledClass::V0(class) => { class .entry_points_by_type .get(&entry_point_type) @@ -375,7 +375,7 @@ impl FeatureContract { .unwrap() .offset } - RunnableContractClass::V1(class) => { + RunnableCompiledClass::V1(class) => { class .entry_points_by_type .get_entry_point(&CallEntryPoint { @@ -387,7 +387,7 @@ impl FeatureContract { .offset } #[cfg(feature = "cairo_native")] - RunnableContractClass::V1Native(_) => { + RunnableCompiledClass::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 469e6cbdb7d..16e3b3ed83f 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::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; 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,10 +35,7 @@ impl StateReader for DictStateReader { Ok(nonce) } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_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/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 581263a05ca..dee7020eac3 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -27,14 +27,14 @@ use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionCont use crate::execution::call_info::{CallExecution, CallInfo, Retdata}; use crate::execution::common_hints::ExecutionMode; #[cfg(feature = "cairo_native")] -use crate::execution::contract_class::ContractClassV1; +use crate::execution::contract_class::CompiledClassV1; use crate::execution::entry_point::{ CallEntryPoint, EntryPointExecutionContext, EntryPointExecutionResult, }; #[cfg(feature = "cairo_native")] -use crate::execution::native::contract_class::NativeContractClassV1; +use crate::execution::native::contract_class::NativeCompiledClassV1; use crate::state::state_api::State; use crate::test_utils::{ get_raw_contract_class, @@ -242,12 +242,12 @@ impl BouncerWeights { } #[cfg(feature = "cairo_native")] -static COMPILED_NATIVE_CONTRACT_CACHE: LazyLock>> = +static COMPILED_NATIVE_CONTRACT_CACHE: LazyLock>> = LazyLock::new(|| RwLock::new(HashMap::new())); #[cfg(feature = "cairo_native")] -impl NativeContractClassV1 { - /// Convenience function to construct a NativeContractClassV1 from a raw contract class. +impl NativeCompiledClassV1 { + /// Convenience function to construct a NativeCompiledClassV1 from a raw contract class. /// If control over the compilation is desired use [Self::new] instead. pub fn try_from_json_string(raw_sierra_contract_class: &str) -> Self { let sierra_contract_class: SierraContractClass = @@ -268,10 +268,10 @@ impl NativeContractClassV1 { let casm_contract_class = CasmContractClass::from_contract_class(sierra_contract_class, false, usize::MAX) .expect("Cannot compile sierra contract class into casm contract class"); - let casm = ContractClassV1::try_from(casm_contract_class) - .expect("Cannot get ContractClassV1 from CasmContractClass"); + let casm = CompiledClassV1::try_from(casm_contract_class) + .expect("Cannot get CompiledClassV1 from CasmContractClass"); - NativeContractClassV1::new(executor, casm) + NativeCompiledClassV1::new(executor, casm) } pub fn from_file(contract_path: &str) -> Self { @@ -287,7 +287,7 @@ impl NativeContractClassV1 { } std::mem::drop(cache); - let class = NativeContractClassV1::from_file(path); + let class = NativeCompiledClassV1::from_file(path); let mut cache = COMPILED_NATIVE_CONTRACT_CACHE.write().unwrap(); cache.insert(path.to_string(), class.clone()); class diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index a4b245dd0d3..4c2c4a8731e 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -28,7 +28,7 @@ use starknet_types_core::felt::Felt; use crate::context::{BlockContext, TransactionContext}; use crate::execution::call_info::CallInfo; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::execution::entry_point::{CallEntryPoint, CallType, EntryPointExecutionContext}; use crate::execution::stack_trace::{ extract_trailing_cairo1_revert_trace, @@ -885,8 +885,8 @@ impl ValidatableTransaction for AccountTransaction { })?; // Validate return data. - let contract_class = state.get_compiled_contract_class(class_hash)?; - if is_cairo1(&contract_class) { + let compiled_class = state.get_compiled_class(class_hash)?; + if is_cairo1(&compiled_class) { // The account contract class is a Cairo 1.0 contract; the `validate` entry point should // return `VALID`. let expected_retdata = retdata![*constants::VALIDATE_RETDATA]; @@ -910,11 +910,11 @@ impl ValidatableTransaction for AccountTransaction { } } -pub fn is_cairo1(contract_class: &RunnableContractClass) -> bool { - match contract_class { - RunnableContractClass::V0(_) => false, - RunnableContractClass::V1(_) => true, +pub fn is_cairo1(compiled_class: &RunnableCompiledClass) -> bool { + match compiled_class { + RunnableCompiledClass::V0(_) => false, + RunnableCompiledClass::V1(_) => true, #[cfg(feature = "cairo_native")] - RunnableContractClass::V1Native(_) => true, + RunnableCompiledClass::V1Native(_) => true, } } diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index d570ebe6c49..9005f73e4dd 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -401,7 +401,7 @@ fn try_declare( class_hash: ClassHash, compiled_class_hash: Option, ) -> TransactionExecutionResult<()> { - match state.get_compiled_contract_class(class_hash) { + match state.get_compiled_class(class_hash) { Err(StateError::UndeclaredClassHash(_)) => { // Class is undeclared; declare it. state.set_contract_class(class_hash, tx.contract_class().try_into()?)?; diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 2a6d85ad98d..648725249fb 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1524,7 +1524,7 @@ fn test_declare_tx( // Check state before transaction application. assert_matches!( - state.get_compiled_contract_class(class_hash).unwrap_err(), + state.get_compiled_class(class_hash).unwrap_err(), StateError::UndeclaredClassHash(undeclared_class_hash) if undeclared_class_hash == class_hash ); @@ -1626,7 +1626,7 @@ fn test_declare_tx( ); // Verify class declaration. - let contract_class_from_state = state.get_compiled_contract_class(class_hash).unwrap(); + let contract_class_from_state = state.get_compiled_class(class_hash).unwrap(); assert_eq!(contract_class_from_state, class_info.contract_class().try_into().unwrap()); // Checks that redeclaring the same contract fails. 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 5362a6ef638..7ebb38ac312 100644 --- a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs @@ -9,7 +9,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::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::cached_state::{CommitmentStateDiff, StateMaps}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader, StateResult}; @@ -217,10 +217,7 @@ impl StateReader for TestStateReader { /// Returns the contract class of the given class hash. /// Compile the contract class if it is Sierra. - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { let contract_class = retry_request!(self.retry_config, || self.get_contract_class(&class_hash))?; @@ -591,10 +588,7 @@ impl StateReader for OfflineStateReader { )?) } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { match self.get_contract_class(&class_hash)? { StarknetContractClass::Sierra(sierra) => { Ok(sierra_to_contact_class_v1(sierra).unwrap().try_into().unwrap()) diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index 17f8604bb16..0cefe8026d0 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -6,7 +6,7 @@ use blockifier::blockifier::transaction_executor::{TransactionExecutor, Transact use blockifier::bouncer::BouncerConfig; use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses}; use blockifier::execution::call_info::CallInfo; -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::fee::receipt::TransactionReceipt; use blockifier::state::global_cache::GlobalContractCache; use blockifier::transaction::objects::{ExecutionResourcesTraits, TransactionExecutionInfo}; @@ -130,7 +130,7 @@ pub struct PyBlockExecutor { pub tx_executor: Option>, /// `Send` trait is required for `pyclass` compatibility as Python objects must be threadsafe. pub storage: Box, - pub global_contract_cache: GlobalContractCache, + pub global_contract_cache: GlobalContractCache, } #[pymethods] diff --git a/crates/native_blockifier/src/py_block_executor_test.rs b/crates/native_blockifier/src/py_block_executor_test.rs index 47a39d3409c..2a87bec4fcf 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::{ContractClassV1, RunnableContractClass}; +use blockifier::execution::contract_class::{CompiledClassV1, RunnableCompiledClass}; use blockifier::state::state_api::StateReader; use cached::Cached; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; @@ -33,7 +33,7 @@ fn global_contract_cache_update() { }; let sierra = SierraContractClass::default(); let contract_class = - RunnableContractClass::V1(ContractClassV1::try_from(casm.clone()).unwrap()); + RunnableCompiledClass::V1(CompiledClassV1::try_from(casm.clone()).unwrap()); let class_hash = class_hash!("0x1"); let temp_storage_path = tempfile::tempdir().unwrap().into_path(); @@ -75,7 +75,7 @@ fn global_contract_cache_update() { .block_state .as_ref() .expect(BLOCK_STATE_ACCESS_ERR) - .get_compiled_contract_class(class_hash) + .get_compiled_class(class_hash) .unwrap(); assert_eq!(queried_contract_class, contract_class); diff --git a/crates/native_blockifier/src/py_test_utils.rs b/crates/native_blockifier/src/py_test_utils.rs index 6cae66fa3fa..2ba5ac4d485 100644 --- a/crates/native_blockifier/src/py_test_utils.rs +++ b/crates/native_blockifier/src/py_test_utils.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use blockifier::execution::contract_class::ContractClassV0; +use blockifier::execution::contract_class::CompiledClassV0; use blockifier::state::cached_state::CachedState; use blockifier::test_utils::dict_state_reader::DictStateReader; use blockifier::test_utils::struct_impls::LoadContractFromFile; @@ -14,7 +14,7 @@ pub const TOKEN_FOR_TESTING_CONTRACT_PATH: &str = starknet/core/test_contract/token_for_testing.json"; pub fn create_py_test_state() -> CachedState { - let contract_class: ContractClassV0 = + let contract_class: CompiledClassV0 = ContractClass::from_file(TOKEN_FOR_TESTING_CONTRACT_PATH).try_into().unwrap(); let class_hash_to_class = HashMap::from([(class_hash!(TOKEN_FOR_TESTING_CLASS_HASH), contract_class.into())]); 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 f379dcb05bf..35cdde1d914 100644 --- a/crates/native_blockifier/src/state_readers/py_state_reader.rs +++ b/crates/native_blockifier/src/state_readers/py_state_reader.rs @@ -1,7 +1,7 @@ use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader, StateResult}; @@ -68,11 +68,8 @@ 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_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 @@ -80,7 +77,7 @@ impl StateReader for PyStateReader { .call_method1("get_raw_compiled_class", args)? .extract()?; - Ok(RunnableContractClass::try_from(py_raw_compiled_class)?) + Ok(RunnableCompiledClass::try_from(py_raw_compiled_class)?) }) .map_err(|err| { if Python::with_gil(|py| err.is_instance_of::(py)) { @@ -110,14 +107,14 @@ pub struct PyRawCompiledClass { pub version: usize, } -impl TryFrom for RunnableContractClass { +impl TryFrom for RunnableCompiledClass { type Error = NativeBlockifierError; fn try_from(raw_compiled_class: PyRawCompiledClass) -> NativeBlockifierResult { match raw_compiled_class.version { - 0 => Ok(ContractClassV0::try_from_json_string(&raw_compiled_class.raw_compiled_class)? + 0 => Ok(CompiledClassV0::try_from_json_string(&raw_compiled_class.raw_compiled_class)? .into()), - 1 => Ok(ContractClassV1::try_from_json_string(&raw_compiled_class.raw_compiled_class)? + 1 => Ok(CompiledClassV1::try_from_json_string(&raw_compiled_class.raw_compiled_class)? .into()), _ => Err(NativeBlockifierInputError::UnsupportedContractClassVersion { version: raw_compiled_class.version, diff --git a/crates/papyrus_execution/src/execution_utils.rs b/crates/papyrus_execution/src/execution_utils.rs index 45e45d16b8d..9a6f34ffb79 100644 --- a/crates/papyrus_execution/src/execution_utils.rs +++ b/crates/papyrus_execution/src/execution_utils.rs @@ -3,9 +3,9 @@ use std::fs::File; use std::path::PathBuf; use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::cached_state::{CachedState, CommitmentStateDiff, MutRefState}; use blockifier::state::state_api::StateReader; @@ -59,15 +59,15 @@ pub(crate) fn get_contract_class( txn: &StorageTxn<'_, RO>, class_hash: &ClassHash, state_number: StateNumber, -) -> Result, ExecutionUtilsError> { +) -> Result, ExecutionUtilsError> { match txn.get_state_reader()?.get_class_definition_block_number(class_hash)? { Some(block_number) if state_number.is_before(block_number) => return Ok(None), Some(_block_number) => { let Some(casm) = txn.get_casm(class_hash)? else { return Err(ExecutionUtilsError::CasmTableNotSynced); }; - return Ok(Some(RunnableContractClass::V1( - ContractClassV1::try_from(casm).map_err(ExecutionUtilsError::ProgramError)?, + return Ok(Some(RunnableCompiledClass::V1( + CompiledClassV1::try_from(casm).map_err(ExecutionUtilsError::ProgramError)?, ))); } None => {} @@ -78,8 +78,8 @@ pub(crate) fn get_contract_class( else { return Ok(None); }; - Ok(Some(RunnableContractClass::V0( - ContractClassV0::try_from(deprecated_class).map_err(ExecutionUtilsError::ProgramError)?, + Ok(Some(RunnableCompiledClass::V0( + CompiledClassV0::try_from(deprecated_class).map_err(ExecutionUtilsError::ProgramError)?, ))) } diff --git a/crates/papyrus_execution/src/state_reader.rs b/crates/papyrus_execution/src/state_reader.rs index a963241f613..b67aaa170e3 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::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; @@ -75,17 +75,14 @@ impl BlockifierStateReader for ExecutionStateReader { .unwrap_or_default()) } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { if let Some(pending_casm) = self .maybe_pending_data .as_ref() .and_then(|pending_data| pending_data.classes.get_compiled_class(class_hash)) { - return Ok(RunnableContractClass::V1( - ContractClassV1::try_from(pending_casm).map_err(StateError::ProgramError)?, + return Ok(RunnableCompiledClass::V1( + CompiledClassV1::try_from(pending_casm).map_err(StateError::ProgramError)?, )); } if let Some(ApiContractClass::DeprecatedContractClass(pending_deprecated_class)) = self @@ -93,8 +90,8 @@ impl BlockifierStateReader for ExecutionStateReader { .as_ref() .and_then(|pending_data| pending_data.classes.get_class(class_hash)) { - return Ok(RunnableContractClass::V0( - ContractClassV0::try_from(pending_deprecated_class) + return Ok(RunnableCompiledClass::V0( + CompiledClassV0::try_from(pending_deprecated_class) .map_err(StateError::ProgramError)?, )); } diff --git a/crates/papyrus_execution/src/state_reader_test.rs b/crates/papyrus_execution/src/state_reader_test.rs index ac16c98afa6..8e6a3c9558d 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::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::StateReader; @@ -50,7 +50,7 @@ fn read_state() { let class0 = SierraContractClass::default(); let casm0 = get_test_casm(); let blockifier_casm0 = - RunnableContractClass::V1(ContractClassV1::try_from(casm0.clone()).unwrap()); + RunnableCompiledClass::V1(CompiledClassV1::try_from(casm0.clone()).unwrap()); let compiled_class_hash0 = CompiledClassHash(StarkHash::default()); let class_hash1 = ClassHash(1u128.into()); @@ -65,7 +65,7 @@ fn read_state() { let mut casm1 = get_test_casm(); casm1.bytecode[0] = BigUintAsHex { value: 12345u32.into() }; let blockifier_casm1 = - RunnableContractClass::V1(ContractClassV1::try_from(casm1.clone()).unwrap()); + RunnableCompiledClass::V1(CompiledClassV1::try_from(casm1.clone()).unwrap()); let nonce1 = Nonce(felt!(2_u128)); let class_hash3 = ClassHash(567_u128.into()); let class_hash4 = ClassHash(89_u128.into()); @@ -163,8 +163,7 @@ fn read_state() { assert_eq!(nonce_after_block_0, Nonce::default()); let class_hash_after_block_0 = state_reader0.get_class_hash_at(address0).unwrap(); assert_eq!(class_hash_after_block_0, ClassHash::default()); - let compiled_contract_class_after_block_0 = - state_reader0.get_compiled_contract_class(class_hash0); + let compiled_contract_class_after_block_0 = state_reader0.get_compiled_class(class_hash0); assert_matches!( compiled_contract_class_after_block_0, Err(StateError::UndeclaredClassHash(class_hash)) if class_hash == class_hash0 @@ -185,12 +184,12 @@ fn read_state() { let class_hash_after_block_1 = state_reader1.get_class_hash_at(address0).unwrap(); assert_eq!(class_hash_after_block_1, class_hash0); let compiled_contract_class_after_block_1 = - state_reader1.get_compiled_contract_class(class_hash0).unwrap(); + state_reader1.get_compiled_class(class_hash0).unwrap(); assert_eq!(compiled_contract_class_after_block_1, blockifier_casm0); - // Test that if we try to get a casm and it's missing, that an error is returned and the field - // `missing_compiled_class` is set to its hash - state_reader1.get_compiled_contract_class(class_hash5).unwrap_err(); + // Test that an error is returned if we try to get a missing casm, and the field + // `missing_compiled_class` is set to the missing casm's hash. + state_reader1.get_compiled_class(class_hash5).unwrap_err(); assert_eq!(state_reader1.missing_compiled_class.get().unwrap(), class_hash5); let state_number2 = StateNumber::unchecked_right_after_block(BlockNumber(2)); @@ -234,14 +233,14 @@ fn read_state() { assert_eq!(state_reader2.get_compiled_class_hash(class_hash2).unwrap(), compiled_class_hash2); assert_eq!(state_reader2.get_nonce_at(address0).unwrap(), nonce0); assert_eq!(state_reader2.get_nonce_at(address2).unwrap(), nonce1); - assert_eq!(state_reader2.get_compiled_contract_class(class_hash0).unwrap(), blockifier_casm0); - assert_eq!(state_reader2.get_compiled_contract_class(class_hash2).unwrap(), blockifier_casm1); - // Test that if we only got the class without the casm then an error is returned. - state_reader2.get_compiled_contract_class(class_hash3).unwrap_err(); + assert_eq!(state_reader2.get_compiled_class(class_hash0).unwrap(), blockifier_casm0); + assert_eq!(state_reader2.get_compiled_class(class_hash2).unwrap(), blockifier_casm1); + // Test that an error is returned if we only got the class without the casm. + state_reader2.get_compiled_class(class_hash3).unwrap_err(); // Test that if the class is deprecated it is returned. assert_eq!( - state_reader2.get_compiled_contract_class(class_hash4).unwrap(), - RunnableContractClass::V0(ContractClassV0::try_from(class1).unwrap()) + state_reader2.get_compiled_class(class_hash4).unwrap(), + RunnableCompiledClass::V0(CompiledClassV0::try_from(class1).unwrap()) ); // Test get_class_hash_at when the class is replaced. diff --git a/crates/papyrus_rpc/src/v0_8/api/api_impl.rs b/crates/papyrus_rpc/src/v0_8/api/api_impl.rs index b05437de3d3..ad9094da1ae 100644 --- a/crates/papyrus_rpc/src/v0_8/api/api_impl.rs +++ b/crates/papyrus_rpc/src/v0_8/api/api_impl.rs @@ -1445,7 +1445,7 @@ impl JsonRpcServer for JsonRpcServerImpl { } #[instrument(skip(self), level = "debug", err)] - fn get_compiled_contract_class( + fn get_compiled_class( &self, block_id: BlockId, class_hash: ClassHash, diff --git a/crates/papyrus_rpc/src/v0_8/api/mod.rs b/crates/papyrus_rpc/src/v0_8/api/mod.rs index 0c272fc3792..1437933c934 100644 --- a/crates/papyrus_rpc/src/v0_8/api/mod.rs +++ b/crates/papyrus_rpc/src/v0_8/api/mod.rs @@ -257,9 +257,9 @@ pub trait JsonRpc { block_id: BlockId, ) -> RpcResult>; - /// Returns the compiled contract class associated with the given class hash. + /// Returns the compiled class associated with the given class hash. #[method(name = "getCompiledContractClass")] - fn get_compiled_contract_class( + fn get_compiled_class( &self, block_id: BlockId, class_hash: ClassHash, diff --git a/crates/papyrus_rpc/src/v0_8/api/test.rs b/crates/papyrus_rpc/src/v0_8/api/test.rs index 54819a917f4..5bfb5c6c8ed 100644 --- a/crates/papyrus_rpc/src/v0_8/api/test.rs +++ b/crates/papyrus_rpc/src/v0_8/api/test.rs @@ -3680,7 +3680,7 @@ async fn get_deprecated_class_state_mutability() { // TODO (Yael 16/06/2024): Add a test case for block_number which is not the latest. #[tokio::test] -async fn get_compiled_contract_class() { +async fn get_compiled_class() { let cairo1_class_hash = ClassHash(Felt::ONE); let cairo0_class_hash = ClassHash(Felt::TWO); let invalid_class_hash = ClassHash(Felt::THREE); diff --git a/crates/papyrus_state_reader/src/papyrus_state.rs b/crates/papyrus_state_reader/src/papyrus_state.rs index 3ff2cdc46e3..2af2651d10a 100644 --- a/crates/papyrus_state_reader/src/papyrus_state.rs +++ b/crates/papyrus_state_reader/src/papyrus_state.rs @@ -1,7 +1,7 @@ use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::global_cache::GlobalContractCache; @@ -23,14 +23,14 @@ type RawPapyrusReader<'env> = papyrus_storage::StorageTxn<'env, RO>; pub struct PapyrusReader { storage_reader: StorageReader, latest_block: BlockNumber, - global_class_hash_to_class: GlobalContractCache, + global_class_hash_to_class: GlobalContractCache, } impl PapyrusReader { pub fn new( storage_reader: StorageReader, latest_block: BlockNumber, - global_class_hash_to_class: GlobalContractCache, + global_class_hash_to_class: GlobalContractCache, ) -> Self { Self { storage_reader, latest_block, global_class_hash_to_class } } @@ -43,10 +43,10 @@ impl PapyrusReader { /// Returns a V1 contract if found, or a V0 contract if a V1 contract is not /// found, or an `Error` otherwise. - fn get_compiled_contract_class_inner( + fn get_compiled_class_inner( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let state_number = StateNumber(self.latest_block); let class_declaration_block_number = self .reader()? @@ -57,7 +57,7 @@ impl PapyrusReader { Some(block_number) if block_number <= state_number.0); if class_is_declared { - let casm_contract_class = self + let casm_compiled_class = self .reader()? .get_casm(&class_hash) .map_err(|err| StateError::StateReadError(err.to_string()))? @@ -66,18 +66,18 @@ impl PapyrusReader { inconsistent.", ); - return Ok(RunnableContractClass::V1(ContractClassV1::try_from(casm_contract_class)?)); + return Ok(RunnableCompiledClass::V1(CompiledClassV1::try_from(casm_compiled_class)?)); } - let v0_contract_class = self + let v0_compiled_class = self .reader()? .get_state_reader() .and_then(|sr| sr.get_deprecated_class_definition_at(state_number, &class_hash)) .map_err(|err| StateError::StateReadError(err.to_string()))?; - match v0_contract_class { + match v0_compiled_class { Some(starknet_api_contract_class) => { - Ok(ContractClassV0::try_from(starknet_api_contract_class)?.into()) + Ok(CompiledClassV0::try_from(starknet_api_contract_class)?.into()) } None => Err(StateError::UndeclaredClassHash(class_hash)), } @@ -124,17 +124,14 @@ impl StateReader for PapyrusReader { } } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_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); match contract_class { Some(contract_class) => Ok(contract_class), None => { - let contract_class_from_db = self.get_compiled_contract_class_inner(class_hash)?; + let contract_class_from_db = self.get_compiled_class_inner(class_hash)?; // The class was declared in a previous (finalized) state; update the global cache. self.global_class_hash_to_class.set(class_hash, contract_class_from_db.clone()); Ok(contract_class_from_db) diff --git a/crates/starknet_api/src/contract_class.rs b/crates/starknet_api/src/contract_class.rs index f103a13eaed..3a85573a06a 100644 --- a/crates/starknet_api/src/contract_class.rs +++ b/crates/starknet_api/src/contract_class.rs @@ -42,7 +42,7 @@ impl ContractClass { } } } -/// All relevant information about a declared contract class, including the compiled contract class +/// All relevant information about a declared contract class, including the compiled class /// and other parameters derived from the original declare transaction required for billing. #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] // TODO(Ayelet,10/02/2024): Change to bytes. diff --git a/crates/starknet_api/src/executable_transaction.rs b/crates/starknet_api/src/executable_transaction.rs index fe3e20f9f49..a3e0f96f33c 100644 --- a/crates/starknet_api/src/executable_transaction.rs +++ b/crates/starknet_api/src/executable_transaction.rs @@ -168,7 +168,7 @@ impl DeclareTransaction { Ok(Self { tx: declare_tx, tx_hash, class_info }) } - /// Validates that the compiled class hash of the compiled contract class matches the supplied + /// Validates that the compiled class hash of the compiled class matches the supplied /// compiled class hash. /// Relevant only for version 3 transactions. pub fn validate_compiled_class_hash(&self) -> bool { diff --git a/crates/starknet_batcher/src/block_builder.rs b/crates/starknet_batcher/src/block_builder.rs index 4eab564c0fc..ecb944c3471 100644 --- a/crates/starknet_batcher/src/block_builder.rs +++ b/crates/starknet_batcher/src/block_builder.rs @@ -11,7 +11,7 @@ use blockifier::blockifier::transaction_executor::{ }; use blockifier::bouncer::{BouncerConfig, BouncerWeights}; use blockifier::context::{BlockContext, ChainInfo}; -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::cached_state::CommitmentStateDiff; use blockifier::state::errors::StateError; use blockifier::state::global_cache::GlobalContractCache; @@ -296,7 +296,7 @@ impl SerializeConfig for BlockBuilderConfig { pub struct BlockBuilderFactory { pub block_builder_config: BlockBuilderConfig, pub storage_reader: StorageReader, - pub global_class_hash_to_class: GlobalContractCache, + pub global_class_hash_to_class: GlobalContractCache, } impl BlockBuilderFactory { diff --git a/crates/starknet_gateway/src/rpc_objects.rs b/crates/starknet_gateway/src/rpc_objects.rs index 9d015fb8627..f9b7d17cc25 100644 --- a/crates/starknet_gateway/src/rpc_objects.rs +++ b/crates/starknet_gateway/src/rpc_objects.rs @@ -48,7 +48,7 @@ pub struct GetClassHashAtParams { } #[derive(Serialize, Deserialize)] -pub struct GetCompiledContractClassParams { +pub struct GetCompiledClassParams { pub class_hash: ClassHash, pub block_id: BlockId, } diff --git a/crates/starknet_gateway/src/rpc_state_reader.rs b/crates/starknet_gateway/src/rpc_state_reader.rs index 57eb41212ca..fa4e5fc684e 100644 --- a/crates/starknet_gateway/src/rpc_state_reader.rs +++ b/crates/starknet_gateway/src/rpc_state_reader.rs @@ -1,8 +1,8 @@ use blockifier::blockifier::block::BlockInfo; use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; @@ -22,7 +22,7 @@ use crate::rpc_objects::{ BlockId, GetBlockWithTxHashesParams, GetClassHashAtParams, - GetCompiledContractClassParams, + GetCompiledClassParams, GetNonceParams, GetStorageAtParams, RpcResponse, @@ -139,23 +139,20 @@ impl BlockifierStateReader for RpcStateReader { } } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { let get_compiled_class_params = - GetCompiledContractClassParams { class_hash, block_id: self.block_id }; + GetCompiledClassParams { class_hash, block_id: self.block_id }; let result = self.send_rpc_request("starknet_getCompiledContractClass", get_compiled_class_params)?; 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(RunnableContractClass::V1( - ContractClassV1::try_from(contract_class_v1).map_err(StateError::ProgramError)?, + CompiledContractClass::V1(contract_class_v1) => Ok(RunnableCompiledClass::V1( + CompiledClassV1::try_from(contract_class_v1).map_err(StateError::ProgramError)?, )), - CompiledContractClass::V0(contract_class_v0) => Ok(RunnableContractClass::V0( - ContractClassV0::try_from(contract_class_v0).map_err(StateError::ProgramError)?, + CompiledContractClass::V0(contract_class_v0) => Ok(RunnableCompiledClass::V0( + CompiledClassV0::try_from(contract_class_v0).map_err(StateError::ProgramError)?, )), } } diff --git a/crates/starknet_gateway/src/rpc_state_reader_test.rs b/crates/starknet_gateway/src/rpc_state_reader_test.rs index 034c9db09c9..34756045fb5 100644 --- a/crates/starknet_gateway/src/rpc_state_reader_test.rs +++ b/crates/starknet_gateway/src/rpc_state_reader_test.rs @@ -1,4 +1,4 @@ -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::state_api::StateReader; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use papyrus_rpc::CompiledContractClass; @@ -13,7 +13,7 @@ use crate::rpc_objects::{ BlockId, GetBlockWithTxHashesParams, GetClassHashAtParams, - GetCompiledContractClassParams, + GetCompiledClassParams, GetNonceParams, GetStorageAtParams, ResourcePrice, @@ -153,7 +153,7 @@ async fn test_get_nonce_at() { } #[tokio::test] -async fn test_get_compiled_contract_class() { +async fn test_get_compiled_class() { let mut server = run_rpc_server().await; let config = RpcStateReaderConfig { url: server.url(), ..Default::default() }; @@ -171,10 +171,7 @@ async fn test_get_compiled_contract_class() { &mut server, &config.json_rpc_version, "starknet_getCompiledContractClass", - GetCompiledContractClassParams { - block_id: BlockId::Latest, - class_hash: class_hash!("0x1"), - }, + GetCompiledClassParams { block_id: BlockId::Latest, class_hash: class_hash!("0x1") }, &RpcResponse::Success(RpcSuccessResponse { result: serde_json::to_value(CompiledContractClass::V1(expected_result.clone())) .unwrap(), @@ -183,12 +180,11 @@ async fn test_get_compiled_contract_class() { ); let client = RpcStateReader::from_latest(&config); - let result = - tokio::task::spawn_blocking(move || client.get_compiled_contract_class(class_hash!("0x1"))) - .await - .unwrap() - .unwrap(); - assert_eq!(result, RunnableContractClass::V1(expected_result.try_into().unwrap())); + let result = tokio::task::spawn_blocking(move || client.get_compiled_class(class_hash!("0x1"))) + .await + .unwrap() + .unwrap(); + assert_eq!(result, RunnableCompiledClass::V1(expected_result.try_into().unwrap())); mock.assert_async().await; } diff --git a/crates/starknet_gateway/src/state_reader.rs b/crates/starknet_gateway/src/state_reader.rs index 993fe4b5d55..4109a426eea 100644 --- a/crates/starknet_gateway/src/state_reader.rs +++ b/crates/starknet_gateway/src/state_reader.rs @@ -1,5 +1,5 @@ use blockifier::blockifier::block::BlockInfo; -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; #[cfg(test)] @@ -45,11 +45,8 @@ impl BlockifierStateReader for Box { self.as_ref().get_class_hash_at(contract_address) } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { - self.as_ref().get_compiled_contract_class(class_hash) + fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { + self.as_ref().get_compiled_class(class_hash) } fn get_compiled_class_hash(&self, class_hash: ClassHash) -> StateResult { diff --git a/crates/starknet_gateway/src/state_reader_test_utils.rs b/crates/starknet_gateway/src/state_reader_test_utils.rs index faf1121a530..45184de5d4e 100644 --- a/crates/starknet_gateway/src/state_reader_test_utils.rs +++ b/crates/starknet_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::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; use blockifier::test_utils::contracts::FeatureContract; @@ -44,11 +44,8 @@ impl BlockifierStateReader for TestStateReader { self.blockifier_state_reader.get_class_hash_at(contract_address) } - fn get_compiled_contract_class( - &self, - class_hash: ClassHash, - ) -> StateResult { - self.blockifier_state_reader.get_compiled_contract_class(class_hash) + fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { + self.blockifier_state_reader.get_compiled_class(class_hash) } fn get_compiled_class_hash(&self, class_hash: ClassHash) -> StateResult {