-
Notifications
You must be signed in to change notification settings - Fork 43
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
Verify inclusion proofs with multiple leaves #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,10 +206,19 @@ func (proof Proof) verifyLeafHashes(nth *Hasher, verifyCompleteness bool, nID na | |
return bytes.Equal(tree.Root(), root) | ||
} | ||
|
||
func (proof Proof) VerifyInclusion(h hash.Hash, nid namespace.ID, data []byte, root []byte) bool { | ||
// VerifyInclusion checks that the inclusion proof is valid by using leaf data | ||
// and the provided proof to regenerate and compare the root. Note that the leaf | ||
// data should not contain the prefixed namespace, unlike the tree.Push method, | ||
// which takes prefixed data. All leaves implicitly have the same namespace ID: `nid`. | ||
func (proof Proof) VerifyInclusion(h hash.Hash, nid namespace.ID, leaves [][]byte, root []byte) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An additional convenience method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see that working as well, tbh I just didn't think about that and was just following the underlying library's API. I want to merge to wrap this up, but I also don't want to lose this comment, so #59 |
||
nth := NewNmtHasher(h, nid.Size(), proof.isMaxNamespaceIDIgnored) | ||
leafData := append(nid, data...) | ||
return proof.verifyLeafHashes(nth, false, nid, [][]byte{nth.HashLeaf(leafData)}, root) | ||
hashes := make([][]byte, len(leaves)) | ||
for i, d := range leaves { | ||
leafData := append(append(make([]byte, 0, len(d)+len(nid)), nid...), d...) | ||
hashes[i] = nth.HashLeaf(leafData) | ||
} | ||
|
||
return proof.verifyLeafHashes(nth, false, nid, hashes, root) | ||
} | ||
|
||
// nextSubtreeSize returns the size of the subtree adjacent to start that does | ||
|
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.
We should switch to the go-internal fuzzer soon.
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.
#60