Skip to content

Commit 99986ea

Browse files
feat(blockifier): add fn encode_felt252_data_and_calc_blake_hash_cost
1 parent 3118bbb commit 99986ea

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

crates/blockifier/src/execution/execution_utils.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,24 @@ pub fn poseidon_hash_many_cost(data_length: usize) -> ExecutionResources {
363363
builtin_instance_counter: HashMap::from([(BuiltinName::poseidon, data_length / 2 + 1)]),
364364
}
365365
}
366+
367+
/// Estimates the VM resources required for running `encode_felt252_data_and_calc_blake_hash` in
368+
/// the Starknet OS.
369+
///
370+
/// This estimator currently assumes every felt252 unpacks into 8-u32 (not accounting for 2-u32
371+
/// optimization for small-felts).
372+
pub fn encode_felt252_data_and_calc_blake_hash_cost(data_length: usize) -> ExecutionResources {
373+
// Every 2 (large) felts complete a 16-u32s message that is passed to the blake hash.
374+
const STEPS_PER_TWO_FELTS: usize = 90;
375+
// Extra odd felt (8-u32s) is padded with zeros to complete a 16-u32s message.
376+
const STEPS_FOR_ODD_FELT: usize = 55;
377+
378+
let full_pairs = data_length / 2;
379+
let has_odd = data_length % 2;
380+
381+
ExecutionResources {
382+
n_steps: full_pairs * STEPS_PER_TWO_FELTS + has_odd * STEPS_FOR_ODD_FELT,
383+
n_memory_holes: 0,
384+
builtin_instance_counter: HashMap::from([(BuiltinName::range_check, data_length)]),
385+
}
386+
}

0 commit comments

Comments
 (0)