Skip to content

Commit

Permalink
fix(merkle): update tests and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfertel committed Apr 29, 2024
1 parent aa8f192 commit 8fc8f1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
4 changes: 3 additions & 1 deletion lib/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ license.workspace = true
repository.workspace = true
version = "0.1.0"

[dev-dependencies]
[dependencies]
tiny-keccak = { version = "2.0.2", features = ["keccak"] }

[dev-dependencies]
const-hex = { version = "1.11.1", default-features = false }
rand = "0.8.5"

Expand Down
8 changes: 6 additions & 2 deletions lib/crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ pub trait Hasher {
///
/// # Examples
///
/// ```
/// TODO: FIX EXAMPLE
///
/// ```ignore
/// use core::hash::{BuildHasher, Hasher, RandomState};
///
/// let s = RandomState::new();
Expand All @@ -76,7 +78,9 @@ pub trait BuildHasher {
///
/// # Examples
///
/// ```
/// TODO: FIX EXAMPLE
///
/// ```ignore
/// use core::hash::{BuildHasher, RandomState};
///
/// let s = RandomState::new();
Expand Down
24 changes: 4 additions & 20 deletions lib/crypto/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,7 @@ impl MerkleVerifier<KeccakBuilder> {
///
/// ```
/// # use const_hex::FromHex;
/// # use alloy_primitives::keccak256;
/// # use crypto::merkle::verify;
/// # struct Keccak256;
/// # impl crypto::merkle::Hasher for Keccak256 {
/// # type Hash = Bytes32;
/// # fn hash<B: AsRef<[u8]>>(&mut self, bytes: B) -> Self::Hash {
/// # *keccak256(bytes.as_ref())
/// # }
/// # }
/// # use crypto::merkle::MerkleVerifier;
/// type Bytes32 = [u8; 32];
///
/// const ROOT: &str = "0x0000000000000000000000000000000000000000000000000000000000000000";
Expand All @@ -86,7 +78,7 @@ impl MerkleVerifier<KeccakBuilder> {
/// let leaf = Bytes32::from_hex(LEAF).unwrap();
/// let proof = Bytes32::from_hex(PROOF).unwrap();
///
/// let verification = verify(&[proof], root, leaf, Keccak256);
/// let verification = MerkleVerifier::verify(&[proof], root, leaf);
/// assert!(!verification);
/// ```
pub fn verify(proof: &[Bytes32], root: Bytes32, mut leaf: Bytes32) -> bool {
Expand Down Expand Up @@ -149,15 +141,7 @@ impl MerkleVerifier<KeccakBuilder> {
///
/// ```
/// # use const_hex::FromHex;
/// # use alloy_primitives::keccak256;
/// # use crypto::merkle::verify_multi_proof;
/// # struct Keccak256;
/// # impl crypto::merkle::Hasher for Keccak256 {
/// # type Hash = Bytes32;
/// # fn hash<B: AsRef<[u8]>>(&mut self, bytes: B) -> Self::Hash {
/// # *keccak256(bytes.as_ref())
/// # }
/// # }
/// # use crypto::merkle::MerkleVerifier;
/// type Bytes32 = [u8; 32];
///
/// const ROOT: &str = "0x6deb52b5da8fd108f79fab00341f38d2587896634c646ee52e49f845680a70c8";
Expand All @@ -179,7 +163,7 @@ impl MerkleVerifier<KeccakBuilder> {
/// let proof_flags = [false, true, false, true];
///
/// let verification =
/// verify_multi_proof(&proof, &proof_flags, root, &leaves, Keccak256);
/// MerkleVerifier::verify_multi_proof(&proof, &proof_flags, root, &leaves);
/// assert!(verification.unwrap());
/// ```
#[cfg(feature = "multi_proof")]
Expand Down

0 comments on commit 8fc8f1e

Please sign in to comment.