Skip to content

Commit

Permalink
default hasher is removed, need to be explicit (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagician authored Jun 19, 2024
1 parent 9ef1753 commit 6b19555
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 7 additions & 1 deletion crypto-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ark-snark = { version = "^0.4.0", default-features = false }
rayon = { version = "1.0", optional = true }
derivative = { version = "2.0", features = ["use_core"] }
tracing = { version = "0.1", default-features = false, features = [ "attributes" ], optional = true }
hashbrown = { version = "^0.14", default-features = false, optional = true }
hashbrown = { version = "0.14", default-features = false, features = ["inline-more", "allocator-api2"], optional = true }

[features]
default = ["std"]
Expand All @@ -50,6 +50,12 @@ prf = []
snark = []
signature = []

[target.'cfg(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr"))'.dependencies]
ahash = { version = "0.8", default-features = false}

[target.'cfg(not(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr")))'.dependencies]
fnv = { version = "1.0", default-features = false }

[dev-dependencies]
ark-ed-on-bls12-377 = { version = "^0.4.0", default-features = false }
ark-ed-on-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "r1cs" ] }
Expand Down
23 changes: 22 additions & 1 deletion crypto-primitives/src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(clippy::needless_range_loop)]

use core::hash::BuildHasherDefault;

/// Defines a trait to chain two types of CRHs.
use crate::crh::TwoToOneCRHScheme;
use crate::sponge::Absorb;
Expand All @@ -21,6 +23,24 @@ pub mod constraints;
#[cfg(feature = "parallel")]
use rayon::prelude::*;

#[cfg(all(
target_has_atomic = "8",
target_has_atomic = "16",
target_has_atomic = "32",
target_has_atomic = "64",
target_has_atomic = "ptr"
))]
type DefaultHasher = ahash::AHasher;

#[cfg(not(all(
target_has_atomic = "8",
target_has_atomic = "16",
target_has_atomic = "32",
target_has_atomic = "64",
target_has_atomic = "ptr"
)))]
type DefaultHasher = fnv::FnvHasher;

/// Convert the hash digest in different layers by converting previous layer's output to
/// `TargetType`, which is a `Borrow` to next layer's input.
pub trait DigestConverter<From, To: ?Sized> {
Expand Down Expand Up @@ -248,7 +268,8 @@ impl<P: Config> MultiPath<P> {
let mut leaves = leaves.into_iter();

// LookUp table to speedup computation avoid redundant hash computations
let mut hash_lut: HashMap<usize, P::InnerDigest> = HashMap::new();
let mut hash_lut: HashMap<usize, P::InnerDigest, _> =
HashMap::with_hasher(BuildHasherDefault::<DefaultHasher>::default());

// init prev path for decoding
let mut prev_path: Vec<_> = self.auth_paths_suffixes[0].clone();
Expand Down

0 comments on commit 6b19555

Please sign in to comment.