Skip to content

Commit 0e03927

Browse files
committed
better checks at boundaries
1 parent 216c761 commit 0e03927

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

cmd/proofgen/main.go

Lines changed: 12 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,21 @@ 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+
// Shift indices independently to allow for pathological cases.
346+
if p.Start <= math.MaxUint64-shift {
347+
start += shift
348+
}
349+
if p.LeafIdx <= math.MaxUint64-shift {
345350
leafIdx += shift
346-
} else {
347-
leafIdx = ^uint64(0)
351+
}
352+
if p.End <= math.MaxUint64-shift {
353+
end += shift
348354
}
349355
return subtreeInclusionProbe{
350356
LeafIdx: leafIdx,
351-
Start: p.Start + shift,
352-
End: p.End + shift,
357+
Start: start,
358+
End: end,
353359
Root: p.Root,
354360
LeafHash: p.LeafHash,
355361
Proof: p.Proof,

0 commit comments

Comments
 (0)