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

Add deep trees for IAVL, for fraud proofs and stateless execution #1

Closed
9 tasks done
musalbas opened this issue Sep 20, 2022 · 1 comment
Closed
9 tasks done
Assignees
Labels

Comments

@musalbas
Copy link

musalbas commented Sep 20, 2022

This should be done in a separate branch eg (deepiavl), as we shouldn't assume this will be merged into iavl upstream.

How to add deep trees:

  1. Add a DeepTree (deep_tree.go) that inherits or extends MutableTree
  2. Modify this Verify function and the functions it calls to add a DeepTree instance as an (optional) parameter, all the way down the stack into computeRootHash
  3. In pathWithLeaf.computeRootHash and pathToLeaf.computeRootHash, every time a hash for a leaf or a node is computed, add it to to the nodeCache in the nodeDB of the MutableTree of the DeepTree (or your own custom cache/map), by creating new Node() object with nil left and right nodes
  4. After a range proof is verified with Verify(), DeepTree should loop through all the the entries in nodeCache to populate Node objects with pointers to their respective left and right Node objects, where available (you can also do this step inside computeRootHash instead of doing it after, as well)
  5. You can now call Set() in MutableTree with the root node to update values in the deep tree (you'll need to set the ImmutableTree's root first), and call Hash() in MutableTree's ImmutableTree to get the root hash

Tracking:

@musalbas
Copy link
Author

musalbas commented Sep 21, 2022

Based on https://github.com/cosmos/iavl/blob/master/docs/proof/proof.md I think some extra steps will also be needed:

  1. We might need to modify the proof so that it includes the values of the sibling nodes, not just the hashes, as we need to know those in order for Set() to know if it needs to do any re-balancing operations, as the size of nodes are in their values, not hashes. I think this may up to ~double the hashes in the proof in the worse case. I think this is fine because we can optimize this later on as we only need to include these nodes for insertions and deletions, not updates (as updates don't need a rebalance), and also because afaik only up to one rebalancing operation needs to be done per insert/delete, so we only need to provide the nodes up to the point where rebalancing is done. See https://github.com/cosmos/iavl/blob/f50272dc2b8f521ea1fe4db3d9b67913a42cded3/node.go#L508
  2. When doing step 4, we also need to populate the key field of the inner nodes with the highest key in its left branch that we know of (https://github.com/cosmos/iavl/blob/master/docs/node/node.md).

This tool is also pretty handy for visualization: https://www.cs.usfca.edu/~galles/visualization/AVLtree.html

@Manav-Aggarwal Manav-Aggarwal linked a pull request Oct 1, 2022 that will close this issue
6 tasks
@tzdybal tzdybal closed this as completed Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants