-
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
Impl (Add|Sub)(Assign) for ValueCommitment #1105
Conversation
f9bd380
to
44594c1
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.
Looks good, but I don't understand the cryptography enough to know if it works.
Let's add a few quick tests?
]), | ||
); | ||
|
||
let identity = ValueCommitment(jubjub::AffinePoint::identity()); |
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.
Maybe move the identity to the top to be consistent with the other tests.
0x0000_0000_0000_0000, | ||
0x0000_0000_0000_0000, | ||
]), | ||
)); |
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.
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.
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 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
.
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.
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 ?
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.
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 |
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.
What is the reason for the new function in the context of 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 snuck over into this PR from the WIP over here: #1100
// 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"); |
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.
Should we make these into a lazy_static?
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.
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.
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
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.
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)
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.
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>
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.
LGTM
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.
👍
Needed for computing the transaction binding validating key