@@ -393,23 +393,24 @@ func hasRightElement(node node, key []byte) bool {
393
393
// (unless firstProof is an existent proof).
394
394
//
395
395
// Expect the normal case, this function can also be used to verify the following
396
- // range proofs(note this function doesn't accept zero element proof) :
396
+ // range proofs:
397
397
//
398
398
// - All elements proof. In this case the left and right proof can be nil, but the
399
399
// range should be all the leaves in the trie.
400
400
//
401
401
// - One element proof. In this case no matter the left edge proof is a non-existent
402
402
// proof or not, we can always verify the correctness of the proof.
403
403
//
404
+ // - Zero element proof(left edge proof should be a non-existent proof). In this
405
+ // case if there are still some other leaves available on the right side, then
406
+ // an error will be returned.
407
+ //
404
408
// Except returning the error to indicate the proof is valid or not, the function will
405
409
// also return a flag to indicate whether there exists more accounts/slots in the trie.
406
410
func VerifyRangeProof (rootHash common.Hash , firstKey []byte , keys [][]byte , values [][]byte , firstProof ethdb.KeyValueReader , lastProof ethdb.KeyValueReader ) (error , bool ) {
407
411
if len (keys ) != len (values ) {
408
412
return fmt .Errorf ("inconsistent proof data, keys: %d, values: %d" , len (keys ), len (values )), false
409
413
}
410
- if len (keys ) == 0 {
411
- return errors .New ("empty proof" ), false
412
- }
413
414
// Ensure the received batch is monotonic increasing.
414
415
for i := 0 ; i < len (keys )- 1 ; i ++ {
415
416
if bytes .Compare (keys [i ], keys [i + 1 ]) >= 0 {
@@ -431,6 +432,18 @@ func VerifyRangeProof(rootHash common.Hash, firstKey []byte, keys [][]byte, valu
431
432
}
432
433
return nil , false // no more element.
433
434
}
435
+ // Special case, there is a provided left edge proof and zero key/value
436
+ // pairs, ensure there are no more accounts / slots in the trie.
437
+ if len (keys ) == 0 {
438
+ root , val , err := proofToPath (rootHash , nil , firstKey , firstProof , true )
439
+ if err != nil {
440
+ return err , false
441
+ }
442
+ if val != nil || hasRightElement (root , firstKey ) {
443
+ return errors .New ("more entries available" ), false
444
+ }
445
+ return nil , false
446
+ }
434
447
// Special case, there is only one element and left edge
435
448
// proof is an existent one.
436
449
if len (keys ) == 1 && bytes .Equal (keys [0 ], firstKey ) {
0 commit comments