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