diff --git a/crypto-primitives/Cargo.toml b/crypto-primitives/Cargo.toml index 7b31c5e..a3c9bc5 100644 --- a/crypto-primitives/Cargo.toml +++ b/crypto-primitives/Cargo.toml @@ -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"] @@ -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" ] } diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 49627ea..5a7e493 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -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; @@ -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 { @@ -248,7 +268,8 @@ impl MultiPath

{ let mut leaves = leaves.into_iter(); // LookUp table to speedup computation avoid redundant hash computations - let mut hash_lut: HashMap = HashMap::new(); + let mut hash_lut: HashMap = + HashMap::with_hasher(BuildHasherDefault::::default()); // init prev path for decoding let mut prev_path: Vec<_> = self.auth_paths_suffixes[0].clone();