-
Notifications
You must be signed in to change notification settings - Fork 21
feat(mmr): inital MMR rewrite complete #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks in shape, some questions and feedbacks.
Seems like the code needs to be run through a formatter once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few issues here. I should have been more clear that the "chunk" concept was specific to the original application the provided code was used for and that we just need to talk about it in terms of leafs as hashes. But the main issue we really gotta resolve is the excessive allocations, some bookkeeping, and module layout.
- Concept of chunk is removed - H type used instead of Sha256 for trait that uses Digest - new verify function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bigger stuff has been resolved but main issue is still that the types are improperly defined/used.
…emove hash_leaves function, \n - remove redundant prooflen from MerkleHash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor cleanup now.
crates/util/mmr/src/lib.rs
Outdated
| /// verifies if the hash of the element at particular index is present as a proof | ||
| pub fn verify(&self,proof: &MerkleProof<H>,hash: MerkleHash) -> Result<bool, MerkleError> { | ||
| if proof.index as usize>= self.num as usize{ | ||
| return Err(MerkleError::IndexOutOfBounds); | ||
| } | ||
|
|
||
| return Ok(proof.proof_verify(self, hash)); | ||
| } | ||
|
|
||
| /// constructs a MerkleProof and then verifies it | ||
| pub fn verify_with_cohashes(&self, index: u64,hash: MerkleHash, cohashes: Vec<MerkleHash>) -> Result<bool, MerkleError> { | ||
| let proof: MerkleProof<H> = MerkleProof { | ||
| prooflen: cohashes.len(), | ||
| cohashes, | ||
| index, | ||
| hasher: PhantomData, | ||
| }; | ||
|
|
||
| self.verify(&proof, hash) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not new but something like this yes
|
I think this is in a good position now. We can roll with it. |
This is the first rewrite of MMR based on https://codeberg.org/treyd/supermerkle.
Closes #74