@@ -808,6 +808,85 @@ func TestBloatedProof(t *testing.T) {
808
808
}
809
809
}
810
810
811
+ // TestEmptyValueRangeProof tests normal range proof with both edge proofs
812
+ // as the existent proof, but with an extra empty value included, which is a
813
+ // noop technically, but practically should be rejected.
814
+ func TestEmptyValueRangeProof (t * testing.T ) {
815
+ trie , values := randomTrie (512 )
816
+ var entries entrySlice
817
+ for _ , kv := range values {
818
+ entries = append (entries , kv )
819
+ }
820
+ sort .Sort (entries )
821
+
822
+ // Create a new entry with a slightly modified key
823
+ mid := len (entries ) / 2
824
+ key := common .CopyBytes (entries [mid - 1 ].k )
825
+ for n := len (key ) - 1 ; n >= 0 ; n -- {
826
+ if key [n ] < 0xff {
827
+ key [n ]++
828
+ break
829
+ }
830
+ }
831
+ noop := & kv {key , []byte {}, false }
832
+ entries = append (append (append ([]* kv {}, entries [:mid ]... ), noop ), entries [mid :]... )
833
+
834
+ start , end := 1 , len (entries )- 1
835
+
836
+ proof := memorydb .New ()
837
+ if err := trie .Prove (entries [start ].k , 0 , proof ); err != nil {
838
+ t .Fatalf ("Failed to prove the first node %v" , err )
839
+ }
840
+ if err := trie .Prove (entries [end - 1 ].k , 0 , proof ); err != nil {
841
+ t .Fatalf ("Failed to prove the last node %v" , err )
842
+ }
843
+ var keys [][]byte
844
+ var vals [][]byte
845
+ for i := start ; i < end ; i ++ {
846
+ keys = append (keys , entries [i ].k )
847
+ vals = append (vals , entries [i ].v )
848
+ }
849
+ _ , err := VerifyRangeProof (trie .Hash (), keys [0 ], keys [len (keys )- 1 ], keys , vals , proof )
850
+ if err == nil {
851
+ t .Fatalf ("Expected failure on noop entry" )
852
+ }
853
+ }
854
+
855
+ // TestAllElementsEmptyValueRangeProof tests the range proof with all elements,
856
+ // but with an extra empty value included, which is a noop technically, but
857
+ // practically should be rejected.
858
+ func TestAllElementsEmptyValueRangeProof (t * testing.T ) {
859
+ trie , values := randomTrie (512 )
860
+ var entries entrySlice
861
+ for _ , kv := range values {
862
+ entries = append (entries , kv )
863
+ }
864
+ sort .Sort (entries )
865
+
866
+ // Create a new entry with a slightly modified key
867
+ mid := len (entries ) / 2
868
+ key := common .CopyBytes (entries [mid - 1 ].k )
869
+ for n := len (key ) - 1 ; n >= 0 ; n -- {
870
+ if key [n ] < 0xff {
871
+ key [n ]++
872
+ break
873
+ }
874
+ }
875
+ noop := & kv {key , []byte {}, false }
876
+ entries = append (append (append ([]* kv {}, entries [:mid ]... ), noop ), entries [mid :]... )
877
+
878
+ var keys [][]byte
879
+ var vals [][]byte
880
+ for i := 0 ; i < len (entries ); i ++ {
881
+ keys = append (keys , entries [i ].k )
882
+ vals = append (vals , entries [i ].v )
883
+ }
884
+ _ , err := VerifyRangeProof (trie .Hash (), nil , nil , keys , vals , nil )
885
+ if err == nil {
886
+ t .Fatalf ("Expected failure on noop entry" )
887
+ }
888
+ }
889
+
811
890
// mutateByte changes one byte in b.
812
891
func mutateByte (b []byte ) {
813
892
for r := mrand .Intn (len (b )); ; {
0 commit comments