Skip to content

Commit c940fff

Browse files
Manav-AggarwaltzdybalMSeveycool-developecolin-axner
authored
feat: Rebase Deep Subtree on top of 0.19.x (#25)
* feat: Deep tree structure with Updates (#13) * ICS23-style approach for DeepSubTree creation * Fix deepsubtree, all checks pass * Update documentation for deep subtrees * Fix deepsubtree to accomodate left/right paths both * Refactor test code * Refactor TestDeepSubtreeStepByStep * Address comments * Refactor code * Disable gocritic and unused * Add description * Refactor code to check err in Set * Modify traversal conditions to be clearer * feat: build deep subtree from ICS23 inclusion proofs (#9) * feat: build deep subtree from ICS23 inclusion proofs * feat: handle non-existence proofs * linter: goimports deepsubtree.go * refactor: addExistenceProofProof -> addExistenceProof * fix: un-hardcode size of byte array * Add more comments * Refactor ndb.Commit call outside for loop * verify that in the case that dst.root != nil that the root node hash matches the provided hash and check dst.root != nil first * Add strings and use strings.Repeat * Delete addPath and AddPath * Remove print statements * Refactor recomputeHash usage Co-authored-by: Matthew Sevey <mjsevey@gmail.com> * return err directly Co-authored-by: Matthew Sevey <mjsevey@gmail.com> * Address linting checks * Use tm-db instead of cosmos-db * Fix linter * Update comment Co-authored-by: Matthew Sevey <mjsevey@gmail.com> * Add error checking for node hash * turn lengthByte into a const * Refactor linkNode * Update comment Co-authored-by: Tomasz Zdybał <tomek@zdybal.lap.pl> Co-authored-by: Matthew Sevey <mjsevey@gmail.com> * feat: Support Adds in a Deep Subtree (#8) * ICS23-style approach for DeepSubTree creation * Fix deepsubtree, all checks pass * Update documentation for deep subtrees * Fix deepsubtree to accomodate left/right paths both * Refactor test code * Refactor TestDeepSubtreeStepByStep * Address comments * Refactor code * Disable gocritic and unused * Add description * Refactor code to check err in Set * Modify traversal conditions to be clearer * feat: build deep subtree from ICS23 inclusion proofs (#9) * feat: build deep subtree from ICS23 inclusion proofs * feat: handle non-existence proofs * linter: goimports deepsubtree.go * refactor: addExistenceProofProof -> addExistenceProof * fix: un-hardcode size of byte array * Add more comments * Refactor ndb.Commit call outside for loop * verify that in the case that dst.root != nil that the root node hash matches the provided hash and check dst.root != nil first * Add strings and use strings.Repeat * Delete addPath and AddPath * Remove print statements * Refactor recomputeHash usage Co-authored-by: Matthew Sevey <mjsevey@gmail.com> * return err directly Co-authored-by: Matthew Sevey <mjsevey@gmail.com> * Address linting checks * Use tm-db instead of cosmos-db * Fix linter * Add test to check add operation in deepsubtree: WIP * Add insert key functionality WIP * Try replicating non-inclusion proofs * Add sibling nodes to nonExistenceProofs * Refactor test code * Finish adding add functionality to dst * Add Remove functionality to dst * Fix linting errors * Fix GetSiblingNode * Remove more print statements * Add comment for each case in recursive set * Change which methods are exported and document exported methods * feat: Support Empty Hashes and Add constructor (#11) * Export siblings * Add deepsubtree constructor * Support empty root hashes * Use working hash instead of root.hash * Use tm-db instead of cosmos-db * Return nil in BuildTree * Address comments * Address more comments Co-authored-by: Tomasz Zdybał <tomek@zdybal.lap.pl> Co-authored-by: Matthew Sevey <mjsevey@gmail.com> * Add randomized tests for adding/removing keys (#16) * Add go fuzz tests * Add membership proof for existing keys * Build tree after adding membership proof * Make batch add fuzz tests work * Do not commit version twice for dst * Save version out of dst.Set condition * Set rootHash to workingHash * Fix edge cases * Refactor DST Non-Existence Proof * Change cacheSize * Add test data and sibling nodes for each node in path * Fix GetSiblingNodes * Add more test data * testing: fuzz: failing test case * Use set for keys * Add more test data * Refactor existence proofs code * Add required info for remove operation * Add children of siblings as well * Remove debug code * Add testdata that breaks current code * Fix bug * Add failing testcase * Add breaking testcase * IAVL with tracing * Fuzz tests pass * Refactor tracing code * Remove redundant code * Remove working hash in calls to AddExistenceProof * Clean up flag * Make build tree a private method * Add back whitespace in node.go * Add new ci for fuzz * Refactor more * Refactor out getKey method * Change name to reapInclusionProofs * Refactor set and remove in DST * Factor out add existence proofs from Remove DST for consistency with Set * Refactor into testContext * Clean up setInDST Co-authored-by: Tomasz Zdybał <tomek@zdybal.lap.pl> * Add tracing to Trees and Deep Subtrees (#18) * Add go fuzz tests * Add membership proof for existing keys * Build tree after adding membership proof * Make batch add fuzz tests work * Do not commit version twice for dst * Save version out of dst.Set condition * Set rootHash to workingHash * Fix edge cases * Refactor DST Non-Existence Proof * Change cacheSize * Add test data and sibling nodes for each node in path * Fix GetSiblingNodes * Add more test data * testing: fuzz: failing test case * Use set for keys * Add more test data * Refactor existence proofs code * Add required info for remove operation * Add children of siblings as well * Remove debug code * Add testdata that breaks current code * Fix bug * Add failing testcase * Add breaking testcase * IAVL with tracing * Fuzz tests pass * Refactor tracing code * Remove redundant code * Remove working hash in calls to AddExistenceProof * Clean up flag * Make build tree a private method * Add back whitespace in node.go * Add new ci for fuzz * Refactor more * Refactor out getKey method * Change name to reapInclusionProofs * Refactor set and remove in DST * Factor out add existence proofs from Remove DST for consistency with Set * Refactor into testContext * Clean up setInDST * Add method for get * Export methods * Add witness data to deep subtree * Verify operation in witness data * Refactor and verify operation for get and remove * Add set witness data * Add tracing to tree * add getter for witness data * Verify existence proofs in dst * Cleanup * Reset witness data on tracing enabled * Add node to keysAccessed even not in cache * Add initial root hash * Refactor GetInitialRootHash * Modify GetInitialRootHash * Add test data * Add get to dst tests: fails right now * Refactor and add tracing for root key as well * Add docs * Add more docs * Update comments * Update log message Co-authored-by: Tomasz Zdybał <tomek@zdybal.lap.pl> * allocate length Co-authored-by: Tomasz Zdybał <tomek@zdybal.lap.pl> * fix: remove `RangeProofs` (cosmos#586) Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> * Update go.mod file * Add new line at end of .golangci.yml Co-authored-by: Tomasz Zdybał <tomek@zdybal.lap.pl> Co-authored-by: Matthew Sevey <mjsevey@gmail.com> Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com>
1 parent 21ea96e commit c940fff

42 files changed

Lines changed: 1583 additions & 4556 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
run: |
3636
go test ./... -mod=readonly -timeout 5m -short -race -coverprofile=coverage.txt -covermode=atomic
3737
go test ./... -mod=readonly -timeout 5m
38+
go test -fuzz=. -fuzztime=1m
3839
GOARCH=386 go test ./... -mod=readonly -timeout 5m
3940
- uses: codecov/codecov-action@v3.1.0
4041
with:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
- [#599](https://github.com/cosmos/iavl/pull/599) Populate ImmutableTree creation in copy function with missing field
1414
- [#589](https://github.com/cosmos/iavl/pull/589) Wrap `tree.addUnsavedRemoval()` with missing `if !tree.skipFastStorageUpgrade` statement
15+
- [#586](https://github.com/cosmos/iavl/pull/586) Remove the `RangeProof` and refactor the ics23_proof to use the internal methods.
1516

1617
## 0.19.3 (October 8, 2022)
1718

basic_test.go

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,17 @@ func TestProof(t *testing.T) {
513513

514514
// Now for each item, construct a proof and verify
515515
tree.Iterate(func(key []byte, value []byte) bool {
516-
value2, proof, err := tree.GetWithProof(key)
516+
proof, err := tree.GetMembershipProof(key)
517517
assert.NoError(t, err)
518-
assert.Equal(t, value, value2)
519-
if assert.NotNil(t, proof) {
520-
hash, err := tree.WorkingHash()
521-
require.NoError(t, err)
522-
verifyProof(t, proof, hash)
518+
assert.Equal(t, value, proof.GetExist().Value)
519+
res, err := tree.VerifyMembership(proof, key)
520+
assert.NoError(t, err)
521+
value2, err := tree.ImmutableTree.Get(key)
522+
assert.NoError(t, err)
523+
if value2 != nil {
524+
assert.True(t, res)
525+
} else {
526+
assert.False(t, res)
523527
}
524528
return false
525529
})
@@ -534,11 +538,8 @@ func TestTreeProof(t *testing.T) {
534538
assert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", hex.EncodeToString(hash))
535539

536540
// should get false for proof with nil root
537-
value, proof, err := tree.GetWithProof([]byte("foo"))
538-
assert.Nil(t, value)
539-
assert.Nil(t, proof)
540-
assert.Error(t, proof.Verify([]byte(nil)))
541-
assert.NoError(t, err)
541+
_, err = tree.GetProof([]byte("foo"))
542+
require.Error(t, err)
542543

543544
// insert lots of info and store the bytes
544545
keys := make([][]byte, 200)
@@ -551,27 +552,18 @@ func TestTreeProof(t *testing.T) {
551552
tree.SaveVersion()
552553

553554
// query random key fails
554-
value, proof, err = tree.GetWithProof([]byte("foo"))
555-
assert.Nil(t, value)
556-
assert.NotNil(t, proof)
557-
assert.NoError(t, err)
558-
hash, err = tree.Hash()
559-
assert.NoError(t, err)
560-
assert.NoError(t, proof.Verify(hash))
561-
assert.NoError(t, proof.VerifyAbsence([]byte("foo")))
555+
_, err = tree.GetMembershipProof([]byte("foo"))
556+
assert.Error(t, err)
562557

563558
// valid proof for real keys
564-
root, err := tree.WorkingHash()
565-
assert.NoError(t, err)
566559
for _, key := range keys {
567-
value, proof, err := tree.GetWithProof(key)
560+
proof, err := tree.GetMembershipProof(key)
568561
if assert.NoError(t, err) {
569562
require.Nil(t, err, "Failed to read proof from bytes: %v", err)
570-
assert.Equal(t, key, value)
571-
err := proof.Verify(root)
572-
assert.NoError(t, err, "#### %v", proof.String())
573-
err = proof.VerifyItem(key, key)
574-
assert.NoError(t, err, "#### %v", proof.String())
563+
assert.Equal(t, key, proof.GetExist().Value)
564+
res, err := tree.VerifyMembership(proof, key)
565+
require.NoError(t, err)
566+
require.True(t, res)
575567
}
576568
}
577569
}

0 commit comments

Comments
 (0)