-
Notifications
You must be signed in to change notification settings - Fork 120
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
ZIP-221: integrate MMR tree from librustcash (without Orchard) #2227
Conversation
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.
This all looks good so far, just a bunch of tweaks and suggestions.
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've addressed most of the issues; still need to change to return Result
where needed
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.
Just some quick suggestions before I tackle the larger questions on the PR.
In the primitives module, it's ok to return a We'll wrap it in our own error types in the calling code in
Yes, let's do separate PRs for each ticket. And any changes within a ticket that are easily split up. But if there are any tests you can run on this code, let's add them in this PR. The Here are some tests you can do:
For primitives, let's match the method names from the library we're wrapping.
Let's put primitive operations in
The other changes should go in
This is the type that will be cloned for each chain in the We might want a tuple struct wrapper around
Here's our current serialization design, you should update it in the serialization PR: You'll probably want to serialize it with We can calculate |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Another round of fixes. I had to make a small refactoring because I was mixing up Node
and Entry
. An Entry
contains a Node
and the indices of the left/right children, and Tree::new
requires Entry
s and not Node
s.
I've created a wrapper for Entry
that stores it encoded as a buffer vector. However that may be not needed (you can derive the children indices, no need to store them), but for simplicity I chose this route for now.
Tests are not complete either - see next comment I'll post
To do that I'll need the Sapling root for that block, not sure how I'll get that. I'll ask in the chat. |
The final sapling roots for all post-sapling test vectors are in PR #2243 |
07cec85
to
1429711
Compare
Co-authored-by: teor <teor@riseup.net>
Co-authored-by: teor <teor@riseup.net>
1429711
to
ea7e528
Compare
ea7e528
to
2bcfbb1
Compare
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.
This looks good, just a few minor changes to tidy up the code.
Co-authored-by: teor <teor@riseup.net>
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.
New round of improvements!
FYI I've implemented the NU5 tree format: zcash/librustzcash#401 (feedback welcome, particularly re: how it interacts with this PR). |
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.
This looks like a good API, let's merge so we can start work on the state changes.
@conradoplg do you think we need to make any changes now to prepare for the librustzcash
Orchard changes?
https://github.com/zcash/librustzcash/pull/401/files
We can leave all the changes to the Orchard-specific PR, unless they impact the state design.
@teor2345 I believe that the only changes to the API of this module will be adding a type parameter to |
Motivation
ZIP-221 specifies that the
hashFinalSaplingRoot
field of the header is a commitment to the root of a MMR tree, therefore Zebra must support it.Solution
librustzcash has code for that in
zcash_history
, though not for the whole logic. It has a Tree class that contains the logic for adding / removing nodes to the tree, but it's not supposed to be used as a long-term data structure - zcashd instantiates it every time a node is added or removed.This PR creates a wrapper over it.
The code in this pull request has:
(will add tests after moving from draft)
Review
@teor2345 will probably want to review it.
This draft PR only adds the wrapping over librustzcash; it still does not handle the logic to keep track of what should be stored.
Draft PR points that I'd like feedback on:
expects
OK? If an error should be returned, how should I wrap it? (I guess I shouldn't return a librustzcash error. I tried usingthiserror
but couldn't get it to work, so I thought it would be better to confirm which approach to use beforehand)push
/pop
(similar toVec
)zebra_chain
?Questions about the design in #2132
Related Issues
Part of #2132
Follow Up Work
Needs Orchard support which is blocked by librustzcash: zcash/librustzcash#368