Skip to content

Commit

Permalink
Move to extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
WizardOfMenlo committed Jul 28, 2024
1 parent fa5b195 commit a8a5ccc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 46 deletions.
28 changes: 27 additions & 1 deletion ff/src/fields/models/cubic_extension.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
fields::{Field, PrimeField},
AdditiveGroup, LegendreSymbol, One, SqrtPrecomputation, ToConstraintField, UniformRand, Zero,
AdditiveGroup, FftField, LegendreSymbol, One, SqrtPrecomputation, ToConstraintField,
UniformRand, Zero,
};
use ark_serialize::{
CanonicalDeserialize, CanonicalDeserializeWithFlags, CanonicalSerialize,
Expand Down Expand Up @@ -770,3 +771,28 @@ mod cube_ext_tests {
}
}
}

impl<P: CubicExtConfig> FftField for CubicExtField<P>
where
P::BaseField: FftField,
{
const GENERATOR: Self = Self::new(
P::BaseField::GENERATOR,
P::BaseField::ZERO,
P::BaseField::ZERO,
);
const TWO_ADICITY: u32 = P::BaseField::TWO_ADICITY;
const TWO_ADIC_ROOT_OF_UNITY: Self = Self::new(
P::BaseField::TWO_ADIC_ROOT_OF_UNITY,
P::BaseField::ZERO,
P::BaseField::ZERO,
);
const SMALL_SUBGROUP_BASE: Option<u32> = P::BaseField::SMALL_SUBGROUP_BASE;
const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = P::BaseField::SMALL_SUBGROUP_BASE_ADICITY;
const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<Self> =
if let Some(x) = P::BaseField::LARGE_SUBGROUP_ROOT_OF_UNITY {
Some(Self::new(x, P::BaseField::ZERO, P::BaseField::ZERO))
} else {
None
};
}
21 changes: 1 addition & 20 deletions ff/src/fields/models/fp2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use num_traits::ConstZero;

use super::quadratic_extension::{QuadExtConfig, QuadExtField};
use crate::{fields::PrimeField, CyclotomicMultSubgroup, FftField, Zero};
use crate::{fields::PrimeField, CyclotomicMultSubgroup, Zero};
use core::{marker::PhantomData, ops::Not};

/// Trait that specifies constants and methods for defining degree-two extension fields.
Expand Down Expand Up @@ -139,20 +137,3 @@ impl<P: Fp2Config> CyclotomicMultSubgroup for Fp2<P> {
})
}
}

impl<P: Fp2Config> FftField for Fp2<P>
where
P::Fp: FftField + ConstZero,
{
const GENERATOR: Self = Fp2::new(P::Fp::GENERATOR, P::Fp::ZERO);
const TWO_ADICITY: u32 = P::Fp::TWO_ADICITY;
const TWO_ADIC_ROOT_OF_UNITY: Self = Fp2::new(P::Fp::TWO_ADIC_ROOT_OF_UNITY, P::Fp::ZERO);
const SMALL_SUBGROUP_BASE: Option<u32> = P::Fp::SMALL_SUBGROUP_BASE;
const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = P::Fp::SMALL_SUBGROUP_BASE_ADICITY;
const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<Self> =
if let Some(x) = P::Fp::LARGE_SUBGROUP_ROOT_OF_UNITY {
Some(Fp2::new(x, P::Fp::ZERO))
} else {
None
};
}
25 changes: 1 addition & 24 deletions ff/src/fields/models/fp3.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use num_traits::ConstZero;

use super::cubic_extension::{CubicExtConfig, CubicExtField};
use crate::{
fields::{CyclotomicMultSubgroup, MulAssign, PrimeField, SqrtPrecomputation},
FftField,
};
use crate::fields::{CyclotomicMultSubgroup, MulAssign, PrimeField, SqrtPrecomputation};
use core::marker::PhantomData;

/// Trait that specifies constants and methods for defining degree-three extension fields.
Expand Down Expand Up @@ -105,21 +100,3 @@ impl<P: Fp3Config> Fp3<P> {

// We just use the default algorithms; there don't seem to be any faster ones.
impl<P: Fp3Config> CyclotomicMultSubgroup for Fp3<P> {}

impl<P: Fp3Config> FftField for Fp3<P>
where
P::Fp: FftField + ConstZero,
{
const GENERATOR: Self = Fp3::new(P::Fp::GENERATOR, P::Fp::ZERO, P::Fp::ZERO);
const TWO_ADICITY: u32 = P::Fp::TWO_ADICITY;
const TWO_ADIC_ROOT_OF_UNITY: Self =
Fp3::new(P::Fp::TWO_ADIC_ROOT_OF_UNITY, P::Fp::ZERO, P::Fp::ZERO);
const SMALL_SUBGROUP_BASE: Option<u32> = P::Fp::SMALL_SUBGROUP_BASE;
const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = P::Fp::SMALL_SUBGROUP_BASE_ADICITY;
const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<Self> =
if let Some(x) = P::Fp::LARGE_SUBGROUP_ROOT_OF_UNITY {
Some(Fp3::new(x, P::Fp::ZERO, P::Fp::ZERO))
} else {
None
};
}
20 changes: 19 additions & 1 deletion ff/src/fields/models/quadratic_extension.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
biginteger::BigInteger,
fields::{Field, LegendreSymbol, PrimeField},
AdditiveGroup, One, SqrtPrecomputation, ToConstraintField, UniformRand, Zero,
AdditiveGroup, FftField, One, SqrtPrecomputation, ToConstraintField, UniformRand, Zero,
};
use ark_serialize::{
CanonicalDeserialize, CanonicalDeserializeWithFlags, CanonicalSerialize,
Expand Down Expand Up @@ -825,3 +825,21 @@ mod quad_ext_tests {
}
}
}

impl<P: QuadExtConfig> FftField for QuadExtField<P>
where
P::BaseField: FftField,
{
const GENERATOR: Self = Self::new(P::BaseField::GENERATOR, P::BaseField::ZERO);
const TWO_ADICITY: u32 = P::BaseField::TWO_ADICITY;
const TWO_ADIC_ROOT_OF_UNITY: Self =
Self::new(P::BaseField::TWO_ADIC_ROOT_OF_UNITY, P::BaseField::ZERO);
const SMALL_SUBGROUP_BASE: Option<u32> = P::BaseField::SMALL_SUBGROUP_BASE;
const SMALL_SUBGROUP_BASE_ADICITY: Option<u32> = P::BaseField::SMALL_SUBGROUP_BASE_ADICITY;
const LARGE_SUBGROUP_ROOT_OF_UNITY: Option<Self> =
if let Some(x) = P::BaseField::LARGE_SUBGROUP_ROOT_OF_UNITY {
Some(Self::new(x, P::BaseField::ZERO))
} else {
None
};
}

0 comments on commit a8a5ccc

Please sign in to comment.