Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Added validation to `PartialMerkleTree::with_leaves()` to reject internal nodes ([#684](https://github.com/0xMiden/crypto/pull/684)).
- [BREAKING] Moved `LargeSmt` root ownership from storage to in-memory layer ([#694](https://github.com/0xMiden/crypto/pull/694)).
- Remove use of `transmute()` in blake3 implementation ([#704](https://github.com/0xMiden/crypto/pull/704)).
- [BREAKING] Removed the direct `hashbrown` dependency and made the `hashmaps` feature use `std::collections::{HashMap, HashSet}` ([#696](https://github.com/0xMiden/crypto/issues/696)).

## 0.19.2 (2025-12-04)

Expand Down
21 changes: 0 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ This crate can be compiled with the following features:
- `concurrent`- enabled by default; enables multi-threaded implementation of `Smt::with_entries()` which significantly improves performance on multi-core CPUs.
- `std` - enabled by default and relies on the Rust standard library.
- `no_std` does not rely on the Rust standard library and enables compilation to WebAssembly.
- `hashmaps` - uses hashbrown hashmaps in SMT and Merkle Store implementation which significantly improves performance of updates. Keys ordering in iterators is not guaranteed when this feature is enabled.
- `hashmaps` - uses standard library hash maps in SMT and Merkle Store implementation which significantly improves performance of updates (requires the `std` feature). Keys ordering in iterators is not guaranteed when this feature is enabled.
- `rocksdb` - enables the RocksDB-backed storage for `LargeSmt` and related utilities. Implies `concurrent`.
All of these features imply the use of [alloc](https://doc.rust-lang.org/alloc/) to support heap-allocated collections.

Expand Down
1 change: 0 additions & 1 deletion miden-crypto-fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions miden-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ harness = false
name = "rand"

[features]
concurrent = ["dep:rayon", "hashbrown?/rayon"]
concurrent = ["dep:rayon"]
default = ["concurrent", "std"]
executable = ["dep:clap", "dep:rand-utils", "std"]
fuzzing = []
hashmaps = ["dep:hashbrown"]
hashmaps = ["std"]
internal = []
rocksdb = ["concurrent", "dep:rocksdb"]
serde = ["dep:serde", "serde?/alloc", "winter-math/serde"]
Expand All @@ -87,7 +87,6 @@ clap = { features = ["derive"], optional = true, versio
curve25519-dalek = { default-features = false, version = "4" }
ed25519-dalek = { features = ["zeroize"], version = "2" }
flume = { version = "0.11" }
hashbrown = { features = ["serde"], optional = true, version = "0.16" }
hkdf = { default-features = false, version = "0.12" }
k256 = { features = ["ecdh", "ecdsa"], version = "0.13" }
miden-crypto-derive.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion miden-crypto/benches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ For each algorithm, we benchmark three core operations:

### Sparse Merkle Tree

We build cryptographic data structures incorporating these hash functions. What follows are benchmarks of operations on sparse Merkle trees (SMTs) which use the above `RPO_256` hash function. We perform a batched modification of 1,000 values in a tree with 1,000,000 leaves (with the `hashmaps` feature to use the `hashbrown` crate).
We build cryptographic data structures incorporating these hash functions. What follows are benchmarks of operations on sparse Merkle trees (SMTs) which use the above `RPO_256` hash function. We perform a batched modification of 1,000 values in a tree with 1,000,000 leaves (with the `hashmaps` feature enabled to leverage the standard library `HashMap`).

### Scenario 1: SMT Construction (1M pairs)

Expand Down
29 changes: 16 additions & 13 deletions miden-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

#[cfg(all(feature = "hashmaps", not(feature = "std")))]
compile_error!("`hashmaps` feature requires `std` to provide HashMap/HashSet support");

pub mod aead;
pub mod dsa;
pub mod ecdh;
Expand All @@ -31,35 +34,35 @@ pub use word::{Word, WordError};
/// An alias for a key-value map.
///
/// By default, this is an alias for the [`alloc::collections::BTreeMap`], however, when the
/// `hashmaps` feature is enabled, this is an alias for the `hashbrown`'s `HashMap`.
#[cfg(feature = "hashmaps")]
pub type Map<K, V> = hashbrown::HashMap<K, V>;
/// `hashmaps` feature is enabled, this is an alias for the `std::collections::HashMap`.
#[cfg(all(feature = "hashmaps", feature = "std"))]
pub type Map<K, V> = std::collections::HashMap<K, V>;

#[cfg(feature = "hashmaps")]
pub use hashbrown::hash_map::Entry as MapEntry;
#[cfg(all(feature = "hashmaps", feature = "std"))]
pub use std::collections::hash_map::Entry as MapEntry;

/// An alias for a key-value map.
///
/// By default, this is an alias for the [`alloc::collections::BTreeMap`], however, when the
/// `hashmaps` feature is enabled, this is an alias for the `hashbrown`'s `HashMap`.
#[cfg(not(feature = "hashmaps"))]
/// `hashmaps` feature is enabled, this is an alias for the `std::collections::HashMap`.
#[cfg(not(all(feature = "hashmaps", feature = "std")))]
pub type Map<K, V> = alloc::collections::BTreeMap<K, V>;

#[cfg(not(feature = "hashmaps"))]
#[cfg(not(all(feature = "hashmaps", feature = "std")))]
pub use alloc::collections::btree_map::Entry as MapEntry;

/// An alias for a simple set.
///
/// By default, this is an alias for the [`alloc::collections::BTreeSet`]. However, when the
/// `hashmaps` feature is enabled, this becomes an alias for hashbrown's HashSet.
#[cfg(feature = "hashmaps")]
pub type Set<V> = hashbrown::HashSet<V>;
/// `hashmaps` feature is enabled, this becomes an alias for `std::collections::HashSet`.
#[cfg(all(feature = "hashmaps", feature = "std"))]
pub type Set<V> = std::collections::HashSet<V>;

/// An alias for a simple set.
///
/// By default, this is an alias for the [`alloc::collections::BTreeSet`]. However, when the
/// `hashmaps` feature is enabled, this becomes an alias for hashbrown's HashSet.
#[cfg(not(feature = "hashmaps"))]
/// `hashmaps` feature is enabled, this becomes an alias for `std::collections::HashSet`.
#[cfg(not(all(feature = "hashmaps", feature = "std")))]
pub type Set<V> = alloc::collections::BTreeSet<V>;

// CONSTANTS
Expand Down
4 changes: 2 additions & 2 deletions miden-crypto/src/merkle/smt/forest/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ impl SmtStore {
#[allow(unused_mut)]
let mut sorted_leaf_indices = leaves_by_index.keys().cloned().collect::<Vec<_>>();

#[cfg(feature = "hashmaps")]
#[cfg(all(feature = "hashmaps", feature = "std"))]
// Sort leaves by NodeIndex to easily detect when leaves share a parent (only neighboring
// leaves can share a parent). Hashbrown::HashMap doesn't maintain key ordering, so
// leaves can share a parent). `std::collections::HashMap` doesn't maintain key ordering, so
// we need to sort the indices.
sorted_leaf_indices.sort();

Expand Down
Loading