Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trie: test for edgecase in VerifyRangeProof #24257

Merged
merged 3 commits into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions trie/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,3 +1067,36 @@ func nonRandomTrie(n int) (*Trie, map[string]*kv) {
}
return trie, vals
}

func TestRangeProofKeysWithSharedPrefix(t *testing.T) {
keys := [][]byte{
common.Hex2Bytes("aa10000000000000000000000000000000000000000000000000000000000000"),
common.Hex2Bytes("aa20000000000000000000000000000000000000000000000000000000000000"),
}
vals := [][]byte{
common.Hex2Bytes("02"),
common.Hex2Bytes("03"),
}
trie := new(Trie)
for i, key := range keys {
trie.Update(key, vals[i])
}
root := trie.Hash()
proof := memorydb.New()
start := common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")
end := common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
if err := trie.Prove(start, 0, proof); err != nil {
t.Fatalf("failed to prove start: %v", err)
}
if err := trie.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")
}
}