-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
A reminder that you'll likely need to modify the proofs themselves too as mentioned here, eg adding a new optional field for |
proof_test.go
Outdated
// nodes, err := dst.ndb.nodes() | ||
// require.Nil(err) | ||
// for _, node := range nodes { | ||
// pnode, _ := dst.ndb.GetNode(node.hash) | ||
// print(pnode.hash) | ||
// print("\n") | ||
// } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
* use `NoError` instead of `NotNil` for errors * un-hardcode loop counter
…root mismatch errors
… left branch that we know of
@@ -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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Thanks for sharing an example, will add one. |
7b89c40
to
5f062cb
Compare
proto/iavl/proof.proto
Outdated
@@ -32,11 +32,13 @@ message ProofInnerNode { | |||
int64 version = 3; | |||
bytes left = 4; | |||
bytes right = 5; | |||
Node leftNode = 6; |
There was a problem hiding this comment.
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?
This reverts commit 718defe.
5f062cb
to
c31bff8
Compare
First step of implementation is to build deep tree structure. As pointed out by @musalbas in #1, this can be done by modifying
RangeProof
sVerify
function.Definition of done:
DeepTree
structure is introducedVerify
functions are modified to collect required nodesNode
objects)ImmutableTree
is set properlyProofInnerNode
) with the highest key in its left branch that we know ofProofLeafNode
Resolves #2.