-
Notifications
You must be signed in to change notification settings - Fork 103
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
Breaking additions to the Field
trait
#93
Conversation
Ported from zcash/pasta_curves@db83057.
b36fbf5
to
0dd4723
Compare
src/helpers.rs
Outdated
for j in 2..max_v { | ||
let tmp_is_one = tmp.ct_eq(&F::one()); | ||
let squared = F::conditional_select(&tmp, &z, tmp_is_one).square(); | ||
tmp = F::conditional_select(&squared, &tmp, tmp_is_one); |
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.
Are you sure this is right? If tmp == 1 then we set squared = tmp (= 1) and then tmp = squared (i.e. no effect on tmp).
Otherwise we set squared = z2 and tmp = tmp (i.e. no effect on tmp).
In either case, this line is redundant, if it is correct.
tmp = F::conditional_select(&squared, &tmp, tmp_is_one); |
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.
You're reading the conditional select method backwards. Per the API docs, it is conditional_select(false_case, true_case, condition)
. Therefore, what this does is:
- If
tmp != 1
,squared <-- tmp^2
and thentmp <-- squared
. Thussquared = tmp = tmp^2
. - If
tmp == 1
,squared <-- z^2
and thentmp <-- tmp
. Thussquared = z^2
andtmp = 1
.
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.
Oh! Google found docs for a really old version of subtle in which true_case
came before false_case
. Ok I'll need to re-review with that in mind.
let mut z = F::root_of_unity(); | ||
|
||
for max_v in (1..=F::S).rev() { | ||
let mut k = 1; |
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 doesn't follow algorithm 5 in the paper, because step 8 can result in k = 0 and this cannot.
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.
That is a typo in Algorithm 5.
let result = x * z; | ||
x = F::conditional_select(&result, &x, b.ct_eq(&F::one())); | ||
z = z.square(); |
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 cannot follow how this corresponds to the paper.
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 corresponds to step 9. This specific line corresponds to z
update on line 43.
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 think I clicked the wrong review outcome here; should have been Request changes]
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.
Responses needed. In particular I think sqrt_ratio_generic
may be incorrect, and I wasn't able to verify sqrt_tonelli_shanks
against the implementation in the paper.
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.
utACK modulo comments and variable renaming.
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.
possible improvement to wording of changelog
We also provide helper methods for implementing the square root trait methods. Ported from zcash/pasta_curves@db83057.
0dd4723
to
58741b7
Compare
Force-pushed to address review comments from @ebfull and @daira. |
This makes the potential for a cycle clear (if the `Field` implementor uses `sqrt` to implement `sqrt_ratio`).
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.
ACK -- didn't look at the Tonelli-Shanks algorithm in detail; I'm just assuming it's been lifted from pasta_curves
.
These new trait methods are moved from the
FieldExt
trait inpasta_curves
, where we had placed them while figuring out their APIs.Closes #33.