Skip to content

Commit

Permalink
accumulator/pollard: Add a VerifyBatchProof method
Browse files Browse the repository at this point in the history
Pollard now has a method just for verifying a given proof. This new
method does not alter the Pollard in any way, making it useful during
verifying mempool Bitcoin transactions.
  • Loading branch information
kcalvinalvin committed Sep 6, 2021
1 parent 9606c8a commit 12e9202
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion accumulator/pollardproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,39 @@ import (
"fmt"
)

// VerifyBatchProof verifies the hash and the proof passed in. It does not
// make any modifications to the pollard.
//
// NOTE: The order in which the hashes are given matter (aka permutation matters).
// The hashes being verified should be in the same order as they were
// proven.
func (p *Pollard) VerifyBatchProof(toProve []Hash, bp BatchProof) error {
// verify the batch proof.
rootHashes := p.rootHashesForward()
_, _, err := verifyBatchProof(toProve, bp, rootHashes, p.numLeaves,
// pass a closure that checks the pollard for cached nodes.
// returns true and the hash value of the node if it exists.
// returns false if the node does not exist or the hash value is empty.
func(pos uint64) (bool, Hash) {
n, _, _, err := p.readPos(pos)
if err != nil {
return false, empty
}
if n != nil && n.data != empty {
return true, n.data
}

return false, empty
})
return err
}

// IngestBatchProof populates the Pollard with all needed data to delete the
// targets in the block proof
// targets in the block proof.
//
// NOTE: The order in which the hashes are given matter (aka permutation matters).
// The hashes being verified should be in the same order as they were
// proven.
func (p *Pollard) IngestBatchProof(toProve []Hash, bp BatchProof) error {
// verify the batch proof.
rootHashes := p.rootHashesForward()
Expand Down

0 comments on commit 12e9202

Please sign in to comment.