From d8264f38660125c8c2abb89c95259c89f7d8d0b3 Mon Sep 17 00:00:00 2001 From: AvivYossef-starkware Date: Thu, 5 Dec 2024 13:22:53 +0200 Subject: [PATCH] refactor(starknet_api): use const in sierra version --- .../blockifier/src/transaction/test_utils.rs | 4 ++-- .../state_reader/reexecution_state_reader.rs | 2 +- crates/papyrus_execution/src/lib.rs | 4 ++-- crates/papyrus_execution/src/test_utils.rs | 2 +- crates/starknet_api/src/contract_class.rs | 18 +++++++----------- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index 07ff2ba797..dd74791c16 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -359,8 +359,8 @@ pub fn create_all_resource_bounds( pub fn calculate_class_info_for_testing(contract_class: ContractClass) -> ClassInfo { let (sierra_program_length, sierra_version) = match contract_class { - ContractClass::V0(_) => (0, SierraVersion::zero()), - ContractClass::V1(_) => (100, SierraVersion::latest()), + ContractClass::V0(_) => (0, SierraVersion::DEPRECATED), + ContractClass::V1(_) => (100, SierraVersion::LATEST), }; ClassInfo::new(&contract_class, sierra_program_length, 100, sierra_version).unwrap() } diff --git a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs index a1aec7138b..46d8016e59 100644 --- a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs @@ -39,7 +39,7 @@ pub trait ReexecutionStateReader { &legacy_to_contract_class_v0(legacy)?, DEPRECATED_CONTRACT_SIERRA_SIZE, abi_length, - SierraVersion::zero(), + SierraVersion::DEPRECATED, )?) } } diff --git a/crates/papyrus_execution/src/lib.rs b/crates/papyrus_execution/src/lib.rs index e982c8a8df..a9b6801fd9 100644 --- a/crates/papyrus_execution/src/lib.rs +++ b/crates/papyrus_execution/src/lib.rs @@ -835,7 +835,7 @@ fn to_blockifier_tx( &deprecated_class.into(), DEPRECATED_CONTRACT_SIERRA_SIZE, abi_length, - SierraVersion::zero(), + SierraVersion::DEPRECATED, ) .map_err(|err| ExecutionError::BadDeclareTransaction { tx: DeclareTransaction::V0(declare_tx.clone()), @@ -862,7 +862,7 @@ fn to_blockifier_tx( &deprecated_class.into(), DEPRECATED_CONTRACT_SIERRA_SIZE, abi_length, - SierraVersion::zero(), + SierraVersion::DEPRECATED, ) .map_err(|err| ExecutionError::BadDeclareTransaction { tx: DeclareTransaction::V1(declare_tx.clone()), diff --git a/crates/papyrus_execution/src/test_utils.rs b/crates/papyrus_execution/src/test_utils.rs index 377cc957a1..6cf362dbe0 100644 --- a/crates/papyrus_execution/src/test_utils.rs +++ b/crates/papyrus_execution/src/test_utils.rs @@ -313,7 +313,7 @@ impl TxsScenarioBuilder { DUMMY_SIERRA_SIZE, 0, false, - SierraVersion::latest(), + SierraVersion::LATEST, ); self.txs.push(tx); self diff --git a/crates/starknet_api/src/contract_class.rs b/crates/starknet_api/src/contract_class.rs index 86445cd26f..c8a295d57a 100644 --- a/crates/starknet_api/src/contract_class.rs +++ b/crates/starknet_api/src/contract_class.rs @@ -52,19 +52,15 @@ impl ContractClass { pub struct SierraVersion(Version); impl SierraVersion { - pub fn new(major: u64, minor: u64, patch: u64) -> Self { - Self(Version::new(major, minor, patch)) - } - - /// Version of deprecated contract class. - pub fn zero() -> Self { - Self(Version::new(0, 0, 0)) - } + /// Version of deprecated contract class (Cairo 0). + pub const DEPRECATED: Self = Self(Version::new(0, 0, 0)); // TODO(Aviv): Implement logic to fetch the latest version dynamically from Cargo.toml and write // tests to ensure that it matches the value returned by this function. - pub fn latest() -> Self { - Self::new(2, 8, 4) + pub const LATEST: Self = Self(Version::new(2, 8, 4)); + + pub fn new(major: u64, minor: u64, patch: u64) -> Self { + Self(Version::new(major, minor, patch)) } /// Converts a sierra program to a SierraVersion. @@ -105,7 +101,7 @@ impl SierraVersion { impl Default for SierraVersion { fn default() -> Self { - Self::latest() + Self::LATEST } }