-
Notifications
You must be signed in to change notification settings - Fork 476
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
[WIP] Impl ff::Field
for Scalar
#471
Conversation
For the field element types `FieldElement` and `Scalar`, use inherent constants instead of (non-const) functions to return these constant values. It's likely the original functions predate support for inherent constants, but now that they're available, they're a better fit for these sort of constant values.
Adds https://github.com/zkcrypto/ff as an optional dependency, which provides traits for finite fields.
@@ -568,6 +571,36 @@ impl Zeroize for Scalar { | |||
} | |||
} | |||
|
|||
#[cfg(all(feature = "ff", feature = "rand_core"))] |
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.
Would be nice to use namespaced features so an ff
feature could activate dep:ff
and rand_core
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.
We will be using this in ff
itself once its MSRV is 1.60 (zkcrypto/ff#78), but I haven't seen a strong push for that MSRV yet in the wider ecosystem.
} | ||
|
||
fn sqrt_ratio(_num: &Self, _div: &Self) -> (Choice, Self) { | ||
// TODO: can't use `ff::helpers::sqrt_ratio_generic` because `Scalar` isn't a `PrimeField` |
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.
The documentation of Scalar
indicates that its arithmetic is modulo ell
, the prime order of both Ristretto and the Ed25519 basepoint. So we can impl PrimeField for Scalar
. (It does have concrete constructors for bit-twiddling purposes that enable construction of scalar representations that aren't canonical, but those are irrelevant to the ff::PrimeField
trait, and any arithmetic on those representations would result in canonical scalars.)
Closing in favor of #473 |
Note: depends on #470 which needs to be merged first.
Adds https://github.com/zkcrypto/ff as an optional dependency, which provides traits for finite fields.