Skip to content

Commit 3aea23c

Browse files
authored
Merge pull request #2345 from CortexFoundation/dev
add edgecase for rangeproof correctness
2 parents e4df15c + ca8b16b commit 3aea23c

8 files changed

Lines changed: 115 additions & 28 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ require (
206206
github.com/pion/transport/v2 v2.2.10 // indirect
207207
github.com/pion/transport/v3 v3.0.7 // indirect
208208
github.com/pion/turn/v4 v4.0.1 // indirect
209-
github.com/pion/webrtc/v4 v4.0.16 // indirect
209+
github.com/pion/webrtc/v4 v4.1.0 // indirect
210210
github.com/pkg/errors v0.9.1 // indirect
211211
github.com/pmezard/go-difflib v1.0.0 // indirect
212212
github.com/prometheus/client_golang v1.22.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,8 @@ github.com/pion/turn/v4 v4.0.1 h1:01UTBhYToe8PDC8piB++i66q1mmctfhhoeguaFqB84c=
10371037
github.com/pion/turn/v4 v4.0.1/go.mod h1:pMMKP/ieNAG/fN5cZiN4SDuyKsXtNTr0ccN7IToA1zs=
10381038
github.com/pion/webrtc/v2 v2.2.7/go.mod h1:EfCuvKjzMgX4F/aSryRUC7L9o3u2N8WNUgnzd6wOO+8=
10391039
github.com/pion/webrtc/v2 v2.2.9/go.mod h1:TcArPDphZIBtZ+mh8J/qOREyY3ca7ihQrenulOIvfPQ=
1040-
github.com/pion/webrtc/v4 v4.0.16 h1:5f8QMVIbNvJr2mPRGi2QamkPa/LVUB6NWolOCwphKHA=
1041-
github.com/pion/webrtc/v4 v4.0.16/go.mod h1:C3uTCPzVafUA0eUzru9f47OgNt3nEO7ZJ6zNY6VSJno=
1040+
github.com/pion/webrtc/v4 v4.1.0 h1:yq/p0G5nKGbHISf0YKNA8Yk+kmijbblBvuSLwaJ4QYg=
1041+
github.com/pion/webrtc/v4 v4.1.0/go.mod h1:cgEGkcpxGkT6Di2ClBYO5lP9mFXbCfEOrkYUpjjCQO4=
10421042
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
10431043
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
10441044
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=

trie/proof.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,18 @@ func VerifyRangeProof(rootHash common.Hash, firstKey []byte, lastKey []byte, key
467467
if len(keys) != len(values) {
468468
return nil, nil, nil, false, fmt.Errorf("inconsistent proof data, keys: %d, values: %d", len(keys), len(values))
469469
}
470-
// Ensure the received batch is monotonic increasing and contains no deletions
470+
// Ensure the received batch is
471+
// - monotonically increasing,
472+
// - not expanding down prefix-paths
473+
// - and contains no deletions
471474
for i := 0; i < len(keys); i++ {
472-
if i < len(keys)-1 && bytes.Compare(keys[i], keys[i+1]) >= 0 {
473-
return nil, nil, nil, false, errors.New("range is not monotonically increasing")
475+
if i < len(keys)-1 {
476+
if bytes.Compare(keys[i], keys[i+1]) >= 0 {
477+
return nil, nil, nil, false, errors.New("range is not monotonically increasing")
478+
}
479+
if bytes.HasPrefix(keys[i+1], keys[i]) {
480+
return nil, nil, nil, false, errors.New("range contains path prefixes")
481+
}
474482
}
475483
if len(values[i]) == 0 {
476484
return nil, nil, nil, false, errors.New("range contains deletion")

trie/proof_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

vendor/github.com/pion/webrtc/v4/mediaengine.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pion/webrtc/v4/peerconnection.go

Lines changed: 47 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/pion/webrtc/v4/track_local_static.go

Lines changed: 18 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ github.com/pion/turn/v4/internal/client
967967
github.com/pion/turn/v4/internal/ipnet
968968
github.com/pion/turn/v4/internal/proto
969969
github.com/pion/turn/v4/internal/server
970-
# github.com/pion/webrtc/v4 v4.0.16
970+
# github.com/pion/webrtc/v4 v4.1.0
971971
## explicit; go 1.20
972972
github.com/pion/webrtc/v4
973973
github.com/pion/webrtc/v4/internal/fmtp

0 commit comments

Comments
 (0)