|
|
@ -182,7 +182,7 @@ func TestRangeProof(t *testing.T) { |
|
|
|
keys = append(keys, entries[i].k) |
|
|
|
keys = append(keys, entries[i].k) |
|
|
|
vals = append(vals, entries[i].v) |
|
|
|
vals = append(vals, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, vals, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, vals, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Case %d(%d->%d) expect no error, got %v", i, start, end-1, err) |
|
|
|
t.Fatalf("Case %d(%d->%d) expect no error, got %v", i, start, end-1, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -233,7 +233,7 @@ func TestRangeProofWithNonExistentProof(t *testing.T) { |
|
|
|
keys = append(keys, entries[i].k) |
|
|
|
keys = append(keys, entries[i].k) |
|
|
|
vals = append(vals, entries[i].v) |
|
|
|
vals = append(vals, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), first, last, keys, vals, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), first, last, keys, vals, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Case %d(%d->%d) expect no error, got %v", i, start, end-1, err) |
|
|
|
t.Fatalf("Case %d(%d->%d) expect no error, got %v", i, start, end-1, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -254,7 +254,7 @@ func TestRangeProofWithNonExistentProof(t *testing.T) { |
|
|
|
k = append(k, entries[i].k) |
|
|
|
k = append(k, entries[i].k) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), first, last, k, v, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), first, last, k, v, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal("Failed to verify whole rang with non-existent edges") |
|
|
|
t.Fatal("Failed to verify whole rang with non-existent edges") |
|
|
|
} |
|
|
|
} |
|
|
@ -289,7 +289,7 @@ func TestRangeProofWithInvalidNonExistentProof(t *testing.T) { |
|
|
|
k = append(k, entries[i].k) |
|
|
|
k = append(k, entries[i].k) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), first, k[len(k)-1], k, v, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), first, k[len(k)-1], k, v, proof) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
t.Fatalf("Expected to detect the error, got nil") |
|
|
|
t.Fatalf("Expected to detect the error, got nil") |
|
|
|
} |
|
|
|
} |
|
|
@ -311,7 +311,7 @@ func TestRangeProofWithInvalidNonExistentProof(t *testing.T) { |
|
|
|
k = append(k, entries[i].k) |
|
|
|
k = append(k, entries[i].k) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err = VerifyRangeProof(trie.Hash(), k[0], last, k, v, proof) |
|
|
|
_, _, err = VerifyRangeProof(trie.Hash(), k[0], last, k, v, proof) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
t.Fatalf("Expected to detect the error, got nil") |
|
|
|
t.Fatalf("Expected to detect the error, got nil") |
|
|
|
} |
|
|
|
} |
|
|
@ -335,7 +335,7 @@ func TestOneElementRangeProof(t *testing.T) { |
|
|
|
if err := trie.Prove(entries[start].k, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(entries[start].k, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the first node %v", err) |
|
|
|
t.Fatalf("Failed to prove the first node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), entries[start].k, entries[start].k, [][]byte{entries[start].k}, [][]byte{entries[start].v}, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), entries[start].k, entries[start].k, [][]byte{entries[start].k}, [][]byte{entries[start].v}, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -350,7 +350,7 @@ func TestOneElementRangeProof(t *testing.T) { |
|
|
|
if err := trie.Prove(entries[start].k, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(entries[start].k, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err = VerifyRangeProof(trie.Hash(), first, entries[start].k, [][]byte{entries[start].k}, [][]byte{entries[start].v}, proof) |
|
|
|
_, _, err = VerifyRangeProof(trie.Hash(), first, entries[start].k, [][]byte{entries[start].k}, [][]byte{entries[start].v}, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -365,7 +365,7 @@ func TestOneElementRangeProof(t *testing.T) { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err = VerifyRangeProof(trie.Hash(), entries[start].k, last, [][]byte{entries[start].k}, [][]byte{entries[start].v}, proof) |
|
|
|
_, _, err = VerifyRangeProof(trie.Hash(), entries[start].k, last, [][]byte{entries[start].k}, [][]byte{entries[start].v}, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -380,7 +380,7 @@ func TestOneElementRangeProof(t *testing.T) { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err = VerifyRangeProof(trie.Hash(), first, last, [][]byte{entries[start].k}, [][]byte{entries[start].v}, proof) |
|
|
|
_, _, err = VerifyRangeProof(trie.Hash(), first, last, [][]byte{entries[start].k}, [][]byte{entries[start].v}, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -399,7 +399,7 @@ func TestOneElementRangeProof(t *testing.T) { |
|
|
|
if err := tinyTrie.Prove(last, 0, proof); err != nil { |
|
|
|
if err := tinyTrie.Prove(last, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err = VerifyRangeProof(tinyTrie.Hash(), first, last, [][]byte{entry.k}, [][]byte{entry.v}, proof) |
|
|
|
_, _, err = VerifyRangeProof(tinyTrie.Hash(), first, last, [][]byte{entry.k}, [][]byte{entry.v}, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -421,7 +421,7 @@ func TestAllElementsProof(t *testing.T) { |
|
|
|
k = append(k, entries[i].k) |
|
|
|
k = append(k, entries[i].k) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), nil, nil, k, v, nil) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), nil, nil, k, v, nil) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -434,7 +434,7 @@ func TestAllElementsProof(t *testing.T) { |
|
|
|
if err := trie.Prove(entries[len(entries)-1].k, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(entries[len(entries)-1].k, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err = VerifyRangeProof(trie.Hash(), k[0], k[len(k)-1], k, v, proof) |
|
|
|
_, _, err = VerifyRangeProof(trie.Hash(), k[0], k[len(k)-1], k, v, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -449,7 +449,7 @@ func TestAllElementsProof(t *testing.T) { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err = VerifyRangeProof(trie.Hash(), first, last, k, v, proof) |
|
|
|
_, _, err = VerifyRangeProof(trie.Hash(), first, last, k, v, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -482,7 +482,7 @@ func TestSingleSideRangeProof(t *testing.T) { |
|
|
|
k = append(k, entries[i].k) |
|
|
|
k = append(k, entries[i].k) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), common.Hash{}.Bytes(), k[len(k)-1], k, v, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), common.Hash{}.Bytes(), k[len(k)-1], k, v, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -518,7 +518,7 @@ func TestReverseSingleSideRangeProof(t *testing.T) { |
|
|
|
k = append(k, entries[i].k) |
|
|
|
k = append(k, entries[i].k) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), k[0], last.Bytes(), k, v, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), k[0], last.Bytes(), k, v, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -590,7 +590,7 @@ func TestBadRangeProof(t *testing.T) { |
|
|
|
index = mrand.Intn(end - start) |
|
|
|
index = mrand.Intn(end - start) |
|
|
|
vals[index] = nil |
|
|
|
vals[index] = nil |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), first, last, keys, vals, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), first, last, keys, vals, proof) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
t.Fatalf("%d Case %d index %d range: (%d->%d) expect error, got nil", i, testcase, index, start, end-1) |
|
|
|
t.Fatalf("%d Case %d index %d range: (%d->%d) expect error, got nil", i, testcase, index, start, end-1) |
|
|
|
} |
|
|
|
} |
|
|
@ -624,7 +624,7 @@ func TestGappedRangeProof(t *testing.T) { |
|
|
|
keys = append(keys, entries[i].k) |
|
|
|
keys = append(keys, entries[i].k) |
|
|
|
vals = append(vals, entries[i].v) |
|
|
|
vals = append(vals, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, vals, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, vals, proof) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
t.Fatal("expect error, got nil") |
|
|
|
t.Fatal("expect error, got nil") |
|
|
|
} |
|
|
|
} |
|
|
@ -651,7 +651,7 @@ func TestSameSideProofs(t *testing.T) { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), first, last, [][]byte{entries[pos].k}, [][]byte{entries[pos].v}, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), first, last, [][]byte{entries[pos].k}, [][]byte{entries[pos].v}, proof) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
t.Fatalf("Expected error, got nil") |
|
|
|
t.Fatalf("Expected error, got nil") |
|
|
|
} |
|
|
|
} |
|
|
@ -667,7 +667,7 @@ func TestSameSideProofs(t *testing.T) { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(last, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
t.Fatalf("Failed to prove the last node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, _, err = VerifyRangeProof(trie.Hash(), first, last, [][]byte{entries[pos].k}, [][]byte{entries[pos].v}, proof) |
|
|
|
_, _, err = VerifyRangeProof(trie.Hash(), first, last, [][]byte{entries[pos].k}, [][]byte{entries[pos].v}, proof) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
t.Fatalf("Expected error, got nil") |
|
|
|
t.Fatalf("Expected error, got nil") |
|
|
|
} |
|
|
|
} |
|
|
@ -735,7 +735,7 @@ func TestHasRightElement(t *testing.T) { |
|
|
|
k = append(k, entries[i].k) |
|
|
|
k = append(k, entries[i].k) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
v = append(v, entries[i].v) |
|
|
|
} |
|
|
|
} |
|
|
|
_, _, _, hasMore, err := VerifyRangeProof(trie.Hash(), firstKey, lastKey, k, v, proof) |
|
|
|
_, hasMore, err := VerifyRangeProof(trie.Hash(), firstKey, lastKey, k, v, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -768,25 +768,19 @@ func TestEmptyRangeProof(t *testing.T) { |
|
|
|
if err := trie.Prove(first, 0, proof); err != nil { |
|
|
|
if err := trie.Prove(first, 0, proof); err != nil { |
|
|
|
t.Fatalf("Failed to prove the first node %v", err) |
|
|
|
t.Fatalf("Failed to prove the first node %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
db, tr, not, _, err := VerifyRangeProof(trie.Hash(), first, nil, nil, nil, proof) |
|
|
|
db, _, err := VerifyRangeProof(trie.Hash(), first, nil, nil, nil, proof) |
|
|
|
if c.err && err == nil { |
|
|
|
if c.err && err == nil { |
|
|
|
t.Fatalf("Expected error, got nil") |
|
|
|
t.Fatalf("Expected error, got nil") |
|
|
|
} |
|
|
|
} |
|
|
|
if !c.err && err != nil { |
|
|
|
if !c.err && err != nil { |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
t.Fatalf("Expected no error, got %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
// If no error was returned, ensure the returned trie and database contains
|
|
|
|
// If no error was returned, ensure the returned database contains
|
|
|
|
// the entire proof, since there's no value
|
|
|
|
// the entire proof, since there's no value
|
|
|
|
if !c.err { |
|
|
|
if !c.err { |
|
|
|
if err := tr.Prove(first, 0, memorydb.New()); err != nil { |
|
|
|
|
|
|
|
t.Errorf("returned trie doesn't contain original proof: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if memdb := db.(*memorydb.Database); memdb.Len() != proof.Len() { |
|
|
|
if memdb := db.(*memorydb.Database); memdb.Len() != proof.Len() { |
|
|
|
t.Errorf("database entry count mismatch: have %d, want %d", memdb.Len(), proof.Len()) |
|
|
|
t.Errorf("database entry count mismatch: have %d, want %d", memdb.Len(), proof.Len()) |
|
|
|
} |
|
|
|
} |
|
|
|
if not == nil { |
|
|
|
|
|
|
|
t.Errorf("missing notary") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -805,6 +799,8 @@ func TestBloatedProof(t *testing.T) { |
|
|
|
var vals [][]byte |
|
|
|
var vals [][]byte |
|
|
|
|
|
|
|
|
|
|
|
proof := memorydb.New() |
|
|
|
proof := memorydb.New() |
|
|
|
|
|
|
|
// In the 'malicious' case, we add proofs for every single item
|
|
|
|
|
|
|
|
// (but only one key/value pair used as leaf)
|
|
|
|
for i, entry := range entries { |
|
|
|
for i, entry := range entries { |
|
|
|
trie.Prove(entry.k, 0, proof) |
|
|
|
trie.Prove(entry.k, 0, proof) |
|
|
|
if i == 50 { |
|
|
|
if i == 50 { |
|
|
@ -812,12 +808,15 @@ func TestBloatedProof(t *testing.T) { |
|
|
|
vals = append(vals, entry.v) |
|
|
|
vals = append(vals, entry.v) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// For reference, we use the same function, but _only_ prove the first
|
|
|
|
|
|
|
|
// and last element
|
|
|
|
want := memorydb.New() |
|
|
|
want := memorydb.New() |
|
|
|
trie.Prove(keys[0], 0, want) |
|
|
|
trie.Prove(keys[0], 0, want) |
|
|
|
trie.Prove(keys[len(keys)-1], 0, want) |
|
|
|
trie.Prove(keys[len(keys)-1], 0, want) |
|
|
|
|
|
|
|
|
|
|
|
_, _, notary, _, _ := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, vals, proof) |
|
|
|
db, _, _ := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, vals, proof) |
|
|
|
if used := notary.Accessed().(*memorydb.Database); used.Len() != want.Len() { |
|
|
|
// The db should not contain anything of the bloated data
|
|
|
|
|
|
|
|
if used := db.(*memorydb.Database); used.Len() != want.Len() { |
|
|
|
t.Fatalf("notary proof size mismatch: have %d, want %d", used.Len(), want.Len()) |
|
|
|
t.Fatalf("notary proof size mismatch: have %d, want %d", used.Len(), want.Len()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -922,13 +921,40 @@ func benchmarkVerifyRangeProof(b *testing.B, size int) { |
|
|
|
|
|
|
|
|
|
|
|
b.ResetTimer() |
|
|
|
b.ResetTimer() |
|
|
|
for i := 0; i < b.N; i++ { |
|
|
|
for i := 0; i < b.N; i++ { |
|
|
|
_, _, _, _, err := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, values, proof) |
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, values, proof) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
b.Fatalf("Case %d(%d->%d) expect no error, got %v", i, start, end-1, err) |
|
|
|
b.Fatalf("Case %d(%d->%d) expect no error, got %v", i, start, end-1, err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkVerifyRangeNoProof10(b *testing.B) { benchmarkVerifyRangeNoProof(b, 100) } |
|
|
|
|
|
|
|
func BenchmarkVerifyRangeNoProof500(b *testing.B) { benchmarkVerifyRangeNoProof(b, 500) } |
|
|
|
|
|
|
|
func BenchmarkVerifyRangeNoProof1000(b *testing.B) { benchmarkVerifyRangeNoProof(b, 1000) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func benchmarkVerifyRangeNoProof(b *testing.B, size int) { |
|
|
|
|
|
|
|
trie, vals := randomTrie(size) |
|
|
|
|
|
|
|
var entries entrySlice |
|
|
|
|
|
|
|
for _, kv := range vals { |
|
|
|
|
|
|
|
entries = append(entries, kv) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sort.Sort(entries) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var keys [][]byte |
|
|
|
|
|
|
|
var values [][]byte |
|
|
|
|
|
|
|
for _, entry := range entries { |
|
|
|
|
|
|
|
keys = append(keys, entry.k) |
|
|
|
|
|
|
|
values = append(values, entry.v) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
b.ResetTimer() |
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ { |
|
|
|
|
|
|
|
_, _, err := VerifyRangeProof(trie.Hash(), keys[0], keys[len(keys)-1], keys, values, nil) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
b.Fatalf("Expected no error, got %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func randomTrie(n int) (*Trie, map[string]*kv) { |
|
|
|
func randomTrie(n int) (*Trie, map[string]*kv) { |
|
|
|
trie := new(Trie) |
|
|
|
trie := new(Trie) |
|
|
|
vals := make(map[string]*kv) |
|
|
|
vals := make(map[string]*kv) |
|
|
|