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

Add associated constants of type Self to Field and PrimeField #94

Merged
merged 1 commit into from
Nov 2, 2022

Conversation

str4d
Copy link
Member

@str4d str4d commented Oct 28, 2022

We now require that the type implementing Field, and its particular values for these constants, can be constructed in a const context. Once upon a time this might have been onerous, but it should now be a reasonable requirement given our MSRV of 1.56.0.

Closes #87.

@str4d
Copy link
Member Author

str4d commented Oct 28, 2022

Prior to merging this, I want to confirm that the major implementors of the ff traits are able to implement these associated constants. Here is the list of crates I know about, and which ones I have confirmed can migrate to providing associated constants:

  • bls12_381
  • jubjub
  • pasta_curves
  • blstrs
  • ec-gpu-gen
  • Rust Crypto crates:
    • k256
    • p256
    • p384
    • bp256
    • bp384
  • TODO: find more crates

@tarcieri
Copy link
Contributor

@str4d the @RustCrypto crates are all fine. They support both const fn constructors and arithmetic on their respective FieldElement and Scalar types.

@str4d
Copy link
Member Author

str4d commented Oct 31, 2022

I confirmed that blstrs implements the current trait methods using constants, so can migrate to associated constants. And AFAICT ec-gpu-gen only uses the representation parts of the ff traits to shuttle field elements between CPU and GPU; it doesn't actually generate code that implements Field or PrimeField. So I think I'm satisfied that this PR is fine.

@str4d str4d marked this pull request as ready for review October 31, 2022 08:29
Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

utACK

src/lib.rs Outdated Show resolved Hide resolved
Base automatically changed from field-trait-changes to main November 2, 2022 18:55
@str4d
Copy link
Member Author

str4d commented Nov 2, 2022

Rebased on main to fix merge conflicts and address @ebfull's comment.

We now require that the type implementing `Field`, and its particular
values for these constants, can be constructed in a const context. Once
upon a time this might have been onerous, but it should now be a
reasonable requirement given our MSRV of 1.56.0.

Closes #87.
@str4d
Copy link
Member Author

str4d commented Nov 2, 2022

Force-pushed to fix a documentation lint.

@str4d str4d merged commit 1eddf54 into main Nov 2, 2022
@str4d str4d deleted the trait-constants branch November 2, 2022 20:42
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.

Consider promoting Field::{zero, one} to associated constants
4 participants