Skip to content

Commit 6008f4b

Browse files
blockifier: encode blake in trait
1 parent 7a2291c commit 6008f4b

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

crates/blockifier/src/execution/casm_hash_estimation.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::execution::contract_class::{
1010
FeltSizeCount,
1111
NestedFeltCounts,
1212
};
13-
use crate::execution::execution_utils::poseidon_hash_many_cost;
13+
use crate::execution::execution_utils::{encode_and_blake_hash_resources, poseidon_hash_many_cost};
1414
use crate::utils::u64_from_usize;
1515

1616
#[cfg(test)]
@@ -151,8 +151,7 @@ trait EstimateCasmHashResources {
151151
/// Estimates the Cairo execution resources used when applying the hash function during CASM
152152
/// hashing.
153153
fn estimated_resources_of_hash_function(
154-
&mut self,
155-
_felt_count: FeltSizeCount,
154+
_felt_size_groups: &FeltSizeCount,
156155
) -> EstimatedExecutionResources;
157156

158157
/// Estimates the Cairo execution resources for `compiled_class_hash` in the
@@ -177,12 +176,11 @@ impl EstimateCasmHashResources for CasmV1HashResourceEstimate {
177176
}
178177

179178
fn estimated_resources_of_hash_function(
180-
&mut self,
181-
felt_count: FeltSizeCount,
179+
felt_size_groups: &FeltSizeCount,
182180
) -> EstimatedExecutionResources {
183181
EstimatedExecutionResources::V1Hash {
184182
// TODO(AvivG): Consider inlining `poseidon_hash_many_cost` logic here.
185-
resources: poseidon_hash_many_cost(felt_count.n_felts()),
183+
resources: poseidon_hash_many_cost(felt_size_groups.n_felts()),
186184
}
187185
}
188186
}
@@ -197,10 +195,8 @@ impl EstimateCasmHashResources for CasmV2HashResourceEstimate {
197195
}
198196

199197
fn estimated_resources_of_hash_function(
200-
&mut self,
201-
_felt_count: FeltSizeCount,
198+
felt_size_groups: &FeltSizeCount,
202199
) -> EstimatedExecutionResources {
203-
// TODO(AvivG): Use `cost_of_encode_felt252_data_and_calc_blake_hash` once it returns ER.
204-
EstimatedExecutionResources::new(HashVersion::V2)
200+
encode_and_blake_hash_resources(felt_size_groups)
205201
}
206202
}

crates/blockifier/src/execution/execution_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ fn felts_steps(n_big_felts: usize, n_small_felts: usize) -> usize {
422422
fn estimate_steps_of_encode_felt252_data_and_calc_blake_hash(
423423
felt_size_groups: &FeltSizeCount,
424424
) -> usize {
425-
let total_u32s = total_u32s_from_felts(felt_size_groups.large, felt_size_groups.small);
425+
let total_u32s = felt_size_groups.encoded_u32_len();
426426
if total_u32s == 0 {
427427
// The empty input case is a special case.
428428
return blake_estimation::STEPS_EMPTY_INPUT;

0 commit comments

Comments
 (0)