Skip to content

Commit 33e69e1

Browse files
committed
added new invariant
1 parent 3b1f34d commit 33e69e1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

x/merkledb/db.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,9 @@ func (db *merkleDB) VerifyChangeProof(
10861086
keys := make([]Key, len(proof.KeyChanges))
10871087
for i, keyValue := range proof.KeyChanges {
10881088
k := ToKey(keyValue.Key)
1089+
if k.hasPartialByte() {
1090+
return ErrProofKeyPartialByte
1091+
}
10891092

10901093
keyChanges[k] = keyValue.Value
10911094
keys[i] = k

x/merkledb/proof.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var (
3838
ErrExclusionProofUnexpectedValue = errors.New("exclusion proof's value should be empty")
3939
ErrExclusionProofInvalidNode = errors.New("invalid node for exclusion proof")
4040
ErrProofValueDoesntMatch = errors.New("the provided value does not match the proof node for the provided key's value")
41+
ErrProofKeyPartialByte = errors.New("the provided key has partial byte length")
4142
ErrProofNodeHasUnincludedValue = errors.New("the provided proof has a value for a key within the range that is not present in the provided key/values")
4243
ErrInvalidMaybe = errors.New("maybe is nothing but has value")
4344
ErrNilProofNode = errors.New("proof node is nil")
@@ -124,6 +125,7 @@ type Proof struct {
124125
// Always contains at least the root.
125126
Path []ProofNode
126127
// This is a proof that [key] exists/doesn't exist.
128+
// Must not have any partial bytes.
127129
Key Key
128130

129131
// Nothing if [Key] isn't in the trie.
@@ -145,6 +147,10 @@ func (proof *Proof) Verify(
145147
return ErrEmptyProof
146148
}
147149

150+
if proof.Key.hasPartialByte() {
151+
return ErrProofKeyPartialByte
152+
}
153+
148154
lastNode := proof.Path[len(proof.Path)-1]
149155
inclusionProof := lastNode.Key.Compare(proof.Key) == 0
150156

@@ -258,6 +264,7 @@ type RangeProof struct {
258264
// Each key is in the requested range (inclusive).
259265
// The first key-value is the first key-value at/after the range start.
260266
// The key-value pairs are consecutive.
267+
// Must not have any partial bytes.
261268
// Sorted by increasing key and with no duplicate keys.
262269
KeyValues []KeyValue
263270
}
@@ -352,6 +359,9 @@ func (proof *RangeProof) Verify(
352359
keys := make([]Key, len(proof.KeyValues))
353360
for i, keyValue := range proof.KeyValues {
354361
k := ToKey(keyValue.Key)
362+
if k.hasPartialByte() {
363+
return ErrProofKeyPartialByte
364+
}
355365

356366
keyValues[k] = keyValue.Value
357367
keys[i] = k
@@ -580,6 +590,7 @@ type ChangeProof struct {
580590
// end roots such that k1 < k3 < k2.
581591
// This is a subset of the requested key-value range, rather than the entire
582592
// range, because otherwise the proof may be too large.
593+
// Must not have any partial bytes.
583594
// Sorted by increasing key and with no duplicate keys.
584595
//
585596
// Example: Suppose that between the start root and the end root, the following

0 commit comments

Comments
 (0)