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

Build deep tree structure by altering Verify method #3

Closed
wants to merge 26 commits into from

Conversation

Manav-Aggarwal
Copy link
Member

@Manav-Aggarwal Manav-Aggarwal commented Sep 25, 2022

First step of implementation is to build deep tree structure. As pointed out by @musalbas in #1, this can be done by modifying RangeProofs Verify function.

Definition of done:

  • DeepTree structure is introduced
  • Verify functions are modified to collect required nodes
  • Tree structure is properly linked (by pointers in Node objects)
  • Root of underlying ImmutableTree is set properly
  • Key field of the inner nodes (ProofInnerNode) with the highest key in its left branch that we know of
  • Modified proof to include values on top of the already existing hashes of values in ProofLeafNode

Resolves #2.

@Manav-Aggarwal Manav-Aggarwal linked an issue Sep 25, 2022 that may be closed by this pull request
6 tasks
@Manav-Aggarwal Manav-Aggarwal changed the title Add Deep Subtrees Build deep tree structure by altering Verify method Sep 25, 2022
@Manav-Aggarwal Manav-Aggarwal self-assigned this Sep 25, 2022
@Manav-Aggarwal Manav-Aggarwal marked this pull request as ready for review September 25, 2022 04:57
@Manav-Aggarwal Manav-Aggarwal added the enhancement New feature or request label Sep 25, 2022
@musalbas
Copy link

A reminder that you'll likely need to modify the proofs themselves too as mentioned here, eg adding a new optional field for deepnodes or similar to include nodes needed when appending or deleting from a deep tree: #1 (comment)

proof_test.go Outdated
Comment on lines 259 to 265
// nodes, err := dst.ndb.nodes()
// require.Nil(err)
// for _, node := range nodes {
// pnode, _ := dst.ndb.GetNode(node.hash)
// print(pnode.hash)
// print("\n")
// }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out? What purpose does this serve?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, this was being used while debugging. Removed it

@tzdybal tzdybal marked this pull request as draft September 27, 2022 13:49
@Manav-Aggarwal Manav-Aggarwal marked this pull request as ready for review October 1, 2022 10:30
@Manav-Aggarwal Manav-Aggarwal linked an issue Oct 1, 2022 that may be closed by this pull request
9 tasks
@@ -472,6 +518,7 @@ func (t *ImmutableTree) getRangeProof(keyStart, keyEnd []byte, limit int) (proof
h := sha256.Sum256(node.value)
leaves = append(leaves, ProofLeafNode{
Key: node.key,
Value: node.value,
Copy link

@musalbas musalbas Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the values for the leaf nodes? I believe you need the values for the sibling inner nodes for rebalancing, rather than leaf nodes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I misinterpreted it to mean values of the node, not just the valueHash. I'll add the values of the leftNode and rightNode in ProofInnerNode in addition to the already existing leftHash and rightHash

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify I believe we need the preimage of sibling inner nodes, not their hashes, to get their "size" field to enable set() to do rebalancing. This is why doing the full test I suggested below will be important - as I'm not sure sets will work right now as they don't have the data needed to do rebalancing.

@musalbas
Copy link

musalbas commented Oct 2, 2022

Is there a test for updating and deleting from the deepsubtree and checking that it returns the correct roots? Something like this: https://ethresear.ch/t/data-availability-proof-friendly-state-tree-transitions/1453/23

@@ -509,8 +556,9 @@ func (t *ImmutableTree) getRangeProof(keyStart, keyEnd []byte, limit int) (proof
Height: node.subtreeHeight,
Size: node.size,
Version: node.version,
Left: nil,
Right: node.rightHash,
// Need this information to know where we came from while constructing a DeepSubTree
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should not be necessary to send over the wire. You should be able to compute this locally, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried computing it locally earlier, and reproduced it again here: https://github.com/celestiaorg/iavl/pull/4/files

However, in computeRootHash inside PathToLeaf, the hash computed through pin.Hash(hash) is not always the same as what pin.Left contains and that leads to inconsistent hashing. Found removing this optimization to work, so incorporated it for now.

Please correct me if there's a different way you can think of/something obvious I'm missing here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If pin.Hash(hash) returns different things than pin.Left then shouldn't the Merkle proof be impossible to verify in the first place? I think something doesn't add up.

@Manav-Aggarwal
Copy link
Member Author

Is there a test for updating and deleting from the deepsubtree and checking that it returns the correct roots? Something like this: https://ethresear.ch/t/data-availability-proof-friendly-state-tree-transitions/1453/23

Thanks for sharing an example, will add one.

@@ -32,11 +32,13 @@ message ProofInnerNode {
int64 version = 3;
bytes left = 4;
bytes right = 5;
Node leftNode = 6;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to add generic pointers in ProtoBuf?

@tzdybal
Copy link
Member

tzdybal commented Oct 31, 2022

This was a great primer for further work, enabling deep understanding of IAVL internals, but now it's obsolete.
See: #5, #9.

@tzdybal tzdybal closed this Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create deep tree structure using an ICS23-style approach: Updates
4 participants