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 12, 2024
1 parent 4276a78 commit 4632773
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use crate::execution::errors::{ContractClassError, 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::fee::eth_gas_constants;
use crate::transaction::errors::TransactionExecutionError;
use crate::versioned_constants::CompilerVersion;

Expand Down Expand Up @@ -562,7 +561,7 @@ impl ClassInfo {
pub fn code_size(&self) -> usize {
(self.bytecode_length() + self.sierra_program_length())
// We assume each felt is a word.
* eth_gas_constants::WORD_WIDTH
* starknet_api::core::WORD_WIDTH
+ self.abi_length()
}

Expand Down
8 changes: 3 additions & 5 deletions crates/blockifier/src/fee/eth_gas_constants.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// 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;
pub const GAS_PER_MEMORY_WORD: usize = GAS_PER_MEMORY_BYTE * starknet_api::core::WORD_WIDTH;

// Blob Data.
pub const FIELD_ELEMENTS_PER_BLOB: usize = 1 << 12;
Expand All @@ -21,7 +19,7 @@ pub const GAS_PER_COUNTER_DECREASE: usize =
pub const GAS_PER_LOG: usize = 375;
pub const GAS_PER_LOG_TOPIC: usize = 375;
pub const GAS_PER_LOG_DATA_BYTE: usize = 8;
pub const GAS_PER_LOG_DATA_WORD: usize = GAS_PER_LOG_DATA_BYTE * WORD_WIDTH;
pub const GAS_PER_LOG_DATA_WORD: usize = GAS_PER_LOG_DATA_BYTE * starknet_api::core::WORD_WIDTH;

// SHARP empirical costs.
pub const SHARP_ADDITIONAL_GAS_PER_MEMORY_WORD: usize = 100; // This value is not accurate.
Expand All @@ -34,5 +32,5 @@ pub const SHARP_GAS_PER_DA_WORD: usize = SHARP_GAS_PER_MEMORY_WORD - DISCOUNT_PE
// TODO(Yoni, 1/1/2025): rename this file to `_utils`.
pub fn get_calldata_word_cost(n_nonzero_bytes: usize) -> usize {
n_nonzero_bytes * GAS_PER_MEMORY_BYTE
+ (WORD_WIDTH - n_nonzero_bytes) * GAS_PER_MEMORY_ZERO_BYTE
+ (starknet_api::core::WORD_WIDTH - n_nonzero_bytes) * GAS_PER_MEMORY_ZERO_BYTE
}
2 changes: 1 addition & 1 deletion crates/blockifier/src/fee/receipt_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn test_calculate_tx_gas_usage_basic<'a>(
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
* starknet_api::core::WORD_WIDTH
+ class_info.abi_length(),
))
.to_integer()
Expand Down

0 comments on commit 4632773

Please sign in to comment.