Skip to content

Sapling commitment tree#68

Merged
str4d merged 14 commits into
zcash:masterfrom
str4d:sapling-commitment-tree
Jul 15, 2019
Merged

Sapling commitment tree#68
str4d merged 14 commits into
zcash:masterfrom
str4d:sapling-commitment-tree

Conversation

@str4d
Copy link
Copy Markdown
Contributor

@str4d str4d commented Mar 7, 2019

Implementation is similar to the one in zcashd for reviewability. Test vectors are taken from zcashd.

Comment thread zcash_primitives/src/merkle_tree.rs Outdated
Comment thread zcash_primitives/src/merkle_tree.rs Outdated
Comment thread zcash_primitives/src/merkle_tree.rs Outdated
Comment thread zcash_primitives/src/merkle_tree.rs Outdated
Comment thread zcash_primitives/src/merkle_tree.rs Outdated
Comment thread zcash_primitives/src/merkle_tree.rs Outdated
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Mar 19, 2019

Addressed @ebfull's review comments.

@ebfull ebfull self-requested a review March 26, 2019 23:14
@str4d str4d force-pushed the sapling-commitment-tree branch from 67718b9 to 8ce260c Compare April 5, 2019 19:56
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Apr 5, 2019

Rebased on master to fix trivial merge conflict.

@str4d str4d force-pushed the sapling-commitment-tree branch from 8ce260c to ad460b3 Compare April 5, 2019 19:59
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Apr 5, 2019

Force-pushed again to fix an indirect merge conflict.

@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Apr 16, 2019

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.

bitcartel pushed a commit to bitcartel/librustzcash that referenced this pull request May 16, 2019
Make PublicKey inner Point public so that we can use it during zk-SNARK verification
@str4d str4d force-pushed the sapling-commitment-tree branch from 00f5345 to e6dc54d Compare May 29, 2019 17:54
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented May 29, 2019

Force-pushed the last two commits to fix the doctest on older Rust versions (was missing an extern crate).

@mms710 mms710 requested review from Eirik0 and daira May 30, 2019 17:12
Copy link
Copy Markdown
Contributor

@Eirik0 Eirik0 left a comment

Choose a reason for hiding this comment

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

ACK. My comments are non-blocking.

Comment thread zcash_primitives/src/merkle_tree.rs Outdated
Comment thread zcash_primitives/src/merkle_tree.rs Outdated
}
}

/// Returns the number of notes in the tree.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

notes -> nodes (?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean notes, since I'm referring to the leaf nodes (which are the appended cmu values from notes) rather than all nodes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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![],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be more correct to call this ancestors instead of parents?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was a little confused at first, but it's not too hard to figure out what's going on.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer ancestors; let's file a ticket to change this in both C++ and Rust. (Does not block.)

Comment thread zcash_primitives/src/merkle_tree.rs Outdated
Comment thread zcash_primitives/src/serialize.rs
Copy link
Copy Markdown
Contributor

@Eirik0 Eirik0 left a comment

Choose a reason for hiding this comment

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

utACK

@str4d str4d force-pushed the sapling-commitment-tree branch from f668e39 to 9b01585 Compare June 10, 2019 19:35
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Jun 10, 2019

Rebased on master to fix some trivial merge conflicts in module declarations and imports.

Copy link
Copy Markdown
Contributor

@Eirik0 Eirik0 left a comment

Choose a reason for hiding this comment

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

reACK

str4d added 6 commits July 10, 2019 13:53
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.
@str4d str4d force-pushed the sapling-commitment-tree branch from 9b01585 to 07dbfbe Compare July 10, 2019 17:54
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Jul 10, 2019

Rebased on master to fix trivial merge conflicts.

Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

ut(ACK+cov)

Comment thread zcash_primitives/src/merkle_tree.rs Outdated
}
}

/// Returns the number of notes in the tree.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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![],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer ancestors; let's file a ticket to change this in both C++ and Rust. (Does not block.)

Comment thread zcash_primitives/src/merkle_tree.rs Outdated
self.parents.iter().enumerate().fold(
match (self.left, self.right) {
(None, None) => 0,
(Some(_), None) | (None, Some(_)) => 1,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is (None, Some(_)) ever possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did not check the test vectors.

@str4d str4d merged commit 5e3409e into zcash:master Jul 15, 2019
@str4d str4d deleted the sapling-commitment-tree branch July 15, 2019 14:52
Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

ACK changes in 504c3ea.

@str4d str4d added this to the v0.1.0 milestone Aug 22, 2019
greg0x pushed a commit to valargroup/librustzcash that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants