Skip to content

Commit 04ef8ac

Browse files
committed
Fix proof size checks reporting off-by-one sizes
1 parent 4ba2f58 commit 04ef8ac

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

proof/verify.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ func VerifyConsistency(nh NodeHasher, size1, size2 uint64, proof [][]byte, root1
9191

9292
// Otherwise, the consistency proof is equivalent to an inclusion proof of
9393
// its first hash. Verify it below.
94-
if got := len(proof); got < 1 {
95-
// TODO(pavelkalinnikov): Check proof size earlier, show the expected size.
96-
return fmt.Errorf("incorrect proof size: %d", got)
94+
if got, want := len(proof), 1+bits.Len64(size2-1)-int(level); got != want {
95+
return fmt.Errorf("incorrect proof size: %d, want %d", got, want)
9796
}
9897
if err := verify(nh, index, level, size2, proof[0], proof[1:], root2); err != nil {
9998
return err
@@ -134,8 +133,6 @@ func verify(nh NodeHasher, index uint64, level uint, size uint64, hash []byte, p
134133
}
135134

136135
if got, want := len(proof), inner+right+left; got != want {
137-
// TODO(pavelkalinnikov): Fix this error showing off-by-one `got` and
138-
// `want` size for consistency proofs where size1 is not a power of 2.
139136
return fmt.Errorf("incorrect proof size: %d, want %d", got, want)
140137
}
141138

0 commit comments

Comments
 (0)