Skip to content

Commit 2406305

Browse files
authored
trie: combine validation loops in VerifyRangeProof (#30823)
Small optimization. It's guaranteed that `len(keys)` == `len(values)`, so we can combine the checks in a single loop rather than 2 separate loops.
1 parent 8c1a36d commit 2406305

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

trie/proof.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,11 @@ func VerifyRangeProof(rootHash common.Hash, firstKey []byte, keys [][]byte, valu
486486
return false, fmt.Errorf("inconsistent proof data, keys: %d, values: %d", len(keys), len(values))
487487
}
488488
// Ensure the received batch is monotonic increasing and contains no deletions
489-
for i := 0; i < len(keys)-1; i++ {
490-
if bytes.Compare(keys[i], keys[i+1]) >= 0 {
489+
for i := 0; i < len(keys); i++ {
490+
if i < len(keys)-1 && bytes.Compare(keys[i], keys[i+1]) >= 0 {
491491
return false, errors.New("range is not monotonically increasing")
492492
}
493-
}
494-
for _, value := range values {
495-
if len(value) == 0 {
493+
if len(values[i]) == 0 {
496494
return false, errors.New("range contains deletion")
497495
}
498496
}

0 commit comments

Comments
 (0)