Skip to content

Commit fc4aacc

Browse files
blockifier: change input to felt_counts fn compute_blake_hash_steps
1 parent 54335b1 commit fc4aacc

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

crates/blockifier/src/execution/execution_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,15 @@ fn felts_steps(n_big_felts: usize, n_small_felts: usize) -> usize {
431431
/// Estimates the number of VM steps needed to hash the given felts with Blake in Starknet OS.
432432
/// Each small felt unpacks into 2 u32s, and each big felt into 8 u32s.
433433
/// Adds a base cost depending on whether the total fits exactly into full 16-u32 messages.
434-
fn compute_blake_hash_steps(n_big_felts: usize, n_small_felts: usize) -> usize {
435-
let total_u32s = total_u32s_from_felts(n_big_felts, n_small_felts);
434+
fn compute_blake_hash_steps(felt_size_groups: &FeltSizeCount) -> usize {
435+
let total_u32s = felt_size_groups.encoded_u32_len();
436436
if total_u32s == 0 {
437437
// The empty input case is a special case.
438438
return blake_estimation::STEPS_EMPTY_INPUT;
439439
}
440440

441441
let base_steps = base_steps_for_blake_hash(total_u32s);
442-
let felt_steps = felts_steps(n_big_felts, n_small_felts);
442+
let felt_steps = felts_steps(felt_size_groups.large, felt_size_groups.small);
443443

444444
base_steps.checked_add(felt_steps).expect("Overflow computing total Blake hash steps")
445445
}
@@ -465,7 +465,7 @@ fn count_blake_opcode(n_big_felts: usize, n_small_felts: usize) -> usize {
465465
pub fn encode_and_blake_hash_resources(
466466
felt_size_groups: &FeltSizeCount,
467467
) -> EstimatedExecutionResources {
468-
let n_steps = compute_blake_hash_steps(felt_size_groups.large, felt_size_groups.small);
468+
let n_steps = compute_blake_hash_steps(felt_size_groups);
469469
let builtin_instance_counter = match felt_size_groups.n_felts() {
470470
// The empty case does not use builtins at all.
471471
0 => HashMap::new(),

crates/blockifier/src/execution/execution_utils_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use pretty_assertions::assert_eq;
44
use starknet_types_core::felt::Felt;
55

66
use crate::execution::contract_class::FeltSizeCount;
7-
use crate::execution::execution_utils::blake_encoding::{N_U32S_BIG_FELT, N_U32S_SMALL_FELT};
87
use crate::execution::execution_utils::blake_estimation::STEPS_EMPTY_INPUT;
98
use crate::execution::execution_utils::{
109
compute_blake_hash_steps,
@@ -31,7 +30,7 @@ fn test_u32_constants() {
3130
#[test]
3231
fn test_zero_inputs() {
3332
// logic was written.
34-
let steps = compute_blake_hash_steps(0, 0);
33+
let steps = compute_blake_hash_steps(&FeltSizeCount { large: 0, small: 0 });
3534
assert_eq!(steps, STEPS_EMPTY_INPUT, "Unexpected base step cost for zero inputs");
3635

3736
// No opcodes should be emitted.

0 commit comments

Comments
 (0)