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

Refactor Fp code to use const generics, and more #379

Merged
merged 33 commits into from
Jan 31, 2022
Merged

Conversation

Pratyush
Copy link
Member

@Pratyush Pratyush commented Jan 11, 2022

Description

Closes #69
Close #180


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the GitHub PR explorer

@Pratyush Pratyush added breaking-change This PR contains a breaking change T-design Type: discuss API design and/or research T-feature Type: new features T-refactor Type: cleanup/refactor labels Jan 11, 2022
@Pratyush Pratyush self-assigned this Jan 11, 2022
@Pratyush Pratyush marked this pull request as ready for review January 12, 2022 18:46
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
ff/src/to_field_vec.rs Outdated Show resolved Hide resolved
ec/src/models/short_weierstrass_jacobian.rs Show resolved Hide resolved
ff/src/fields/mod.rs Outdated Show resolved Hide resolved
ff/src/fields/models/cubic_extension.rs Show resolved Hide resolved
ff/src/fields/models/fp3.rs Show resolved Hide resolved
Comment on lines +26 to +40
/// The modulus of the field.
const MODULUS: crate::BigInt<N>;

/// A multiplicative generator of the field.
/// `Self::GENERATOR` is an element having multiplicative order
/// `Self::MODULUS - 1`.
const GENERATOR: Fp<Self, N>;

/// Additive identity of the field, i.e. the element `e`
/// such that, for all elements `f` of the field, `e + f = f`.
const ZERO: Fp<Self, N>;

/// Multiplicative identity of the field, i.e. the element `e`
/// such that, for all elements `f` of the field, `e * f = f`.
const ONE: Fp<Self, N>;
Copy link
Member Author

Choose a reason for hiding this comment

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

The replacement for FpParameters, FpConfig, is much simplified; only the bare essentials need to be specified here, compared to implementation-details like R, CAPACITY, etc earlier.

Comment on lines +42 to +61
/// Set a += b.
fn add_assign(a: &mut Fp<Self, N>, b: &Fp<Self, N>);

/// Set a -= b.
fn sub_assign(a: &mut Fp<Self, N>, b: &Fp<Self, N>);

/// Set a = a + a.
fn double_in_place(a: &mut Fp<Self, N>);

/// Set a *= b.
fn mul_assign(a: &mut Fp<Self, N>, b: &Fp<Self, N>);

/// Set a *= b.
fn square_in_place(a: &mut Fp<Self, N>);

/// Compute a^{-1} if `a` is not zero.
fn inverse(a: &Fp<Self, N>) -> Option<Fp<Self, N>>;

/// Compute the square root of a, if it exists.
fn square_root(a: &Fp<Self, N>) -> Option<Fp<Self, N>> {
Copy link
Member Author

Choose a reason for hiding this comment

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

A lot of arithmetic methods have moved here, because this allows specializing the arithmetic implementation downstream

@weikengchen
Copy link
Member

Looks like the CI is passing (but, a corresponding update is needed in curves).

@Pratyush
Copy link
Member Author

I can make a PR for curves sometime early next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This PR contains a breaking change T-design Type: discuss API design and/or research T-feature Type: new features T-refactor Type: cleanup/refactor
Projects
None yet
3 participants