Skip to content

Commit 3cbfd6c

Browse files
committed
better checks at boundaries
1 parent 216c761 commit 3cbfd6c

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

cmd/proofgen/main.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/json"
2020
"fmt"
2121
"log"
22+
"math"
2223
"math/bits"
2324
"os"
2425
"path/filepath"
@@ -340,16 +341,20 @@ func toSubtreeInclusionProbe(p inclusionProbe) subtreeInclusionProbe {
340341
func shiftSubtreeInclusionProbe(p subtreeInclusionProbe) subtreeInclusionProbe {
341342
shift := bitCeil(p.End - p.Start)
342343
desc := p.Desc + " - subtree"
343-
leafIdx := p.LeafIdx
344-
if leafIdx <= ^uint64(0)-shift {
344+
leafIdx, start, end := p.LeafIdx, p.Start, p.End
345+
if p.Start <= math.MaxUint64-shift {
346+
start += shift
347+
}
348+
if p.LeafIdx <= math.MaxUint64-shift {
345349
leafIdx += shift
346-
} else {
347-
leafIdx = ^uint64(0)
350+
}
351+
if p.End <= math.MaxUint64-shift {
352+
end += shift
348353
}
349354
return subtreeInclusionProbe{
350355
LeafIdx: leafIdx,
351-
Start: p.Start + shift,
352-
End: p.End + shift,
356+
Start: start,
357+
End: end,
353358
Root: p.Root,
354359
LeafHash: p.LeafHash,
355360
Proof: p.Proof,

0 commit comments

Comments
 (0)