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

Impl (Add|Sub)(Assign) for ValueCommitment #1105

Merged
merged 7 commits into from
Oct 7, 2020
Merged

Conversation

dconnolly
Copy link
Contributor

Needed for computing the transaction binding validating key

image

@dconnolly dconnolly added NU-1 Sapling Network Upgrade: Sapling specific tasks A-rust Area: Updates to Rust code labels Sep 29, 2020
@dconnolly dconnolly added this to the Validate transactions. milestone Sep 29, 2020
@dconnolly dconnolly requested a review from a team September 29, 2020 00:07
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Looks good, but I don't understand the cryptography enough to know if it works.

Let's add a few quick tests?

@dconnolly dconnolly requested a review from teor2345 October 2, 2020 03:13
@dconnolly dconnolly requested a review from yaahc October 3, 2020 01:49
]),
);

let identity = ValueCommitment(jubjub::AffinePoint::identity());
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move the identity to the top to be consistent with the other tests.

0x0000_0000_0000_0000,
0x0000_0000_0000_0000,
]),
));
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to pick this point or it is just a random point in the curve? Maybe some comment explaining why it was selected if there is any reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a known point on the curve, I just needed any known point, this happens to be the generator of the curve because it's hardcoded into jubjub.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about making the point a constant outside the individual tests but inside mod tests { so we can add a comment explaining this is a known point that it is also the generator ?

yaahc
yaahc previously approved these changes Oct 5, 2020
Copy link
Contributor

@yaahc yaahc left a comment

Choose a reason for hiding this comment

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

Can't really review the crypto but the rust aspects look good to me

@@ -200,13 +241,22 @@ impl ValueCommitment {
///
/// https://zips.z.cash/protocol/protocol.pdf#concretehomomorphiccommit
#[allow(non_snake_case)]
pub fn new<T>(csprng: &mut T, value: Amount<NonNegative>) -> Self
pub fn randomized<T>(csprng: &mut T, value: Amount) -> Self
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for the new function in the context of this PR ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This snuck over into this PR from the WIP over here: #1100

Comment on lines 280 to 282
// TODO: These generator points can be generated once somewhere else to
// avoid having to recompute them on every new commitment.
let V = find_group_hash(*b"Zcash_cv", b"v");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make these into a lazy_static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately lazy_static doesn't quite do what we want:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, so there's a trick here… you have to Deref the struct created by the lazy_static macro. (Confusingly, the struct has the same name as the variable it replaces, but is its own unique type.)

Sometimes, taking the struct as a reference using &V works. But it seems like V.as_ref() is more reliable:
https://github.com/ZcashFoundation/zebra/pull/1116/files#diff-bc19effbc9086e335d897caab9487b76R58

Copy link
Contributor

@yaahc yaahc Oct 6, 2020

Choose a reason for hiding this comment

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

But it seems like V.as_ref() is more reliable:

This is because it is using the method resolution rules which are closely interwined with Deref in rust which we could leverage this directly by using V.mul(v) (I thinkkkk)

teor2345
teor2345 previously approved these changes Oct 6, 2020
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Looks great.

As far as the Rust goes, we could merge now. But I saw a few things you might want to fix.

(I can't really review the cryptography part.)

Co-authored-by: Jane Lusby <jlusby42@gmail.com>
@dconnolly dconnolly requested review from teor2345 and yaahc October 6, 2020 03:40
@dconnolly dconnolly requested a review from oxarbitrage October 6, 2020 03:40
Copy link
Contributor

@yaahc yaahc left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

👍

@dconnolly dconnolly merged commit 8b8ef6d into main Oct 7, 2020
@dconnolly dconnolly deleted the value-commitment-ops branch October 7, 2020 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code NU-1 Sapling Network Upgrade: Sapling specific tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants