diff --git a/crates/blockifier/src/execution/native/syscall_handler.rs b/crates/blockifier/src/execution/native/syscall_handler.rs index 0c0869d5355..ca4778b57fb 100644 --- a/crates/blockifier/src/execution/native/syscall_handler.rs +++ b/crates/blockifier/src/execution/native/syscall_handler.rs @@ -32,7 +32,6 @@ use starknet_types_core::felt::Felt; use crate::execution::call_info::{MessageToL1, OrderedL2ToL1Message, Retdata}; use crate::execution::common_hints::ExecutionMode; -use crate::execution::contract_class::RunnableContractClass; use crate::execution::entry_point::{ CallEntryPoint, CallType, diff --git a/crates/mempool_test_utils/src/starknet_api_test_utils.rs b/crates/mempool_test_utils/src/starknet_api_test_utils.rs index c9e685fbd7b..74a1a7b5a40 100644 --- a/crates/mempool_test_utils/src/starknet_api_test_utils.rs +++ b/crates/mempool_test_utils/src/starknet_api_test_utils.rs @@ -15,7 +15,8 @@ use starknet_api::block::GasPrice; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::executable_transaction::AccountTransaction; use starknet_api::execution_resources::GasAmount; -use starknet_api::rpc_transaction::{ContractClass, RpcTransaction}; +use starknet_api::rpc_transaction::RpcTransaction; +use starknet_api::state::SierraContractClass; use starknet_api::test_utils::declare::rpc_declare_tx; use starknet_api::test_utils::deploy_account::rpc_deploy_account_tx; use starknet_api::test_utils::invoke::{rpc_invoke_tx, InvokeTxArgs}; @@ -65,7 +66,7 @@ pub fn test_valid_resource_bounds() -> ValidResourceBounds { } /// Get the contract class used for testing. -pub fn contract_class() -> ContractClass { +pub fn contract_class() -> SierraContractClass { env::set_current_dir(resolve_project_relative_path(TEST_FILES_FOLDER).unwrap()) .expect("Couldn't set working dir."); let json_file_path = Path::new(CONTRACT_CLASS_FILE); diff --git a/crates/papyrus_protobuf/src/converters/rpc_transaction.rs b/crates/papyrus_protobuf/src/converters/rpc_transaction.rs index 234a31e3ffc..55998e14e8b 100644 --- a/crates/papyrus_protobuf/src/converters/rpc_transaction.rs +++ b/crates/papyrus_protobuf/src/converters/rpc_transaction.rs @@ -4,8 +4,6 @@ mod rpc_transaction_test; use prost::Message; use starknet_api::rpc_transaction::{ - ContractClass, - EntryPointByType, RpcDeclareTransaction, RpcDeclareTransactionV3, RpcDeployAccountTransaction, @@ -14,19 +12,17 @@ use starknet_api::rpc_transaction::{ RpcInvokeTransactionV3, RpcTransaction, }; -use starknet_api::state::EntryPoint; use starknet_api::transaction::fields::{AllResourceBounds, ValidResourceBounds}; use starknet_api::transaction::{ DeclareTransactionV3, DeployAccountTransactionV3, InvokeTransactionV3, }; -use starknet_types_core::felt::Felt; use super::ProtobufConversionError; use crate::auto_impl_into_and_try_from_vec_u8; use crate::mempool::RpcTransactionWrapper; -use crate::protobuf::{self, Felt252}; +use crate::protobuf::{self}; auto_impl_into_and_try_from_vec_u8!(RpcTransactionWrapper, protobuf::RpcTransaction); @@ -330,63 +326,3 @@ impl From for protobuf::ResourceBounds { ValidResourceBounds::AllResources(value).into() } } - -impl TryFrom for ContractClass { - type Error = ProtobufConversionError; - fn try_from(value: protobuf::Cairo1Class) -> Result { - let sierra_program = - value.program.into_iter().map(Felt::try_from).collect::, _>>()?; - let contract_class_version = value.contract_class_version; - let entry_points = value.entry_points.ok_or(ProtobufConversionError::MissingField { - field_description: "Cairo1Class::entry_points_by_type", - })?; - let entry_points_by_type = EntryPointByType { - constructor: entry_points - .constructors - .into_iter() - .map(EntryPoint::try_from) - .collect::, _>>()?, - external: entry_points - .externals - .into_iter() - .map(EntryPoint::try_from) - .collect::, _>>()?, - l1handler: entry_points - .l1_handlers - .into_iter() - .map(EntryPoint::try_from) - .collect::, _>>()?, - }; - let abi = value.abi; - Ok(Self { sierra_program, contract_class_version, entry_points_by_type, abi }) - } -} - -impl From for protobuf::Cairo1Class { - fn from(value: ContractClass) -> Self { - let program = value.sierra_program.into_iter().map(Felt252::from).collect(); - let contract_class_version = value.contract_class_version; - let entry_points = protobuf::Cairo1EntryPoints { - constructors: value - .entry_points_by_type - .constructor - .into_iter() - .map(protobuf::SierraEntryPoint::from) - .collect(), - externals: value - .entry_points_by_type - .external - .into_iter() - .map(protobuf::SierraEntryPoint::from) - .collect(), - l1_handlers: value - .entry_points_by_type - .l1handler - .into_iter() - .map(protobuf::SierraEntryPoint::from) - .collect(), - }; - let abi = value.abi; - Self { program, contract_class_version, entry_points: Some(entry_points), abi } - } -} diff --git a/crates/papyrus_test_utils/src/lib.rs b/crates/papyrus_test_utils/src/lib.rs index e930cf6e60e..2dbf884e806 100644 --- a/crates/papyrus_test_utils/src/lib.rs +++ b/crates/papyrus_test_utils/src/lib.rs @@ -88,7 +88,6 @@ use starknet_api::deprecated_contract_class::{ use starknet_api::execution_resources::{Builtin, ExecutionResources, GasAmount, GasVector}; use starknet_api::hash::{PoseidonHash, StarkHash}; use starknet_api::rpc_transaction::{ - ContractClass as RpcContractClass, EntryPointByType as RpcEntryPointByType, EntryPointByType, RpcDeclareTransaction, @@ -750,12 +749,6 @@ auto_impl_get_test_instance! { pub max_amount: GasAmount, pub max_price_per_unit: GasPrice, } - pub struct RpcContractClass { - pub sierra_program: Vec, - pub contract_class_version: String, - pub entry_points_by_type: RpcEntryPointByType, - pub abi: String, - } pub enum RpcTransaction { Declare(RpcDeclareTransaction) = 0, DeployAccount(RpcDeployAccountTransaction) = 1, @@ -769,7 +762,7 @@ auto_impl_get_test_instance! { pub tip: Tip, pub signature: TransactionSignature, pub nonce: Nonce, - pub contract_class: RpcContractClass, + pub contract_class: SierraContractClass, pub compiled_class_hash: CompiledClassHash, pub sender_address: ContractAddress, pub nonce_data_availability_mode: DataAvailabilityMode, diff --git a/crates/starknet_api/src/rpc_transaction.rs b/crates/starknet_api/src/rpc_transaction.rs index 4607fdd45d5..49295a230d1 100644 --- a/crates/starknet_api/src/rpc_transaction.rs +++ b/crates/starknet_api/src/rpc_transaction.rs @@ -5,7 +5,6 @@ mod rpc_transaction_test; use std::collections::HashMap; use serde::{Deserialize, Serialize}; -use starknet_types_core::felt::Felt; use crate::contract_class::EntryPointType; use crate::core::{ @@ -16,7 +15,7 @@ use crate::core::{ Nonce, }; use crate::data_availability::DataAvailabilityMode; -use crate::state::EntryPoint; +use crate::state::{EntryPoint, SierraContractClass}; use crate::transaction::fields::{ AccountDeploymentData, AllResourceBounds, @@ -180,7 +179,7 @@ pub struct RpcDeclareTransactionV3 { pub compiled_class_hash: CompiledClassHash, pub signature: TransactionSignature, pub nonce: Nonce, - pub contract_class: ContractClass, + pub contract_class: SierraContractClass, pub resource_bounds: AllResourceBounds, pub tip: Tip, pub paymaster_data: PaymasterData, @@ -272,15 +271,6 @@ impl From for InvokeTransactionV3 { } } -// The contract class in SN_API state doesn't have `contract_class_version`, not following the spec. -#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, Hash)] -pub struct ContractClass { - pub sierra_program: Vec, - pub contract_class_version: String, - pub entry_points_by_type: EntryPointByType, - pub abi: String, -} - // TODO(Aviv): remove duplication with sequencer/crates/papyrus_rpc/src/v0_8/state.rs #[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize, Hash)] pub struct EntryPointByType { diff --git a/crates/starknet_api/src/rpc_transaction_test.rs b/crates/starknet_api/src/rpc_transaction_test.rs index f12acce012e..7854a5d9297 100644 --- a/crates/starknet_api/src/rpc_transaction_test.rs +++ b/crates/starknet_api/src/rpc_transaction_test.rs @@ -7,7 +7,6 @@ use crate::block::GasPrice; use crate::core::CompiledClassHash; use crate::execution_resources::GasAmount; use crate::rpc_transaction::{ - ContractClass, DataAvailabilityMode, RpcDeclareTransaction, RpcDeclareTransactionV3, @@ -15,6 +14,7 @@ use crate::rpc_transaction::{ RpcDeployAccountTransactionV3, RpcTransaction, }; +use crate::state::SierraContractClass; use crate::test_utils::invoke::{rpc_invoke_tx, InvokeTxArgs}; use crate::transaction::fields::{ AccountDeploymentData, @@ -40,7 +40,7 @@ fn create_resource_bounds_for_testing() -> AllResourceBounds { fn create_declare_v3() -> RpcDeclareTransaction { RpcDeclareTransaction::V3(RpcDeclareTransactionV3 { - contract_class: ContractClass::default(), + contract_class: SierraContractClass::default(), resource_bounds: create_resource_bounds_for_testing(), tip: Tip(1), signature: TransactionSignature(vec![Felt::ONE, Felt::TWO]), diff --git a/crates/starknet_api/src/state.rs b/crates/starknet_api/src/state.rs index 8bfb841bef4..5de7b488652 100644 --- a/crates/starknet_api/src/state.rs +++ b/crates/starknet_api/src/state.rs @@ -209,7 +209,7 @@ impl StorageKey { impl_from_through_intermediate!(u128, StorageKey, u8, u16, u32, u64); /// A contract class. -#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize, Hash)] pub struct SierraContractClass { pub sierra_program: Vec, pub contract_class_version: String, diff --git a/crates/starknet_api/src/test_utils/declare.rs b/crates/starknet_api/src/test_utils/declare.rs index 141cf964b92..8f905add897 100644 --- a/crates/starknet_api/src/test_utils/declare.rs +++ b/crates/starknet_api/src/test_utils/declare.rs @@ -3,12 +3,8 @@ use crate::contract_class::ClassInfo; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; use crate::executable_transaction::DeclareTransaction as ExecutableDeclareTransaction; -use crate::rpc_transaction::{ - ContractClass, - RpcDeclareTransaction, - RpcDeclareTransactionV3, - RpcTransaction, -}; +use crate::rpc_transaction::{RpcDeclareTransaction, RpcDeclareTransactionV3, RpcTransaction}; +use crate::state::SierraContractClass; use crate::transaction::fields::{ AccountDeploymentData, Fee, @@ -142,7 +138,7 @@ pub fn executable_declare_tx( pub fn rpc_declare_tx( declare_tx_args: DeclareTxArgs, - contract_class: ContractClass, + contract_class: SierraContractClass, ) -> RpcTransaction { if declare_tx_args.version != TransactionVersion::THREE { panic!("Unsupported transaction version: {:?}.", declare_tx_args.version); diff --git a/crates/starknet_gateway/src/stateless_transaction_validator.rs b/crates/starknet_gateway/src/stateless_transaction_validator.rs index 8dbd815540b..871e2a3d3ce 100644 --- a/crates/starknet_gateway/src/stateless_transaction_validator.rs +++ b/crates/starknet_gateway/src/stateless_transaction_validator.rs @@ -237,7 +237,7 @@ impl StatelessTransactionValidator { fn validate_class_length( &self, - contract_class: &starknet_api::rpc_transaction::ContractClass, + contract_class: &starknet_api::state::SierraContractClass, ) -> StatelessTransactionValidatorResult<()> { let contract_class_object_size = serde_json::to_string(&contract_class) .expect("Unexpected error serializing contract class.") @@ -254,7 +254,7 @@ impl StatelessTransactionValidator { fn validate_entry_points_sorted_and_unique( &self, - contract_class: &starknet_api::rpc_transaction::ContractClass, + contract_class: &starknet_api::state::SierraContractClass, ) -> StatelessTransactionValidatorResult<()> { let is_sorted_unique = |entry_points: &[EntryPoint]| { entry_points.windows(2).all(|pair| pair[0].selector < pair[1].selector) diff --git a/crates/starknet_gateway/src/stateless_transaction_validator_test.rs b/crates/starknet_gateway/src/stateless_transaction_validator_test.rs index dd79ded4df7..f02600404ac 100644 --- a/crates/starknet_gateway/src/stateless_transaction_validator_test.rs +++ b/crates/starknet_gateway/src/stateless_transaction_validator_test.rs @@ -5,8 +5,8 @@ use assert_matches::assert_matches; use rstest::rstest; use starknet_api::core::{EntryPointSelector, L2_ADDRESS_UPPER_BOUND}; use starknet_api::data_availability::DataAvailabilityMode; -use starknet_api::rpc_transaction::{ContractClass, EntryPointByType}; -use starknet_api::state::EntryPoint; +use starknet_api::rpc_transaction::EntryPointByType; +use starknet_api::state::{EntryPoint, SierraContractClass}; use starknet_api::test_utils::declare::rpc_declare_tx; use starknet_api::transaction::fields::{ AccountDeploymentData, @@ -356,10 +356,12 @@ fn test_declare_sierra_version_failure( #[case] sierra_program: Vec, #[case] expected_error: StatelessTransactionValidatorError, ) { + use starknet_api::state::SierraContractClass; + let tx_validator = StatelessTransactionValidator { config: DEFAULT_VALIDATOR_CONFIG_FOR_TESTING.clone() }; - let contract_class = ContractClass { sierra_program, ..Default::default() }; + let contract_class = SierraContractClass { sierra_program, ..Default::default() }; let tx = rpc_declare_tx(declare_tx_args!(), contract_class); assert_eq!(tx_validator.validate(&tx).unwrap_err(), expected_error); @@ -379,7 +381,7 @@ fn test_declare_sierra_version_sucsses(#[case] sierra_program: Vec) { let tx_validator = StatelessTransactionValidator { config: DEFAULT_VALIDATOR_CONFIG_FOR_TESTING.clone() }; - let contract_class = ContractClass { sierra_program, ..Default::default() }; + let contract_class = SierraContractClass { sierra_program, ..Default::default() }; let tx = rpc_declare_tx(declare_tx_args!(), contract_class); assert_matches!(tx_validator.validate(&tx), Ok(())); @@ -394,7 +396,7 @@ fn test_declare_contract_class_size_too_long() { ..*DEFAULT_VALIDATOR_CONFIG_FOR_TESTING }, }; - let contract_class = ContractClass { + let contract_class = SierraContractClass { sierra_program: create_sierra_program(&MIN_SIERRA_VERSION), ..Default::default() }; @@ -458,7 +460,7 @@ fn test_declare_entry_points_not_sorted_by_selector( let tx_validator = StatelessTransactionValidator { config: DEFAULT_VALIDATOR_CONFIG_FOR_TESTING.clone() }; - let contract_class = ContractClass { + let contract_class = SierraContractClass { sierra_program: create_sierra_program(&MIN_SIERRA_VERSION), entry_points_by_type: EntryPointByType { constructor: entry_points.clone(), @@ -471,7 +473,7 @@ fn test_declare_entry_points_not_sorted_by_selector( assert_eq!(tx_validator.validate(&tx), expected); - let contract_class = ContractClass { + let contract_class = SierraContractClass { sierra_program: create_sierra_program(&MIN_SIERRA_VERSION), entry_points_by_type: EntryPointByType { constructor: vec![], @@ -484,7 +486,7 @@ fn test_declare_entry_points_not_sorted_by_selector( assert_eq!(tx_validator.validate(&tx), expected); - let contract_class = ContractClass { + let contract_class = SierraContractClass { sierra_program: create_sierra_program(&MIN_SIERRA_VERSION), entry_points_by_type: EntryPointByType { constructor: vec![], diff --git a/crates/starknet_gateway/src/test_utils.rs b/crates/starknet_gateway/src/test_utils.rs index d8866fdffea..f92bb5bce8e 100644 --- a/crates/starknet_gateway/src/test_utils.rs +++ b/crates/starknet_gateway/src/test_utils.rs @@ -2,7 +2,8 @@ use starknet_api::block::GasPrice; use starknet_api::core::ContractAddress; use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::execution_resources::GasAmount; -use starknet_api::rpc_transaction::{ContractClass, RpcTransaction}; +use starknet_api::rpc_transaction::RpcTransaction; +use starknet_api::state::SierraContractClass; use starknet_api::test_utils::declare::{rpc_declare_tx, TEST_SENDER_ADDRESS}; use starknet_api::test_utils::deploy_account::rpc_deploy_account_tx; use starknet_api::test_utils::invoke::rpc_invoke_tx; @@ -89,7 +90,7 @@ pub fn rpc_tx_for_testing( match tx_type { TransactionType::Declare => { // Minimal contract class. - let contract_class = ContractClass { + let contract_class = SierraContractClass { sierra_program: vec![ // Sierra Version ID. felt!(1_u32), diff --git a/crates/starknet_sierra_compile/src/utils.rs b/crates/starknet_sierra_compile/src/utils.rs index e96d0ada5ff..d02a6b7db2d 100644 --- a/crates/starknet_sierra_compile/src/utils.rs +++ b/crates/starknet_sierra_compile/src/utils.rs @@ -6,11 +6,11 @@ use cairo_lang_starknet_classes::contract_class::{ ContractEntryPoints as CairoLangContractEntryPoints, }; use cairo_lang_utils::bigint::BigUintAsHex; -use starknet_api::rpc_transaction::{ - ContractClass as RpcContractClass, - EntryPointByType as StarknetApiEntryPointByType, +use starknet_api::rpc_transaction::EntryPointByType as StarknetApiEntryPointByType; +use starknet_api::state::{ + EntryPoint as StarknetApiEntryPoint, + SierraContractClass as RpcContractClass, }; -use starknet_api::state::EntryPoint as StarknetApiEntryPoint; use starknet_types_core::felt::Felt; /// Retruns a [`CairoLangContractClass`] struct ready for Sierra to Casm compilation. Note the `abi`