Skip to content

Commit 90acf8a

Browse files
committed
better checks at boundaries
1 parent 216c761 commit 90acf8a

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

cmd/proofgen/main.go

Lines changed: 7 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,16 @@ 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 && p.LeafIdx <= math.MaxUint64-shift && p.End <= math.MaxUint64-shift {
345346
leafIdx += shift
346-
} else {
347-
leafIdx = ^uint64(0)
347+
start += shift
348+
end += shift
348349
}
349350
return subtreeInclusionProbe{
350351
LeafIdx: leafIdx,
351-
Start: p.Start + shift,
352-
End: p.End + shift,
352+
Start: start,
353+
End: end,
353354
Root: p.Root,
354355
LeafHash: p.LeafHash,
355356
Proof: p.Proof,

testdata/subtreeinclusion/0/leafIdx-sub-@1-subtree.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"leafIdx": 18446744073709551615,
3-
"start": 1,
4-
"end": 2,
3+
"start": 0,
4+
"end": 1,
55
"root": "bjQLnP+zepicpUTmu3gKLHiQHT+zNzh2hRGjBhevoB0=",
66
"leafHash": "bjQLnP+zepicpUTmu3gKLHiQHT+zNzh2hRGjBhevoB0=",
77
"proof": null,

testdata/subtreeinclusion/1/leafIdx-sub-@1-subtree.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"leafIdx": 18446744073709551615,
3-
"start": 8,
4-
"end": 16,
3+
"start": 0,
4+
"end": 8,
55
"root": "XcnaeacGWamtVZy3Ad7ZoqudgjqtL0lgz+Nw7/RgQyg=",
66
"leafHash": "bjQLnP+zepicpUTmu3gKLHiQHT+zNzh2hRGjBhevoB0=",
77
"proof": [

0 commit comments

Comments
 (0)