Skip to content

Commit

Permalink
Switch to using RPITIT for to_base_prime_field_elements (#751)
Browse files Browse the repository at this point in the history
* Switch to using RPITIT for `to_base_prime_field_elements`

* Bump minimum Rust version to 1.75
  • Loading branch information
Pratyush committed Jun 19, 2024
1 parent 85d17f5 commit 9ce37d5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT", "doc/katex-header.html"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.70"
rust-version = "1.75"

[workspace.metadata.docs.rs]
rustdoc-args = [ "--html-in-header katex-header.html" ]
Expand Down
4 changes: 1 addition & 3 deletions ff/src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ pub trait Field:
{
type BasePrimeField: PrimeField;

type BasePrimeFieldIter: Iterator<Item = Self::BasePrimeField>;

/// Determines the algorithm for computing square roots.
const SQRT_PRECOMP: Option<SqrtPrecomputation<Self>>;

Expand All @@ -219,7 +217,7 @@ pub trait Field:
/// to `Self::BasePrimeField`.
fn extension_degree() -> u64;

fn to_base_prime_field_elements(&self) -> Self::BasePrimeFieldIter;
fn to_base_prime_field_elements(&self) -> impl Iterator<Item = Self::BasePrimeField>;

/// Convert a slice of base prime field elements into a field element.
/// If the slice length != Self::extension_degree(), must return None.
Expand Down
13 changes: 5 additions & 8 deletions ff/src/fields/models/cubic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ impl<P: CubicExtConfig> AdditiveGroup for CubicExtField<P> {
}
}

type BaseFieldIter<P> = <<P as CubicExtConfig>::BaseField as Field>::BasePrimeFieldIter;
impl<P: CubicExtConfig> Field for CubicExtField<P> {
type BasePrimeField = P::BasePrimeField;
type BasePrimeFieldIter = Chain<BaseFieldIter<P>, Chain<BaseFieldIter<P>, BaseFieldIter<P>>>;

const SQRT_PRECOMP: Option<SqrtPrecomputation<Self>> = P::SQRT_PRECOMP;

Expand All @@ -196,12 +194,11 @@ impl<P: CubicExtConfig> Field for CubicExtField<P> {
Self::new(fe, P::BaseField::ZERO, P::BaseField::ZERO)
}

fn to_base_prime_field_elements(&self) -> Self::BasePrimeFieldIter {
self.c0.to_base_prime_field_elements().chain(
self.c1
.to_base_prime_field_elements()
.chain(self.c2.to_base_prime_field_elements()),
)
fn to_base_prime_field_elements(&self) -> impl Iterator<Item = Self::BasePrimeField> {
self.c0
.to_base_prime_field_elements()
.chain(self.c1.to_base_prime_field_elements())
.chain(self.c2.to_base_prime_field_elements())
}

fn from_base_prime_field_elems(
Expand Down
3 changes: 1 addition & 2 deletions ff/src/fields/models/fp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ impl<P: FpConfig<N>, const N: usize> AdditiveGroup for Fp<P, N> {

impl<P: FpConfig<N>, const N: usize> Field for Fp<P, N> {
type BasePrimeField = Self;
type BasePrimeFieldIter = iter::Once<Self::BasePrimeField>;

const SQRT_PRECOMP: Option<SqrtPrecomputation<Self>> = P::SQRT_PRECOMP;
const ONE: Self = P::ONE;
Expand All @@ -221,7 +220,7 @@ impl<P: FpConfig<N>, const N: usize> Field for Fp<P, N> {
elem
}

fn to_base_prime_field_elements(&self) -> Self::BasePrimeFieldIter {
fn to_base_prime_field_elements(&self) -> impl Iterator<Item = Self::BasePrimeField> {
iter::once(*self)
}

Expand Down
5 changes: 1 addition & 4 deletions ff/src/fields/models/quadratic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,9 @@ impl<P: QuadExtConfig> AdditiveGroup for QuadExtField<P> {
}
}

type BaseFieldIter<P> = <<P as QuadExtConfig>::BaseField as Field>::BasePrimeFieldIter;
impl<P: QuadExtConfig> Field for QuadExtField<P> {
type BasePrimeField = P::BasePrimeField;

type BasePrimeFieldIter = Chain<BaseFieldIter<P>, BaseFieldIter<P>>;

const SQRT_PRECOMP: Option<SqrtPrecomputation<Self>> = None;

const ONE: Self = Self::new(P::BaseField::ONE, P::BaseField::ZERO);
Expand All @@ -224,7 +221,7 @@ impl<P: QuadExtConfig> Field for QuadExtField<P> {
Self::new(fe, P::BaseField::ZERO)
}

fn to_base_prime_field_elements(&self) -> Self::BasePrimeFieldIter {
fn to_base_prime_field_elements(&self) -> impl Iterator<Item = Self::BasePrimeField> {
self.c0
.to_base_prime_field_elements()
.chain(self.c1.to_base_prime_field_elements())
Expand Down

0 comments on commit 9ce37d5

Please sign in to comment.