From 87b17ee7045b19eb22a1470d713fda879acd1650 Mon Sep 17 00:00:00 2001 From: Martin Hutchinson Date: Wed, 18 Sep 2024 12:14:50 +0000 Subject: [PATCH] Address comments Also updated comment on VerifyConsistency to say size1 is required to be > 0. The function is only clearly defined in this case. It's now undefined where size1 is 0. --- proof/verify.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/proof/verify.go b/proof/verify.go index 671dcbd..8226ad4 100644 --- a/proof/verify.go +++ b/proof/verify.go @@ -74,7 +74,7 @@ func RootFromInclusionProof(hasher merkle.LogHasher, index, size uint64, leafHas // VerifyConsistency checks that the passed-in consistency proof is valid // between the passed in tree sizes, with respect to the corresponding root -// hashes. Requires 0 <= size1 <= size2. +// hashes. Requires 0 < size1 <= size2. func VerifyConsistency(hasher merkle.LogHasher, size1, size2 uint64, proof [][]byte, root1, root2 []byte) error { hash2, err := RootFromConsistencyProof(hasher, size1, size2, proof, root1) if err != nil { @@ -83,6 +83,10 @@ func VerifyConsistency(hasher merkle.LogHasher, size1, size2 uint64, proof [][]b return verifyMatch(hash2, root2) } +// RootFromConsistencyProof calculates the expected root hash for a tree of the +// given size2, provided a tree of size1 with root1, and a consistency proof. +// Requires 0 < size1 <= size2. +// Note that consistency proofs from a size1==0 cannot be computed. func RootFromConsistencyProof(hasher merkle.LogHasher, size1, size2 uint64, proof [][]byte, root1 []byte) ([]byte, error) { switch { case size2 < size1: @@ -93,7 +97,7 @@ func RootFromConsistencyProof(hasher merkle.LogHasher, size1, size2 uint64, proo } return root1, nil case size1 == 0: - return nil, errors.New("Consistency proof from empty tree are meaningless") + return nil, errors.New("consistency proof from empty tree is meaningless") case len(proof) == 0: return nil, errors.New("empty proof") }