Skip to content

Commit e2241af

Browse files
blockifier: change input to felt_counts fn compute_blake_hash_steps
1 parent b8ec2a6 commit e2241af

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

crates/blockifier/src/execution/execution_utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,17 @@ 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 estimate_steps_of_encode_felt252_data_and_calc_blake_hash(
435+
felt_size_groups: &FeltSizeCount,
436+
) -> usize {
437+
let total_u32s = felt_size_groups.encoded_u32_len();
436438
if total_u32s == 0 {
437439
// The empty input case is a special case.
438440
return blake_estimation::STEPS_EMPTY_INPUT;
439441
}
440442

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

444446
base_steps.checked_add(felt_steps).expect("Overflow computing total Blake hash steps")
445447
}
@@ -465,7 +467,7 @@ fn count_blake_opcode(n_big_felts: usize, n_small_felts: usize) -> usize {
465467
pub fn encode_and_blake_hash_resources(
466468
felt_size_groups: &FeltSizeCount,
467469
) -> EstimatedExecutionResources {
468-
let n_steps = compute_blake_hash_steps(felt_size_groups.large, felt_size_groups.small);
470+
let n_steps = estimate_steps_of_encode_felt252_data_and_calc_blake_hash(felt_size_groups);
469471
let builtin_instance_counter = match felt_size_groups.n_felts() {
470472
// The empty case does not use builtins at all.
471473
0 => HashMap::new(),

crates/blockifier/src/execution/execution_utils_test.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ 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::{
10-
compute_blake_hash_steps,
119
count_blake_opcode,
1210
encode_and_blake_hash_resources,
11+
estimate_steps_of_encode_felt252_data_and_calc_blake_hash,
1312
};
1413

1514
#[test]
@@ -31,7 +30,10 @@ 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 = estimate_steps_of_encode_felt252_data_and_calc_blake_hash(&FeltSizeCount {
34+
large: 0,
35+
small: 0,
36+
});
3537
assert_eq!(steps, STEPS_EMPTY_INPUT, "Unexpected base step cost for zero inputs");
3638

3739
// No opcodes should be emitted.
@@ -46,7 +48,7 @@ fn test_zero_inputs() {
4648
}
4749

4850
// TODO(AvivG): Add tests for:
49-
// - `compute_blake_hash_steps` simple cases (felts input).
51+
// - `estimate_steps_of_encode_felt252_data_and_calc_blake_hash` simple cases (felts input).
5052
// - `count_blake_opcode` simple cases (felts input).
5153
// - `cost_of_encode_felt252_data_and_calc_blake_hash` simple cases (felts input) (including partial
5254
// remainder).

0 commit comments

Comments
 (0)