@@ -14,7 +14,7 @@ use crate::execution::contract_class::{
14
14
FeltSizeCount ,
15
15
NestedFeltCounts ,
16
16
} ;
17
- use crate :: execution:: execution_utils:: { encode_and_blake_hash_resources , poseidon_hash_many_cost} ;
17
+ use crate :: execution:: execution_utils:: poseidon_hash_many_cost;
18
18
use crate :: utils:: u64_from_usize;
19
19
20
20
#[ cfg( test) ]
@@ -149,7 +149,7 @@ impl From<(ExecutionResources, HashVersion)> for EstimatedExecutionResources {
149
149
/// This provides resource estimates rather than exact values.
150
150
// TODO(AvivG): Remove allow once used.
151
151
#[ allow( unused) ]
152
- trait EstimateCasmHashResources {
152
+ pub trait EstimateCasmHashResources {
153
153
/// Specifies the hash function variant that the estimate is for.
154
154
fn hash_version ( & self ) -> HashVersion ;
155
155
@@ -192,17 +192,44 @@ impl EstimateCasmHashResources for CasmV1HashResourceEstimate {
192
192
193
193
// TODO(AvivG): Remove allow once used.
194
194
#[ allow( unused) ]
195
- struct CasmV2HashResourceEstimate { }
195
+ pub struct CasmV2HashResourceEstimate { }
196
196
197
197
impl EstimateCasmHashResources for CasmV2HashResourceEstimate {
198
198
fn hash_version ( & self ) -> HashVersion {
199
199
HashVersion :: V2
200
200
}
201
201
202
+ /// Estimates resource usage for `encode_felt252_data_and_calc_blake_hash` in the Starknet OS.
203
+ ///
204
+ /// # Encoding Details
205
+ /// - Small felts → 2 `u32`s each; Big felts → 8 `u32`s each.
206
+ /// - Each felt requires one `range_check` operation.
207
+ ///
208
+ /// # Returns:
209
+ /// - `ExecutionResources`: VM resource usage (e.g., n_steps, range checks).
210
+ /// - `usize`: number of Blake opcodes used, accounted for separately as those are not reported
211
+ /// via `ExecutionResources`.
202
212
fn estimated_resources_of_hash_function (
203
213
felt_size_groups : & FeltSizeCount ,
204
214
) -> EstimatedExecutionResources {
205
- encode_and_blake_hash_resources ( felt_size_groups)
215
+ let n_steps = estimate_steps_of_encode_felt252_data_and_calc_blake_hash ( felt_size_groups) ;
216
+ let builtin_instance_counter = match felt_size_groups. n_felts ( ) {
217
+ // The empty case does not use builtins at all.
218
+ 0 => HashMap :: new ( ) ,
219
+ // One `range_check` per input felt to validate its size + Overhead for the non empty
220
+ // case.
221
+ _ => HashMap :: from ( [ (
222
+ BuiltinName :: range_check,
223
+ felt_size_groups. n_felts ( ) + blake_estimation:: BASE_RANGE_CHECK_NON_EMPTY ,
224
+ ) ] ) ,
225
+ } ;
226
+
227
+ let resources = ExecutionResources { n_steps, n_memory_holes : 0 , builtin_instance_counter } ;
228
+
229
+ EstimatedExecutionResources :: V2Hash {
230
+ resources,
231
+ blake_count : felt_size_groups. blake_opcode_count ( ) ,
232
+ }
206
233
}
207
234
}
208
235
@@ -267,38 +294,6 @@ fn estimate_steps_of_encode_felt252_data_and_calc_blake_hash(
267
294
base_steps. checked_add ( felt_steps) . expect ( "Overflow computing total Blake hash steps" )
268
295
}
269
296
270
- /// Estimates resource usage for `encode_felt252_data_and_calc_blake_hash` in the Starknet OS.
271
- ///
272
- /// # Encoding Details
273
- /// - Small felts → 2 `u32`s each; Big felts → 8 `u32`s each.
274
- /// - Each felt requires one `range_check` operation.
275
- ///
276
- /// # Returns:
277
- /// - `ExecutionResources`: VM resource usage (e.g., n_steps, range checks).
278
- /// - `usize`: number of Blake opcodes used, accounted for separately as those are not reported via
279
- /// `ExecutionResources`.
280
- pub fn encode_and_blake_hash_resources (
281
- felt_size_groups : & FeltSizeCount ,
282
- ) -> EstimatedExecutionResources {
283
- let n_steps = estimate_steps_of_encode_felt252_data_and_calc_blake_hash ( felt_size_groups) ;
284
- let builtin_instance_counter = match felt_size_groups. n_felts ( ) {
285
- // The empty case does not use builtins at all.
286
- 0 => HashMap :: new ( ) ,
287
- // One `range_check` per input felt to validate its size + Overhead for the non empty case.
288
- _ => HashMap :: from ( [ (
289
- BuiltinName :: range_check,
290
- felt_size_groups. n_felts ( ) + blake_estimation:: BASE_RANGE_CHECK_NON_EMPTY ,
291
- ) ] ) ,
292
- } ;
293
-
294
- let resources = ExecutionResources { n_steps, n_memory_holes : 0 , builtin_instance_counter } ;
295
-
296
- EstimatedExecutionResources :: V2Hash {
297
- resources,
298
- blake_count : felt_size_groups. blake_opcode_count ( ) ,
299
- }
300
- }
301
-
302
297
/// Converts the execution resources and blake opcode count to L2 gas.
303
298
///
304
299
/// Used for both Stwo ("proving_gas") and Stone ("sierra_gas") estimations, which differ in
0 commit comments