From 7c22e272e0b74972b1fed32ba6353bdeebc86e4e Mon Sep 17 00:00:00 2001 From: Aviv Greenburg Date: Tue, 12 Nov 2024 08:15:50 +0200 Subject: [PATCH] refactor(blockifier): remove WORD_WIDTH from blockifier, use starkn et_api instead --- crates/blockifier/src/fee/eth_gas_constants.rs | 4 ++-- crates/blockifier/src/fee/receipt_test.rs | 4 ++-- crates/starknet_api/src/contract_class.rs | 7 +++++-- crates/starknet_api/src/core.rs | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/blockifier/src/fee/eth_gas_constants.rs b/crates/blockifier/src/fee/eth_gas_constants.rs index e01eb73132..0055c5d1f4 100644 --- a/crates/blockifier/src/fee/eth_gas_constants.rs +++ b/crates/blockifier/src/fee/eth_gas_constants.rs @@ -1,8 +1,8 @@ +use starknet_api::core::WORD_WIDTH; + // Calldata. pub const GAS_PER_MEMORY_ZERO_BYTE: usize = 4; pub const GAS_PER_MEMORY_BYTE: usize = 16; -// TODO(AvivG): use starknet_api::core::WORD_WIDTH instead. -pub const WORD_WIDTH: usize = 32; pub const GAS_PER_MEMORY_WORD: usize = GAS_PER_MEMORY_BYTE * WORD_WIDTH; // Blob Data. diff --git a/crates/blockifier/src/fee/receipt_test.rs b/crates/blockifier/src/fee/receipt_test.rs index 95c315918b..ac1a72e24d 100644 --- a/crates/blockifier/src/fee/receipt_test.rs +++ b/crates/blockifier/src/fee/receipt_test.rs @@ -1,4 +1,5 @@ use rstest::{fixture, rstest}; +use starknet_api::core::WORD_WIDTH; use starknet_api::execution_resources::GasVector; use starknet_api::transaction::fields::GasVectorComputationMode; use starknet_api::transaction::L2ToL1Payload; @@ -85,8 +86,7 @@ fn test_calculate_tx_gas_usage_basic<'a>( .gas_per_code_byte; let code_gas_cost = (gas_per_code_byte * u64_from_usize( - (class_info.bytecode_length() + class_info.sierra_program_length()) - * eth_gas_constants::WORD_WIDTH + (class_info.bytecode_length() + class_info.sierra_program_length()) * WORD_WIDTH + class_info.abi_length(), )) .to_integer() diff --git a/crates/starknet_api/src/contract_class.rs b/crates/starknet_api/src/contract_class.rs index 72f4bde161..f103a13eae 100644 --- a/crates/starknet_api/src/contract_class.rs +++ b/crates/starknet_api/src/contract_class.rs @@ -1,10 +1,13 @@ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use serde::{Deserialize, Serialize}; -use crate::core::{CompiledClassHash, WORD_WIDTH}; +use crate::core::CompiledClassHash; use crate::deprecated_contract_class::ContractClass as DeprecatedContractClass; use crate::StarknetApiError; +/// One Felt fits into 32 bytes. +pub const FELT_WIDTH: usize = 32; + #[derive( Debug, Default, Clone, Copy, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord, )] @@ -73,7 +76,7 @@ impl ClassInfo { pub fn code_size(&self) -> usize { (self.bytecode_length() + self.sierra_program_length()) // We assume each felt is a word. - * WORD_WIDTH + * FELT_WIDTH + self.abi_length() } diff --git a/crates/starknet_api/src/core.rs b/crates/starknet_api/src/core.rs index 4f7f6d395b..40d7299ba5 100644 --- a/crates/starknet_api/src/core.rs +++ b/crates/starknet_api/src/core.rs @@ -17,7 +17,7 @@ use crate::transaction::fields::{Calldata, ContractAddressSalt}; use crate::{impl_from_through_intermediate, StarknetApiError}; // Ethereum constant. -/// One Felt fits into 32 bytes. +/// Word size in Ethereum. pub const WORD_WIDTH: usize = 32; /// Felt.