Skip to content

Commit

Permalink
Implement F::characteristic
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiencs committed Nov 27, 2024
1 parent 467f0c1 commit 04a756b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 3 additions & 1 deletion ec/src/models/short_weierstrass_jacobian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ impl<P: Parameters> GroupAffine<P> {
/// Checks if `self` is in the subgroup having order that equaling that of
/// `P::ScalarField`.
pub fn is_in_correct_subgroup_assuming_on_curve(&self) -> bool {
self.mul_bits(BitIteratorBE::new(P::ScalarField::characteristic()))
use core::convert::TryInto;
let characteristic = P::ScalarField::characteristic();
self.mul_bits(BitIteratorBE::new(&ark_ff::biginteger::to_64x4(characteristic.try_into().unwrap())))
.is_zero()
}
}
Expand Down
4 changes: 3 additions & 1 deletion ec/src/models/twisted_edwards_extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ impl<P: Parameters> GroupAffine<P> {
/// Checks that the current point is in the prime order subgroup given
/// the point on the curve.
pub fn is_in_correct_subgroup_assuming_on_curve(&self) -> bool {
self.mul_bits(BitIteratorBE::new(P::ScalarField::characteristic()))
use core::convert::TryInto;
let characteristic = P::ScalarField::characteristic();
self.mul_bits(BitIteratorBE::new(&ark_ff::biginteger::to_64x4(characteristic.try_into().unwrap())))
.is_zero()
}
}
Expand Down
2 changes: 1 addition & 1 deletion ff/src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub trait Field:

/// Returns the characteristic of the field,
/// in little-endian representation.
fn characteristic() -> &'static [u64] {
fn characteristic() -> &'static [u32] {
Self::BasePrimeField::characteristic()
}

Expand Down
5 changes: 3 additions & 2 deletions ff/src/fields/models/fp12_2over3over2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
fields::{fp6_3over2::*, Field, Fp2, Fp2Parameters},
One,
};
use core::marker::PhantomData;
use core::{convert::TryInto, marker::PhantomData};
use core::ops::{AddAssign, SubAssign};

type Fp2Params<P> = <<P as Fp12Parameters>::Fp6Params as Fp6Parameters>::Fp2Params;
Expand Down Expand Up @@ -135,7 +135,8 @@ impl<P: Fp12Parameters> Fp12<P> {
// Faster Squaring in the Cyclotomic Subgroup of Sixth Degree Extensions
// - Robert Granger and Michael Scott
//
if characteristic_square_mod_6_is_one(Self::characteristic()) {
let characteristic = Self::characteristic();
if characteristic_square_mod_6_is_one(&super::to_64x4(characteristic.try_into().unwrap())) {
let fp2_nr = <P::Fp6Params as Fp6Parameters>::mul_fp2_by_nonresidue;

let r0 = &self.c0.c0;
Expand Down
9 changes: 2 additions & 7 deletions ff/src/fields/models/webnode_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,6 @@ impl<C: Fp256Parameters> FromBytes for NewFp256<C> {
})
}
}
// + core::iter::Sum<Self>
// + for<'a> core::iter::Sum<&'a Self>
// + core::iter::Product<Self>
// + for<'a> core::iter::Product<&'a Self>

impl<C: Fp256Parameters> Field for NewFp256<C> {
type BasePrimeField = Self;
Expand All @@ -1150,9 +1146,8 @@ impl<C: Fp256Parameters> Field for NewFp256<C> {
self
}
#[inline]
fn characteristic() -> &'static [u64] {
todo!()
// P::MODULUS.as_ref()
fn characteristic() -> &'static [u32] {
&C::MODULUS.0
}
#[inline]
fn from_random_bytes_with_flags<F: Flags>(bytes: &[u8]) -> Option<(Self, F)> {
Expand Down

0 comments on commit 04a756b

Please sign in to comment.