From 5d4154b8d31c501333e9cb8362dc926afaaea785 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 19 Jan 2022 15:57:18 -0600 Subject: [PATCH 1/3] trie/proof: edge case for VerifyRangeProof --- trie/proof_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/trie/proof_test.go b/trie/proof_test.go index 95ad6169c3bd6..06d75fa2d4a2f 100644 --- a/trie/proof_test.go +++ b/trie/proof_test.go @@ -1067,3 +1067,43 @@ func nonRandomTrie(n int) (*Trie, map[string]*kv) { } return trie, vals } + +func TestRangeProofKeysWithSharedPrefix(t *testing.T) { + // TODO: test fails if 1st key/value pair is omitted. + keys := [][]byte{ + common.Hex2Bytes("1000000000000000000000000000000000000000000000000000000000000000"), + common.Hex2Bytes("aa10000000000000000000000000000000000000000000000000000000000000"), + common.Hex2Bytes("aa20000000000000000000000000000000000000000000000000000000000000"), + } + vals := [][]byte{ + common.Hex2Bytes("01"), + common.Hex2Bytes("02"), + common.Hex2Bytes("03"), + } + db := memorydb.New() + tr, err := New(common.Hash{}, NewDatabase(db)) + if err != nil { + t.Fatalf("could not create new trie: %v", err) + } + for i, key := range keys { + tr.Update(key, vals[i]) + } + root := tr.Hash() + proof := memorydb.New() + start := common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000") + end := common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + if err := tr.Prove(start, 0, proof); err != nil { + t.Fatalf("failed to prove start: %v", err) + } + if err := tr.Prove(end, 0, proof); err != nil { + t.Fatalf("failed to prove end: %v", err) + } + + more, err := VerifyRangeProof(root, start, end, keys, vals, proof) + if err != nil { + t.Fatalf("failed to verify range proof: %v", err) + } + if more != false { + t.Error("expected more to be false") + } +} From 696a1f822bd860b1e5ef3a88e1753f36efb392af Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 19 Jan 2022 16:07:58 -0600 Subject: [PATCH 2/3] more consistency with other tests in the file --- trie/proof_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/trie/proof_test.go b/trie/proof_test.go index 06d75fa2d4a2f..2c92bddf39b52 100644 --- a/trie/proof_test.go +++ b/trie/proof_test.go @@ -1080,22 +1080,18 @@ func TestRangeProofKeysWithSharedPrefix(t *testing.T) { common.Hex2Bytes("02"), common.Hex2Bytes("03"), } - db := memorydb.New() - tr, err := New(common.Hash{}, NewDatabase(db)) - if err != nil { - t.Fatalf("could not create new trie: %v", err) - } + trie := new(Trie) for i, key := range keys { - tr.Update(key, vals[i]) + trie.Update(key, vals[i]) } - root := tr.Hash() + root := trie.Hash() proof := memorydb.New() start := common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000") end := common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - if err := tr.Prove(start, 0, proof); err != nil { + if err := trie.Prove(start, 0, proof); err != nil { t.Fatalf("failed to prove start: %v", err) } - if err := tr.Prove(end, 0, proof); err != nil { + if err := trie.Prove(end, 0, proof); err != nil { t.Fatalf("failed to prove end: %v", err) } From 094cdac847a474472fd331f6c12164e1573868d9 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 21 Jan 2022 10:45:40 +0100 Subject: [PATCH 3/3] trie: fix test todo --- trie/proof_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/trie/proof_test.go b/trie/proof_test.go index 2c92bddf39b52..29866714c2d0a 100644 --- a/trie/proof_test.go +++ b/trie/proof_test.go @@ -1069,14 +1069,11 @@ func nonRandomTrie(n int) (*Trie, map[string]*kv) { } func TestRangeProofKeysWithSharedPrefix(t *testing.T) { - // TODO: test fails if 1st key/value pair is omitted. keys := [][]byte{ - common.Hex2Bytes("1000000000000000000000000000000000000000000000000000000000000000"), common.Hex2Bytes("aa10000000000000000000000000000000000000000000000000000000000000"), common.Hex2Bytes("aa20000000000000000000000000000000000000000000000000000000000000"), } vals := [][]byte{ - common.Hex2Bytes("01"), common.Hex2Bytes("02"), common.Hex2Bytes("03"), }