@@ -1000,3 +1000,35 @@ func TestRangeProofKeysWithSharedPrefix(t *testing.T) {
10001000 t .Error ("expected more to be false" )
10011001 }
10021002}
1003+
1004+ // TestRangeProofErrors tests a few cases where the prover is supposed
1005+ // to exit with errors
1006+ func TestRangeProofErrors (t * testing.T ) {
1007+ // Different number of keys to values
1008+ _ , err := VerifyRangeProof ((common.Hash {}), []byte {}, make ([][]byte , 5 ), make ([][]byte , 4 ), nil )
1009+ if have , want := err .Error (), "inconsistent proof data, keys: 5, values: 4" ; have != want {
1010+ t .Fatalf ("wrong error, have %q, want %q" , err .Error (), want )
1011+ }
1012+ // Non-increasing paths
1013+ _ , err = VerifyRangeProof ((common.Hash {}), []byte {},
1014+ [][]byte {[]byte {2 , 1 }, []byte {2 , 1 }}, make ([][]byte , 2 ), nil )
1015+ if have , want := err .Error (), "range is not monotonically increasing" ; have != want {
1016+ t .Fatalf ("wrong error, have %q, want %q" , err .Error (), want )
1017+ }
1018+ // A prefixed path is never motivated. Inserting the second element will
1019+ // require rewriting/overwriting the previous value-node, thus can only
1020+ // happen if the data is corrupt.
1021+ _ , err = VerifyRangeProof ((common.Hash {}), []byte {},
1022+ [][]byte {[]byte {2 , 1 }, []byte {2 , 1 , 2 }},
1023+ [][]byte {[]byte {1 }, []byte {1 }}, nil )
1024+ if have , want := err .Error (), "range contains path prefixes" ; have != want {
1025+ t .Fatalf ("wrong error, have %q, want %q" , err .Error (), want )
1026+ }
1027+ // Empty values (deletions)
1028+ _ , err = VerifyRangeProof ((common.Hash {}), []byte {},
1029+ [][]byte {[]byte {2 , 1 }, []byte {2 , 2 }},
1030+ [][]byte {[]byte {1 }, []byte {}}, nil )
1031+ if have , want := err .Error (), "range contains deletion" ; have != want {
1032+ t .Fatalf ("wrong error, have %q, want %q" , err .Error (), want )
1033+ }
1034+ }
0 commit comments