Skip to content

Commit b76d138

Browse files
fix rebase?
1 parent b862482 commit b76d138

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

crates/blockifier/src/execution/contract_class.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ pub struct FeltSizeCount {
7373
}
7474

7575
impl FeltSizeCount {
76+
// Constants that define how felts are encoded into u32s for BLAKE hashing.
77+
// Number of `u32` words in a single BLAKE input message block.
78+
pub(crate) const U32_WORDS_PER_MESSAGE: usize = 16;
79+
// Number of `u32` words a large felt expands into.
80+
pub(crate) const U32_WORDS_PER_LARGE_FELT: usize = 8;
81+
// Number of `u32` words a small felt expands into.
82+
pub(crate) const U32_WORDS_PER_SMALL_FELT: usize = 2;
83+
7684
pub(crate) fn n_felts(&self) -> usize {
7785
self.small + self.large
7886
}

crates/blockifier/src/execution/execution_utils.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,6 @@ pub fn poseidon_hash_many_cost(data_length: usize) -> ExecutionResources {
373373
}
374374
}
375375

376-
// Constants that define how felts are encoded into u32s for BLAKE hashing.
377-
mod blake_encoding {
378-
// Number of `u32` words in a single BLAKE input message block.
379-
pub(crate) const U32_WORDS_PER_MESSAGE: usize = 16;
380-
// Number of `u32` words a large felt expands into.
381-
pub(crate) const U32_WORDS_PER_LARGE_FELT: usize = 8;
382-
// Number of `u32` words a small felt expands into.
383-
pub(crate) const U32_WORDS_PER_SMALL_FELT: usize = 2;
384-
}
385-
386376
// Constants used for estimating the cost of BLAKE hashing inside Starknet OS.
387377
// These values are based on empirical measurement by running
388378
// `encode_felt252_data_and_calc_blake_hash` on various combinations of big and small felts.
@@ -408,16 +398,16 @@ mod blake_estimation {
408398
/// Big felts encode to 8 u32s each, small felts encode to 2 u32s each.
409399
fn total_u32s_from_felts(n_big_felts: usize, n_small_felts: usize) -> usize {
410400
let big_u32s = n_big_felts
411-
.checked_mul(blake_encoding::U32_WORDS_PER_LARGE_FELT)
401+
.checked_mul(FeltSizeCount::U32_WORDS_PER_LARGE_FELT)
412402
.expect("Overflow computing big felts u32s");
413403
let small_u32s = n_small_felts
414-
.checked_mul(blake_encoding::U32_WORDS_PER_SMALL_FELT)
404+
.checked_mul(FeltSizeCount::U32_WORDS_PER_SMALL_FELT)
415405
.expect("Overflow computing small felts u32s");
416406
big_u32s.checked_add(small_u32s).expect("Overflow computing total u32s")
417407
}
418408

419409
fn base_steps_for_blake_hash(n_u32s: usize) -> usize {
420-
let rem_u32s = n_u32s % blake_encoding::U32_WORDS_PER_MESSAGE;
410+
let rem_u32s = n_u32s % FeltSizeCount::U32_WORDS_PER_MESSAGE;
421411
if rem_u32s == 0 {
422412
blake_estimation::BASE_STEPS_FULL_MSG
423413
} else {
@@ -461,7 +451,7 @@ fn estimate_steps_of_encode_felt252_data_and_calc_blake_hash(
461451
fn count_blake_opcode(felt_size_groups: &FeltSizeCount) -> usize {
462452
// Count the total number of u32s to be hashed.
463453
let total_u32s = total_u32s_from_felts(felt_size_groups.large, felt_size_groups.small);
464-
total_u32s.div_ceil(blake_encoding::U32_WORDS_PER_MESSAGE)
454+
total_u32s.div_ceil(FeltSizeCount::U32_WORDS_PER_MESSAGE)
465455
}
466456

467457
/// Estimates resource usage for `encode_felt252_data_and_calc_blake_hash` in the Starknet OS.

crates/blockifier/src/execution/execution_utils_test.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use starknet_types_core::felt::Felt;
66
use crate::execution::contract_class::FeltSizeCount;
77
use crate::execution::execution_utils::blake_estimation::STEPS_EMPTY_INPUT;
88
use crate::execution::execution_utils::{
9-
blake_encoding,
109
count_blake_opcode,
1110
encode_and_blake_hash_resources,
1211
estimate_steps_of_encode_felt252_data_and_calc_blake_hash,
@@ -23,8 +22,8 @@ fn test_u32_constants() {
2322
let big_u32s = encode_felts_to_u32s(vec![big_felt]);
2423

2524
// Blake estimation constants should match the actual encoding.
26-
assert_eq!(small_u32s.len(), blake_encoding::U32_WORDS_PER_SMALL_FELT);
27-
assert_eq!(big_u32s.len(), blake_encoding::U32_WORDS_PER_LARGE_FELT);
25+
assert_eq!(small_u32s.len(), FeltSizeCount::U32_WORDS_PER_SMALL_FELT);
26+
assert_eq!(big_u32s.len(), FeltSizeCount::U32_WORDS_PER_LARGE_FELT);
2827
}
2928

3029
/// Test the edge case of hashing an empty array of felt values.

0 commit comments

Comments
 (0)