Skip to content

Commit

Permalink
refactor(blockifier): remove WORD_WIDTH from blockifier, use starkn e…
Browse files Browse the repository at this point in the history
…t_api instead
  • Loading branch information
avivg-starkware committed Nov 13, 2024
1 parent 2b4f533 commit 7c22e27
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/blockifier/src/fee/eth_gas_constants.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/fee/receipt_test.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions crates/starknet_api/src/contract_class.rs
Original file line number Diff line number Diff line change
@@ -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,
)]
Expand Down Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_api/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7c22e27

Please sign in to comment.