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