Conversation
| //! # use fastcrypto::hash::Sha256; | ||
| //! # use fastcrypto_data::merkle_tree::*; | ||
| //! let elements = [[1u8], [2u8], [3u8]]; | ||
| //! let mut tree = MerkleTree::<32, Sha256, [u8; 1]>::new(); |
| } | ||
|
|
||
| impl<const DIGEST_LENGTH: usize, H: HashFunction<DIGEST_LENGTH>, T: AsRef<[u8]>> | ||
| MerkleTree<DIGEST_LENGTH, H, T> |
There was a problem hiding this comment.
pls merge with the impl of this struct above
| /// | ||
| /// To avoid second-preimage attacks, a 0x00 byte is prepended to the hash data for leaf nodes (see | ||
| /// [LeafHasher]), and 0x01 is prepended when computing internal node hashes (see [InternalNodeHasher]). | ||
| pub struct MerkleTree<const DIGEST_LENGTH: usize, H: HashFunction<DIGEST_LENGTH>, T: AsRef<[u8]>> { |
There was a problem hiding this comment.
why do we need T here? can we instead have generic insert()?
| /// | ||
| /// To avoid second-preimage attacks, a 0x00 byte is prepended to the hash data for leaf nodes (see | ||
| /// [LeafHasher]), and 0x01 is prepended when computing internal node hashes (see [InternalNodeHasher]). | ||
| pub struct MerkleTree<const DIGEST_LENGTH: usize, H: HashFunction<DIGEST_LENGTH>, T: AsRef<[u8]>> { |
There was a problem hiding this comment.
Maybe instead of requiring AsRef, let's require trait Hashable or just Serialize
(AsRef requires using OnceCell in some cases, which we better avoid unless have to).
| MerkleTree<DIGEST_LENGTH, H, T> | ||
| { | ||
| /// Hash an element using the hash function used for this tree. | ||
| pub fn hash(element: &T) -> [u8; DIGEST_LENGTH] { |
| //! assert!(verifier.verify(index, &elements[index], &proof)); | ||
| //! ``` | ||
|
|
||
| use std::borrow::Borrow; |
There was a problem hiding this comment.
What is the use case for this data structure? there are many variants of merkle trees, e.g., key-value, with deletions, etc.
Also, what is the expected number of objects, and the expected insertion/deletion pattern?
kchalkias
left a comment
There was a problem hiding this comment.
Let's resurrect that PR and get some timings as well (part of our light client story)
No description provided.