Skip to content

Commit

Permalink
perf: use SmallVec in compute_function_id
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Jun 6, 2024
1 parent 94c709e commit 54189aa
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions console/program/src/function_id/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@ use snarkvm_console_algorithms::Result;
use snarkvm_console_network::Network;
use snarkvm_console_types::{Field, U16, U8};

use smallvec::SmallVec;

/// Compute the function ID as `Hash(network_id, program_id.len(), program_id, function_name.len(), function_name)`.
pub fn compute_function_id<N: Network>(
network_id: &U16<N>,
program_id: &ProgramID<N>,
function_name: &Identifier<N>,
) -> Result<Field<N>> {
N::hash_bhp1024(
&(
*network_id,
U8::<N>::new(program_id.name().size_in_bits()),
program_id.name(),
U8::<N>::new(program_id.network().size_in_bits()),
program_id.network(),
U8::<N>::new(function_name.size_in_bits()),
function_name,
)
.to_bits_le(),
let mut preimage: SmallVec<[bool; 256]> = SmallVec::new();
(
*network_id,
U8::<N>::new(program_id.name().size_in_bits()),
program_id.name(),
U8::<N>::new(program_id.network().size_in_bits()),
program_id.network(),
U8::<N>::new(function_name.size_in_bits()),
function_name,
)
.write_bits_le(&mut preimage);

N::hash_bhp1024(&preimage)
}

0 comments on commit 54189aa

Please sign in to comment.