Skip to content

Commit

Permalink
accumulator/forestproofs: fix off-by-one error in Prove sanity check
Browse files Browse the repository at this point in the history
If the number of leaves is `numLeaves`, valid leaf positions
are in the range of `(0, numLeaves-1)`, i.e. `pos == numLeaves`
is already out of range. Take this into account for the sanity
check before calling `detectSubTreeRows`.
  • Loading branch information
theStack committed Apr 15, 2022
1 parent 1ff40de commit 80599dc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion accumulator/forestproofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (f *Forest) Prove(wanted Hash) (Proof, error) {
}

// should never happen
if pos > f.numLeaves {
if pos >= f.numLeaves {
return pr, fmt.Errorf("prove: got leaf position %d but only %d leaves exist",
pos, f.numLeaves)
}
Expand Down

0 comments on commit 80599dc

Please sign in to comment.