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

[WIP] Impl ff::Field for Scalar #471

Closed
wants to merge 2 commits into from
Closed

[WIP] Impl ff::Field for Scalar #471

wants to merge 2 commits into from

Conversation

tarcieri
Copy link
Contributor

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.

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"))]
Copy link
Contributor Author

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

Copy link
Contributor

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

@str4d str4d Dec 12, 2022

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.)

@tarcieri
Copy link
Contributor Author

Closing in favor of #473

@tarcieri tarcieri closed this Dec 12, 2022
@tarcieri tarcieri deleted the ff branch December 12, 2022 02:10
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.

2 participants