@@ -25,7 +25,10 @@ use starknet_types_core::felt::Felt;
25
25
use crate :: blockifier_versioned_constants:: VersionedConstants ;
26
26
use crate :: bouncer:: vm_resources_to_sierra_gas;
27
27
use crate :: execution:: call_info:: { CallExecution , CallInfo , Retdata } ;
28
- use crate :: execution:: casm_hash_estimation:: EstimatedExecutionResources ;
28
+ use crate :: execution:: casm_hash_estimation:: {
29
+ CasmV2HashResourceEstimate ,
30
+ EstimatedExecutionResources ,
31
+ } ;
29
32
use crate :: execution:: contract_class:: { FeltSizeCount , RunnableCompiledClass , TrackedResource } ;
30
33
use crate :: execution:: entry_point:: {
31
34
execute_constructor_entry_point,
@@ -373,16 +376,6 @@ pub fn poseidon_hash_many_cost(data_length: usize) -> ExecutionResources {
373
376
}
374
377
}
375
378
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
-
386
379
// Constants used for estimating the cost of BLAKE hashing inside Starknet OS.
387
380
// These values are based on empirical measurement by running
388
381
// `encode_felt252_data_and_calc_blake_hash` on various combinations of big and small felts.
@@ -408,16 +401,16 @@ mod blake_estimation {
408
401
/// Big felts encode to 8 u32s each, small felts encode to 2 u32s each.
409
402
fn total_u32s_from_felts ( n_big_felts : usize , n_small_felts : usize ) -> usize {
410
403
let big_u32s = n_big_felts
411
- . checked_mul ( blake_encoding :: U32_WORDS_PER_LARGE_FELT )
404
+ . checked_mul ( FeltSizeCount :: U32_WORDS_PER_LARGE_FELT )
412
405
. expect ( "Overflow computing big felts u32s" ) ;
413
406
let small_u32s = n_small_felts
414
- . checked_mul ( blake_encoding :: U32_WORDS_PER_SMALL_FELT )
407
+ . checked_mul ( FeltSizeCount :: U32_WORDS_PER_SMALL_FELT )
415
408
. expect ( "Overflow computing small felts u32s" ) ;
416
409
big_u32s. checked_add ( small_u32s) . expect ( "Overflow computing total u32s" )
417
410
}
418
411
419
412
fn base_steps_for_blake_hash ( n_u32s : usize ) -> usize {
420
- let rem_u32s = n_u32s % blake_encoding :: U32_WORDS_PER_MESSAGE ;
413
+ let rem_u32s = n_u32s % CasmV2HashResourceEstimate :: U32_WORDS_PER_MESSAGE ;
421
414
if rem_u32s == 0 {
422
415
blake_estimation:: BASE_STEPS_FULL_MSG
423
416
} else {
@@ -461,7 +454,7 @@ fn estimate_steps_of_encode_felt252_data_and_calc_blake_hash(
461
454
fn count_blake_opcode ( felt_size_groups : & FeltSizeCount ) -> usize {
462
455
// Count the total number of u32s to be hashed.
463
456
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 )
457
+ total_u32s. div_ceil ( CasmV2HashResourceEstimate :: U32_WORDS_PER_MESSAGE )
465
458
}
466
459
467
460
/// Estimates resource usage for `encode_felt252_data_and_calc_blake_hash` in the Starknet OS.
0 commit comments