@@ -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
@@ -190,19 +190,44 @@ impl EstimateCasmHashResources for CasmV1HashResourceEstimate {
190
190
}
191
191
}
192
192
193
- // TODO(AvivG): Remove allow once used.
194
- #[ allow( unused) ]
195
- struct CasmV2HashResourceEstimate { }
193
+ pub struct CasmV2HashResourceEstimate { }
196
194
197
195
impl EstimateCasmHashResources for CasmV2HashResourceEstimate {
198
196
fn hash_version ( & self ) -> HashVersion {
199
197
HashVersion :: V2
200
198
}
201
199
200
+ /// Estimates resource usage for `encode_felt252_data_and_calc_blake_hash` in the Starknet OS.
201
+ ///
202
+ /// # Encoding Details
203
+ /// - Small felts → 2 `u32`s each; Big felts → 8 `u32`s each.
204
+ /// - Each felt requires one `range_check` operation.
205
+ ///
206
+ /// # Returns:
207
+ /// - `ExecutionResources`: VM resource usage (e.g., n_steps, range checks).
208
+ /// - `usize`: number of Blake opcodes used, accounted for separately as those are not reported
209
+ /// via `ExecutionResources`.
202
210
fn estimated_resources_of_hash_function (
203
211
felt_size_groups : & FeltSizeCount ,
204
212
) -> EstimatedExecutionResources {
205
- encode_and_blake_hash_resources ( felt_size_groups)
213
+ let n_steps = estimate_steps_of_encode_felt252_data_and_calc_blake_hash ( felt_size_groups) ;
214
+ let builtin_instance_counter = match felt_size_groups. n_felts ( ) {
215
+ // The empty case does not use builtins at all.
216
+ 0 => HashMap :: new ( ) ,
217
+ // One `range_check` per input felt to validate its size + Overhead for the non empty
218
+ // case.
219
+ _ => HashMap :: from ( [ (
220
+ BuiltinName :: range_check,
221
+ felt_size_groups. n_felts ( ) + blake_estimation:: BASE_RANGE_CHECK_NON_EMPTY ,
222
+ ) ] ) ,
223
+ } ;
224
+
225
+ let resources = ExecutionResources { n_steps, n_memory_holes : 0 , builtin_instance_counter } ;
226
+
227
+ EstimatedExecutionResources :: V2Hash {
228
+ resources,
229
+ blake_count : felt_size_groups. blake_opcode_count ( ) ,
230
+ }
206
231
}
207
232
}
208
233
@@ -267,38 +292,6 @@ fn estimate_steps_of_encode_felt252_data_and_calc_blake_hash(
267
292
base_steps. checked_add ( felt_steps) . expect ( "Overflow computing total Blake hash steps" )
268
293
}
269
294
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
295
/// Converts the execution resources and blake opcode count to L2 gas.
303
296
///
304
297
/// Used for both Stwo ("proving_gas") and Stone ("sierra_gas") estimations, which differ in
0 commit comments