From e1f3d2311666a60746458534462b138c2e1b945d Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 6 Feb 2025 16:25:49 -0600 Subject: [PATCH] refactor: define hasher traits in nomt-core hasher module and feature-gate --- Cargo.lock | 1 + benchtop/Cargo.lock | 4 +- benchtop/src/nomt.rs | 4 +- core/Cargo.toml | 6 +- core/src/hasher.rs | 162 ++++++++++++++++++++++ core/src/lib.rs | 1 + core/src/proof/multi_proof.rs | 43 +----- core/src/proof/path_proof.rs | 3 +- core/src/trie.rs | 24 +--- core/src/update.rs | 3 +- examples/commit_batch/src/lib.rs | 4 +- examples/read_value/src/main.rs | 2 +- examples/witness_verification/src/main.rs | 44 +----- fuzz/fuzz_targets/api_surface.rs | 3 +- nomt/Cargo.toml | 5 +- nomt/src/lib.rs | 57 +------- nomt/src/merkle/page_walker.rs | 5 +- nomt/tests/common/mod.rs | 6 +- nomt/tests/compute_root.rs | 2 +- nomt/tests/exclusive_dir.rs | 2 +- nomt/tests/overlay.rs | 2 +- nomt/tests/prev_root_check.rs | 2 +- nomt/tests/rollback.rs | 4 +- nomt/tests/witness_check.rs | 2 +- torture/src/agent.rs | 2 +- 25 files changed, 217 insertions(+), 176 deletions(-) create mode 100644 core/src/hasher.rs diff --git a/Cargo.lock b/Cargo.lock index b567a1b8..7962184f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1088,6 +1088,7 @@ dependencies = [ "borsh", "hex", "ruint", + "sha2", ] [[package]] diff --git a/benchtop/Cargo.lock b/benchtop/Cargo.lock index d857bee9..e9f6237a 100644 --- a/benchtop/Cargo.lock +++ b/benchtop/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -2264,9 +2264,11 @@ version = "0.1.0" dependencies = [ "arrayvec", "bitvec", + "blake3", "borsh 1.4.0", "hex", "ruint", + "sha2 0.10.8", ] [[package]] diff --git a/benchtop/src/nomt.rs b/benchtop/src/nomt.rs index 1bf7df35..61a09cb2 100644 --- a/benchtop/src/nomt.rs +++ b/benchtop/src/nomt.rs @@ -1,8 +1,8 @@ use crate::{backend::Transaction, timer::Timer, workload::Workload}; use fxhash::FxHashMap; use nomt::{ - trie::KeyPath, Blake3Hasher, KeyReadWrite, Nomt, Options, Overlay, Session, SessionParams, - WitnessMode, + hasher::Blake3Hasher, trie::KeyPath, KeyReadWrite, Nomt, Options, Overlay, Session, + SessionParams, WitnessMode, }; use sha2::Digest; use std::{ diff --git a/core/Cargo.toml b/core/Cargo.toml index 0cce5144..7745b28d 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -16,11 +16,15 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc"] } ruint = { version = "1.12.1", default-features = false } arrayvec = { version = "0.7", default-features = false } borsh = { version = ">=1.4, <1.5.0", default-features = false, features = ["derive"], optional = true } +blake3 = { version = "1.5.1", default-features = false, optional = true } +sha2 = { version = "0.10.6" , default-features = false, optional = true } [dev-dependencies] blake3 = "1.5.1" [features] -default = ["std"] +default = ["std", "blake3-hasher", "sha2-hasher"] std = ["bitvec/std", "borsh/std"] borsh = ["dep:borsh"] +blake3-hasher = ["dep:blake3"] +sha2-hasher = ["dep:sha2"] diff --git a/core/src/hasher.rs b/core/src/hasher.rs new file mode 100644 index 00000000..8898cbff --- /dev/null +++ b/core/src/hasher.rs @@ -0,0 +1,162 @@ +//! Hashers (feature-gated) and utilities for implementing them. + +use crate::trie::{InternalData, LeafData, Node, NodeKind, TERMINATOR}; + +/// A trie node hash function specialized for 64 bytes of data. +/// +/// Note that it is illegal for the produced hash to equal [0; 32], as this value is reserved +/// for the terminator node. +/// +/// A node hasher should domain-separate internal and leaf nodes in some specific way. The +/// recommended approach for binary hashes is to set the MSB to 0 or 1 depending on the node kind. +/// However, for other kinds of hashes (e.g. Poseidon2 or other algebraic hashes), other labeling +/// schemes may be required. +pub trait NodeHasher { + /// Hash a leaf. This should domain-separate the hash + /// according to the node kind. + fn hash_leaf(data: &LeafData) -> [u8; 32]; + + /// Hash an internal node. This should domain-separate + /// the hash according to the node kind. + fn hash_internal(data: &InternalData) -> [u8; 32]; + + /// Get the kind of the given node. + fn node_kind(node: &Node) -> NodeKind; +} + +/// A hasher for arbitrary-length values. +pub trait ValueHasher { + /// Hash an arbitrary-length value. + fn hash_value(value: &[u8]) -> [u8; 32]; +} + +/// Get the node kind, according to a most-significant bit labeling scheme. +/// +/// If the MSB is true, it's a leaf. If the node is empty, it's a [`TERMINATOR`]. Otherwise, it's +/// an internal node. +pub fn node_kind_by_msb(node: &Node) -> NodeKind { + if node[0] >> 7 == 1 { + NodeKind::Leaf + } else if node == &TERMINATOR { + NodeKind::Terminator + } else { + NodeKind::Internal + } +} + +/// Set the most-significant bit of the node. +pub fn set_msb(node: &mut Node) { + node[0] |= 0b10000000; +} + +pub fn unset_msb(node: &mut Node) { + node[0] &= 0b01111111; +} + +/// A simple trait for representing binary hash functions. +pub trait BinaryHash { + /// Given a bit-string, produce a 32-bit hash. + fn hash(input: &[u8]) -> [u8; 32]; + + /// An optional specialization of `hash` where there are two 32-byte inputs, left and right. + fn hash2_32_concat(left: &[u8; 32], right: &[u8; 32]) -> [u8; 32] { + let mut buf = [0u8; 64]; + buf[0..32].copy_from_slice(left); + buf[32..64].copy_from_slice(right); + Self::hash(&buf) + } +} + +/// A node and value hasher constructed from a simple binary hasher. +/// +/// This implements a [`ValueHasher`] and [`NodeHasher`] where the node kind is tagged by setting +/// or unsetting the MSB of the hash value. +/// +/// The binary hash wrapped by this structure must behave approximately like a random oracle over +/// the space 2^256, i.e. all 256 bit outputs are valid and inputs are uniformly distributed. +/// +/// Functions like Sha2/Blake3/Keccak/Groestl all meet these criteria. +pub struct BinaryHasher(std::marker::PhantomData); + +impl ValueHasher for BinaryHasher { + fn hash_value(value: &[u8]) -> [u8; 32] { + H::hash(value) + } +} + +impl NodeHasher for BinaryHasher { + fn hash_leaf(data: &LeafData) -> [u8; 32] { + let mut h = H::hash2_32_concat(&data.key_path, &data.value_hash); + set_msb(&mut h); + h + } + + fn hash_internal(data: &InternalData) -> [u8; 32] { + let mut h = H::hash2_32_concat(&data.left, &data.right); + unset_msb(&mut h); + h + } + + fn node_kind(node: &Node) -> NodeKind { + node_kind_by_msb(node) + } +} + +#[cfg(any(feature = "blake3-hasher", test))] +pub use blake3::Blake3Hasher; + +/// A node hasher making use of blake3. +#[cfg(any(feature = "blake3-hasher", test))] +pub mod blake3 { + use super::{BinaryHash, BinaryHasher}; + + /// A [`BinaryHash`] implementation for Blake3. + pub struct Blake3BinaryHasher; + + /// A wrapper around Blake3 for use in NOMT. + pub type Blake3Hasher = BinaryHasher; + + impl BinaryHash for Blake3BinaryHasher { + fn hash(value: &[u8]) -> [u8; 32] { + blake3::hash(value).into() + } + + fn hash2_32_concat(left: &[u8; 32], right: &[u8; 32]) -> [u8; 32] { + let mut hasher = blake3::Hasher::new(); + hasher.update(left); + hasher.update(right); + hasher.finalize().into() + } + } +} + +#[cfg(feature = "sha2-hasher")] +pub use sha2::Sha2Hasher; + +/// A node and value hasher making use of sha2-256. +#[cfg(feature = "sha2-hasher")] +pub mod sha2 { + use super::{BinaryHash, BinaryHasher}; + use sha2::{Digest, Sha256}; + + /// A [`BinaryHash`] implementation for Sha2. + pub struct Sha2BinaryHasher; + + /// A wrapper around sha2-256 for use in NOMT. + pub type Sha2Hasher = BinaryHasher; + + impl BinaryHash for Sha2BinaryHasher { + fn hash(value: &[u8]) -> [u8; 32] { + let mut hasher = Sha256::new(); + hasher.update(value); + hasher.finalize().into() + } + + fn hash2_32_concat(left: &[u8; 32], right: &[u8; 32]) -> [u8; 32] { + let mut hasher = Sha256::new(); + hasher.update(left); + hasher.update(right); + hasher.finalize().into() + } + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs index 86b566e9..6d6b6c31 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -10,6 +10,7 @@ extern crate alloc; +pub mod hasher; pub mod page; pub mod page_id; pub mod proof; diff --git a/core/src/proof/multi_proof.rs b/core/src/proof/multi_proof.rs index c6a51c4a..621b2a10 100644 --- a/core/src/proof/multi_proof.rs +++ b/core/src/proof/multi_proof.rs @@ -3,11 +3,12 @@ //! the inclusion of all provided path proofs. use crate::{ + hasher::NodeHasher, proof::{ path_proof::{hash_path, shared_bits}, KeyOutOfScope, PathProof, PathProofTerminal, }, - trie::{InternalData, KeyPath, LeafData, Node, NodeHasher, TERMINATOR}, + trie::{InternalData, KeyPath, LeafData, Node, TERMINATOR}, }; #[cfg(not(feature = "std"))] @@ -497,8 +498,9 @@ mod tests { use super::{verify, MultiProof}; use crate::{ + hasher::{Blake3Hasher, NodeHasher}, proof::{PathProof, PathProofTerminal}, - trie::{self, InternalData, LeafData, Node, NodeHasher, NodeKind, TERMINATOR}, + trie::{InternalData, LeafData, TERMINATOR}, trie_pos::TriePosition, }; @@ -884,43 +886,6 @@ mod tests { ); } - /// Hash nodes with blake3. - pub struct Blake3Hasher; - - impl NodeHasher for Blake3Hasher { - fn hash_leaf(data: &trie::LeafData) -> [u8; 32] { - let mut hasher = blake3::Hasher::new(); - hasher.update(&data.key_path); - hasher.update(&data.value_hash); - let mut hash: [u8; 32] = hasher.finalize().into(); - - // Label with MSB - hash[0] |= 0b10000000; - hash - } - - fn hash_internal(data: &trie::InternalData) -> [u8; 32] { - let mut hasher = blake3::Hasher::new(); - hasher.update(&data.left); - hasher.update(&data.right); - let mut hash: [u8; 32] = hasher.finalize().into(); - - // Label with MSB - hash[0] &= 0b01111111; - hash - } - - fn node_kind(node: &Node) -> NodeKind { - if node[0] >> 7 == 1 { - NodeKind::Leaf - } else if node == &TERMINATOR { - NodeKind::Terminator - } else { - NodeKind::Internal - } - } - } - #[test] pub fn test_verify_multiproof_two_leafs() { // root diff --git a/core/src/proof/path_proof.rs b/core/src/proof/path_proof.rs index 78ad0f4d..6a73e2c1 100644 --- a/core/src/proof/path_proof.rs +++ b/core/src/proof/path_proof.rs @@ -1,6 +1,7 @@ //! Proving and verifying inclusion, non-inclusion, and updates to the trie. -use crate::trie::{self, InternalData, KeyPath, LeafData, Node, NodeHasher, NodeKind, TERMINATOR}; +use crate::hasher::NodeHasher; +use crate::trie::{self, InternalData, KeyPath, LeafData, Node, NodeKind, TERMINATOR}; use crate::trie_pos::TriePosition; use bitvec::prelude::*; diff --git a/core/src/trie.rs b/core/src/trie.rs index c89de806..5d4fb775 100644 --- a/core/src/trie.rs +++ b/core/src/trie.rs @@ -13,6 +13,8 @@ //! //! All node preimages are 512 bits. +use crate::hasher::NodeHasher; + /// A node in the binary trie. In this schema, it is always 256 bits and is the hash of either /// an [`LeafData`] or [`InternalData`], or zeroed if it's a [`TERMINATOR`]. /// @@ -90,25 +92,3 @@ pub struct LeafData { /// The hash of the value carried in this leaf. pub value_hash: ValueHash, } - -/// A trie node hash function specialized for 64 bytes of data. -/// -/// Note that it is illegal for the produced hash to equal [0; 32], as this value is reserved -/// for the terminator node. -/// -/// A node hasher should domain-separate internal and leaf nodes in some specific way. The -/// recommended approach for binary hashes is to set the MSB to 0 or 1 depending on the node kind. -/// However, for other kinds of hashes (e.g. Poseidon2 or other algebraic hashes), other labeling -/// schemes may be required. -pub trait NodeHasher { - /// Hash a leaf. This should domain-separate the hash - /// according to the node kind. - fn hash_leaf(data: &LeafData) -> [u8; 32]; - - /// Hash an internal node. This should domain-separate - /// the hash according to the node kind. - fn hash_internal(data: &InternalData) -> [u8; 32]; - - /// Get the kind of the given node. - fn node_kind(node: &Node) -> NodeKind; -} diff --git a/core/src/update.rs b/core/src/update.rs index 4d8a6f43..4338bc65 100644 --- a/core/src/update.rs +++ b/core/src/update.rs @@ -1,6 +1,7 @@ //! Trie update logic helpers. -use crate::trie::{self, KeyPath, LeafData, Node, NodeHasher, ValueHash}; +use crate::hasher::NodeHasher; +use crate::trie::{self, KeyPath, LeafData, Node, ValueHash}; use bitvec::prelude::*; diff --git a/examples/commit_batch/src/lib.rs b/examples/commit_batch/src/lib.rs index 4c0b99a7..8a492ba4 100644 --- a/examples/commit_batch/src/lib.rs +++ b/examples/commit_batch/src/lib.rs @@ -1,5 +1,7 @@ use anyhow::Result; -use nomt::{Blake3Hasher, KeyReadWrite, Nomt, Options, Root, SessionParams, Witness, WitnessMode}; +use nomt::{ + hasher::Blake3Hasher, KeyReadWrite, Nomt, Options, Root, SessionParams, Witness, WitnessMode, +}; use sha2::Digest; const NOMT_DB_FOLDER: &str = "nomt_db"; diff --git a/examples/read_value/src/main.rs b/examples/read_value/src/main.rs index 102e5bd2..7b49b593 100644 --- a/examples/read_value/src/main.rs +++ b/examples/read_value/src/main.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use nomt::{Blake3Hasher, KeyReadWrite, Nomt, Options, SessionParams, WitnessMode}; +use nomt::{hasher::Blake3Hasher, KeyReadWrite, Nomt, Options, SessionParams, WitnessMode}; use sha2::Digest; const NOMT_DB_FOLDER: &str = "nomt_db"; diff --git a/examples/witness_verification/src/main.rs b/examples/witness_verification/src/main.rs index f8bd3b8d..cd02bca7 100644 --- a/examples/witness_verification/src/main.rs +++ b/examples/witness_verification/src/main.rs @@ -1,47 +1,5 @@ use anyhow::Result; -use nomt_core::{ - proof, - trie::{self, LeafData, Node, NodeHasher, NodeKind, TERMINATOR}, -}; - -// Hash nodes using blake3. The Hasher below will be utilized in the witness -// verification stage and must conform to the hash used in the commitment -// phase and subsequently during witness creation -pub struct Blake3Hasher; - -impl NodeHasher for Blake3Hasher { - fn hash_leaf(data: &trie::LeafData) -> [u8; 32] { - let mut hasher = blake3::Hasher::new(); - hasher.update(&data.key_path); - hasher.update(&data.value_hash); - let mut hash: [u8; 32] = hasher.finalize().into(); - - // Label with MSB - hash[0] |= 0b10000000; - hash - } - - fn hash_internal(data: &trie::InternalData) -> [u8; 32] { - let mut hasher = blake3::Hasher::new(); - hasher.update(&data.left); - hasher.update(&data.right); - let mut hash: [u8; 32] = hasher.finalize().into(); - - // Label with MSB - hash[0] &= 0b01111111; - hash - } - - fn node_kind(node: &Node) -> NodeKind { - if node[0] >> 7 == 1 { - NodeKind::Leaf - } else if node == &TERMINATOR { - NodeKind::Terminator - } else { - NodeKind::Internal - } - } -} +use nomt_core::{hasher::Blake3Hasher, proof, trie::LeafData}; fn main() -> Result<()> { // The witness produced in the example `commit_batch` will be used diff --git a/fuzz/fuzz_targets/api_surface.rs b/fuzz/fuzz_targets/api_surface.rs index ef9950a8..e2682cba 100644 --- a/fuzz/fuzz_targets/api_surface.rs +++ b/fuzz/fuzz_targets/api_surface.rs @@ -6,7 +6,8 @@ use arbitrary::Arbitrary; use libfuzzer_sys::fuzz_target; use nomt::{ - trie::KeyPath, Blake3Hasher, KeyReadWrite, Nomt, Options, SessionParams, Value, WitnessMode, + hasher::Blake3Hasher, trie::KeyPath, KeyReadWrite, Nomt, Options, SessionParams, Value, + WitnessMode, }; fuzz_target!(|run: Run| { diff --git a/nomt/Cargo.toml b/nomt/Cargo.toml index 0b17578d..dbc8a879 100644 --- a/nomt/Cargo.toml +++ b/nomt/Cargo.toml @@ -12,7 +12,7 @@ license.workspace = true [dependencies] anyhow = { version = "1.0.81", features = ["backtrace"] } -nomt-core = { path = "../core", features = ["std"] } +nomt-core = { path = "../core", default-features = false, features = ["std"] } parking_lot = { version = "0.12.3", features = ["arc_lock", "send_guard"] } threadpool = "1.8.1" bitvec = { version = "1" } @@ -55,6 +55,9 @@ name = "beatree" harness = false [features] +default = ["blake3-hasher", "sha2-hasher"] benchmarks = ["dep:criterion"] fuzz = [] borsh = ["dep:borsh", "nomt-core/borsh"] +blake3-hasher = ["nomt-core/blake3-hasher"] +sha2-hasher = ["nomt-core/sha2-hasher"] diff --git a/nomt/src/lib.rs b/nomt/src/lib.rs index 757c940d..e9ef1673 100644 --- a/nomt/src/lib.rs +++ b/nomt/src/lib.rs @@ -9,9 +9,10 @@ use std::{mem, sync::Arc}; use merkle::{UpdatePool, Updater}; use nomt_core::{ + hasher::{NodeHasher, ValueHasher}, page_id::ROOT_PAGE_ID, proof::PathProof, - trie::{InternalData, KeyPath, LeafData, Node, NodeHasher, NodeKind, ValueHash, TERMINATOR}, + trie::{InternalData, KeyPath, LeafData, Node, ValueHash, TERMINATOR}, trie_pos::TriePosition, }; use overlay::{LiveOverlay, OverlayMarker}; @@ -21,6 +22,7 @@ use store::{Store, ValueTransaction}; // CARGO HACK: silence lint; this is used in integration tests +pub use nomt_core::hasher; pub use nomt_core::proof; pub use nomt_core::trie; pub use options::{Options, PanicOnSyncMode}; @@ -767,56 +769,11 @@ impl Overlay { } } -/// A hasher for arbitrary-length values. -pub trait ValueHasher { - /// Hash an arbitrary-length value. - fn hash_value(value: &[u8]) -> [u8; 32]; -} - -/// A hash algorithm that uses Blake3 for both nodes and values. -pub struct Blake3Hasher; - -impl NodeHasher for Blake3Hasher { - fn hash_leaf(data: &trie::LeafData) -> [u8; 32] { - let mut hasher = blake3::Hasher::new(); - hasher.update(&data.key_path); - hasher.update(&data.value_hash); - let mut hash: [u8; 32] = hasher.finalize().into(); - - // Label with MSB - hash[0] |= 0b10000000; - hash - } - - fn hash_internal(data: &trie::InternalData) -> [u8; 32] { - let mut hasher = blake3::Hasher::new(); - hasher.update(&data.left); - hasher.update(&data.right); - let mut hash: [u8; 32] = hasher.finalize().into(); - - // Label with MSB - hash[0] &= 0b01111111; - hash - } - - fn node_kind(node: &Node) -> NodeKind { - if node[0] >> 7 == 1 { - NodeKind::Leaf - } else if node == &TERMINATOR { - NodeKind::Terminator - } else { - NodeKind::Internal - } - } -} -impl ValueHasher for Blake3Hasher { - fn hash_value(data: &[u8]) -> [u8; 32] { - blake3::hash(data).into() - } -} - /// A marker trait for hash functions usable with NOMT. The type must support both hashing nodes as /// well as values. +/// +/// This is automatically implemented for types implementing +/// both [`NodeHasher`] and [`ValueHasher`]. pub trait HashAlgorithm: ValueHasher + NodeHasher {} impl HashAlgorithm for T {} @@ -885,7 +842,7 @@ fn compute_root_node(page_cache: &PageCache, store: &Store) -> #[cfg(test)] mod tests { - use crate::Blake3Hasher; + use crate::hasher::Blake3Hasher; #[test] fn session_is_sync() { diff --git a/nomt/src/merkle/page_walker.rs b/nomt/src/merkle/page_walker.rs index 6c549501..5db15fdd 100644 --- a/nomt/src/merkle/page_walker.rs +++ b/nomt/src/merkle/page_walker.rs @@ -44,9 +44,10 @@ use bitvec::prelude::*; use nomt_core::{ + hasher::NodeHasher, page::DEPTH, page_id::{PageId, ROOT_PAGE_ID}, - trie::{self, KeyPath, Node, NodeHasher, NodeKind, ValueHash, TERMINATOR}, + trie::{self, KeyPath, Node, NodeKind, ValueHash, TERMINATOR}, trie_pos::TriePosition, update::WriteNode, }; @@ -606,10 +607,10 @@ mod tests { ROOT_PAGE_ID, }; use crate::{ + hasher::Blake3Hasher, io::PagePool, page_cache::{Page, PageMut}, page_diff::PageDiff, - Blake3Hasher, }; use bitvec::prelude::*; use imbl::HashMap; diff --git a/nomt/tests/common/mod.rs b/nomt/tests/common/mod.rs index b595a042..8ebe7c76 100644 --- a/nomt/tests/common/mod.rs +++ b/nomt/tests/common/mod.rs @@ -30,7 +30,7 @@ pub fn expected_root(accounts: u64) -> Node { .map(|a| (a, *blake3::hash(&1000u64.to_le_bytes()).as_bytes())) .collect::>(); ops.sort_unstable_by_key(|(a, _)| *a); - nomt_core::update::build_trie::(0, ops, |_| {}) + nomt_core::update::build_trie::(0, ops, |_| {}) } fn opts(path: PathBuf) -> Options { @@ -41,8 +41,8 @@ fn opts(path: PathBuf) -> Options { } pub struct Test { - nomt: Nomt, - session: Option>, + nomt: Nomt, + session: Option>, access: HashMap, } diff --git a/nomt/tests/compute_root.rs b/nomt/tests/compute_root.rs index ab005910..db24e51a 100644 --- a/nomt/tests/compute_root.rs +++ b/nomt/tests/compute_root.rs @@ -1,7 +1,7 @@ mod common; use common::Test; -use nomt::{trie::NodeKind, Blake3Hasher}; +use nomt::{hasher::Blake3Hasher, trie::NodeKind}; #[test] fn root_on_empty_db() { diff --git a/nomt/tests/exclusive_dir.rs b/nomt/tests/exclusive_dir.rs index feebe75e..d0350c73 100644 --- a/nomt/tests/exclusive_dir.rs +++ b/nomt/tests/exclusive_dir.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; -use nomt::{Blake3Hasher, Nomt, Options}; +use nomt::{hasher::Blake3Hasher, Nomt, Options}; fn setup_nomt(path: &str, should_clean_up: bool) -> anyhow::Result> { let path = { diff --git a/nomt/tests/overlay.rs b/nomt/tests/overlay.rs index 7ebc4e95..3603e294 100644 --- a/nomt/tests/overlay.rs +++ b/nomt/tests/overlay.rs @@ -3,7 +3,7 @@ mod common; use common::Test; fn expected_root(items: Vec<([u8; 32], Vec)>) -> nomt_core::trie::Node { - nomt_core::update::build_trie::( + nomt_core::update::build_trie::( 0, items .into_iter() diff --git a/nomt/tests/prev_root_check.rs b/nomt/tests/prev_root_check.rs index decc31db..7468aa0f 100644 --- a/nomt/tests/prev_root_check.rs +++ b/nomt/tests/prev_root_check.rs @@ -1,4 +1,4 @@ -use nomt::{Blake3Hasher, KeyReadWrite, Nomt, Options, SessionParams}; +use nomt::{hasher::Blake3Hasher, KeyReadWrite, Nomt, Options, SessionParams}; use std::path::PathBuf; /// Setup a NOMT with the given path, rollback enabled, and the given commit concurrency. diff --git a/nomt/tests/rollback.rs b/nomt/tests/rollback.rs index b2742b2a..227bcf57 100644 --- a/nomt/tests/rollback.rs +++ b/nomt/tests/rollback.rs @@ -1,5 +1,7 @@ use hex_literal::hex; -use nomt::{trie::KeyPath, Blake3Hasher, KeyReadWrite, Nomt, Options, SessionParams, Value}; +use nomt::{ + hasher::Blake3Hasher, trie::KeyPath, KeyReadWrite, Nomt, Options, SessionParams, Value, +}; use std::{ collections::{BTreeMap, BTreeSet}, path::PathBuf, diff --git a/nomt/tests/witness_check.rs b/nomt/tests/witness_check.rs index 38a6d000..73b23b66 100644 --- a/nomt/tests/witness_check.rs +++ b/nomt/tests/witness_check.rs @@ -1,7 +1,7 @@ mod common; use common::Test; -use nomt::{proof, trie::LeafData, Blake3Hasher}; +use nomt::{hasher::Blake3Hasher, proof, trie::LeafData}; #[test] fn produced_witness_validity() { diff --git a/torture/src/agent.rs b/torture/src/agent.rs index a1d51c52..4d6010ed 100644 --- a/torture/src/agent.rs +++ b/torture/src/agent.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, bail, Result}; use futures::SinkExt as _; -use nomt::{Blake3Hasher, Nomt, SessionParams}; +use nomt::{hasher::Blake3Hasher, Nomt, SessionParams}; use std::future::Future; use std::path::Path; use std::{path::PathBuf, sync::Arc, time::Duration};