Sapling commitment tree#68
Conversation
|
Addressed @ebfull's review comments. |
67718b9 to
8ce260c
Compare
|
Rebased on master to fix trivial merge conflict. |
8ce260c to
ad460b3
Compare
|
Force-pushed again to fix an indirect merge conflict. |
|
The failure is in a doctest, due to (I believe) using syntax that was introduced in Rust 1.32, while this branch is still testing with Rust 1.31. If we merge #69 first, then the minimum Rust version will be 1.32, and this PR should pass. |
Make PublicKey inner Point public so that we can use it during zk-SNARK verification
00f5345 to
e6dc54d
Compare
|
Force-pushed the last two commits to fix the doctest on older Rust versions (was missing an |
Eirik0
left a comment
There was a problem hiding this comment.
ACK. My comments are non-blocking.
| } | ||
| } | ||
|
|
||
| /// Returns the number of notes in the tree. |
There was a problem hiding this comment.
I mean notes, since I'm referring to the leaf nodes (which are the appended cmu values from notes) rather than all nodes.
There was a problem hiding this comment.
I suggest saying "leaf nodes", since it's possible we or someone else may want to reuse this code for something other than the note commitment tree (and nothing else about it depends on notes).
| CommitmentTree { | ||
| left: None, | ||
| right: None, | ||
| parents: vec![], |
There was a problem hiding this comment.
Would it be more correct to call this ancestors instead of parents?
There was a problem hiding this comment.
Eh, I'm fine leaving this as-is for now, given that this is what we call it in the zcashd implementation. I'm happy to be outvoted however.
There was a problem hiding this comment.
I was a little confused at first, but it's not too hard to figure out what's going on.
There was a problem hiding this comment.
I would prefer ancestors; let's file a ticket to change this in both C++ and Rust. (Does not block.)
f668e39 to
9b01585
Compare
|
Rebased on master to fix some trivial merge conflicts in module declarations and imports. |
This makes the merkle_tree module properly generic over the tree hash. It still hard-codes a depth 32 tree, because Rust doesn't yet support generic sizes, and we are unlikely to need to alter the tree depth in future circuit changes.
When sapling-crypto is refactored, the zcash_primitives::sapling constant would become the canonical one.
9b01585 to
07dbfbe
Compare
|
Rebased on master to fix trivial merge conflicts. |
| } | ||
| } | ||
|
|
||
| /// Returns the number of notes in the tree. |
There was a problem hiding this comment.
I suggest saying "leaf nodes", since it's possible we or someone else may want to reuse this code for something other than the note commitment tree (and nothing else about it depends on notes).
| CommitmentTree { | ||
| left: None, | ||
| right: None, | ||
| parents: vec![], |
There was a problem hiding this comment.
I would prefer ancestors; let's file a ticket to change this in both C++ and Rust. (Does not block.)
| self.parents.iter().enumerate().fold( | ||
| match (self.left, self.right) { | ||
| (None, None) => 0, | ||
| (Some(_), None) | (None, Some(_)) => 1, |
There was a problem hiding this comment.
Is (None, Some(_)) ever possible?
There was a problem hiding this comment.
Technically no; tree appending is lazy, so the state transition is:
(None, None) -> (Some(_), None) <--> (Some(_), Some(_))
I'll make it explicitly unreachable!().
| "00000002b02310f2e087e55bfd07ef5e242e3b87ee5d00c9ab52f61e6bd42542f93a6f55225747f3b5d5dab4e5a424f81f85c904ff43286e0f3fd07ef0b8c6a627b1145800", | ||
| "01b02310f2e087e55bfd07ef5e242e3b87ee5d00c9ab52f61e6bd42542f93a6f55000001225747f3b5d5dab4e5a424f81f85c904ff43286e0f3fd07ef0b8c6a627b1145800", | ||
| "00000002b02310f2e087e55bfd07ef5e242e3b87ee5d00c9ab52f61e6bd42542f93a6f55225747f3b5d5dab4e5a424f81f85c904ff43286e0f3fd07ef0b8c6a627b1145801017c3ea01a6e3a3d90cf59cd789e467044b5cd78eb2c84cc6816f960746d0e036c0000", | ||
| "01b02310f2e087e55bfd07ef5e242e3b87ee5d00c9ab52f61e6bd42542f93a6f55000001225747f3b5d5dab4e |
There was a problem hiding this comment.
I did not check the test vectors.
fix: nullifier checks tx 2 and 3
Implementation is similar to the one in
zcashdfor reviewability. Test vectors are taken fromzcashd.