@@ -302,12 +302,24 @@ func (proof *RangeProof) Verify(
302
302
return err
303
303
}
304
304
305
- largestPath := maybe .Bind (end , newPath )
305
+ // [proof] allegedly provides and proves all key-value
306
+ // pairs in [smallestProvenPath, largestProvenPath].
307
+ // If [smallestProvenPath] is Nothing, [proof] should
308
+ // provide and prove all keys < [largestProvenPath].
309
+ // If [largestProvenPath] is Nothing, [proof] should
310
+ // provide and prove all keys > [smallestProvenPath].
311
+ // If both are Nothing, [proof] should prove the entire trie.
312
+ smallestProvenPath := maybe .Nothing [path ]()
313
+ if start != nil {
314
+ smallestProvenPath = maybe .Some (newPath (start ))
315
+ }
316
+
317
+ largestProvenPath := maybe .Bind (end , newPath )
306
318
if len (proof .KeyValues ) > 0 {
307
319
// If [proof] has key-value pairs, we should insert children
308
- // greater than [largestKey ] to ancestors of the node containing
309
- // [largestKey ] so that we get the expected root ID.
310
- largestPath = maybe .Some (newPath (proof .KeyValues [len (proof .KeyValues )- 1 ].Key ))
320
+ // greater than [largestProvenPath ] to ancestors of the node containing
321
+ // [largestProvenPath ] so that we get the expected root ID.
322
+ largestProvenPath = maybe .Some (newPath (proof .KeyValues [len (proof .KeyValues )- 1 ].Key ))
311
323
}
312
324
313
325
// The key-value pairs (allegedly) proven by [proof].
@@ -316,23 +328,31 @@ func (proof *RangeProof) Verify(
316
328
keyValues [newPath (keyValue .Key )] = keyValue .Value
317
329
}
318
330
319
- smallestPath := newPath (start )
320
-
321
331
// Ensure that the start proof is valid and contains values that
322
332
// match the key/values that were sent.
323
- if err := verifyProofPath (proof .StartProof , smallestPath ); err != nil {
333
+ if err := verifyProofPath (proof .StartProof , smallestProvenPath . Value () ); err != nil {
324
334
return err
325
335
}
326
- if err := verifyAllRangeProofKeyValuesPresent (proof .StartProof , smallestPath , largestPath , keyValues ); err != nil {
336
+ if err := verifyAllRangeProofKeyValuesPresent (
337
+ proof .StartProof ,
338
+ smallestProvenPath .Value (),
339
+ largestProvenPath ,
340
+ keyValues ,
341
+ ); err != nil {
327
342
return err
328
343
}
329
344
330
345
// Ensure that the end proof is valid and contains values that
331
346
// match the key/values that were sent.
332
- if err := verifyProofPath (proof .EndProof , largestPath .Value ()); err != nil {
347
+ if err := verifyProofPath (proof .EndProof , largestProvenPath .Value ()); err != nil {
333
348
return err
334
349
}
335
- if err := verifyAllRangeProofKeyValuesPresent (proof .EndProof , smallestPath , largestPath , keyValues ); err != nil {
350
+ if err := verifyAllRangeProofKeyValuesPresent (
351
+ proof .EndProof ,
352
+ smallestProvenPath .Value (),
353
+ largestProvenPath ,
354
+ keyValues ,
355
+ ); err != nil {
336
356
return err
337
357
}
338
358
@@ -350,24 +370,24 @@ func (proof *RangeProof) Verify(
350
370
}
351
371
352
372
// For all the nodes along the edges of the proof, insert children
353
- // < [smallestPath ] and > [largestPath ]
373
+ // < [smallestProvenPath ] and > [largestProvenPath ]
354
374
// into the trie so that we get the expected root ID (if this proof is valid).
355
- // By inserting all children < [smallestPath ], we prove that there are no keys
356
- // > [largestPath ] but less than the first key given.
375
+ // By inserting all children < [smallestProvenPath ], we prove that there are no keys
376
+ // > [smallestProvenPath ] but less than the first key given.
357
377
// That is, the peer who gave us this proof is not omitting nodes.
358
378
if err := addPathInfo (
359
379
view ,
360
380
proof .StartProof ,
361
- maybe . Some ( smallestPath ) ,
362
- largestPath ,
381
+ smallestProvenPath ,
382
+ largestProvenPath ,
363
383
); err != nil {
364
384
return err
365
385
}
366
386
if err := addPathInfo (
367
387
view ,
368
388
proof .EndProof ,
369
- maybe . Some ( smallestPath ) ,
370
- largestPath ,
389
+ smallestProvenPath ,
390
+ largestProvenPath ,
371
391
); err != nil {
372
392
return err
373
393
}
0 commit comments