Skip to content

Commit

Permalink
Unify trait bound of Projective::mul_bigint and Affine::mul_bigint
Browse files Browse the repository at this point in the history
Co-authored-by: Michele Orrù <[email protected]>
  • Loading branch information
asn-d6 and mmaker committed Jul 18, 2022
1 parent bcaad0d commit 73fd19a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub trait AffineCurve:

/// Performs scalar multiplication of this element with mixed addition.
#[must_use]
fn mul_bigint<S: Into<<Self::ScalarField as PrimeField>::BigInt>>(&self, by: S) -> Self::Projective;
fn mul_bigint<S: AsRef<[u64]>>(&self, by: S) -> Self::Projective;

/// Performs cofactor clearing.
/// The default method is simply to multiply by the cofactor.
Expand All @@ -317,7 +317,7 @@ pub trait AffineCurve:
/// `Self::ScalarField`.
#[must_use]
fn mul_by_cofactor_inv(&self) -> Self {
self.mul_bigint(Self::Config::COFACTOR_INV).into()
self.mul(&Self::Config::COFACTOR_INV).into()
}
}

Expand Down
9 changes: 3 additions & 6 deletions ec/src/models/short_weierstrass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use ark_std::{
vec::Vec,
};

use ark_ff::{
fields::{Field, PrimeField},
ToConstraintField, UniformRand,
};
use ark_ff::{fields::Field, ToConstraintField, UniformRand};

use crate::{msm::VariableBaseMSM, AffineCurve, ProjectiveCurve};

Expand Down Expand Up @@ -326,8 +323,8 @@ impl<P: SWCurveConfig> AffineCurve for Affine<P> {
})
}

fn mul_bigint<S: Into<<Self::ScalarField as PrimeField>::BigInt>>(&self, by: S) -> Self::Projective {
P::mul_affine(self, by.into().as_ref())
fn mul_bigint<S: AsRef<[u64]>>(&self, by: S) -> Self::Projective {
P::mul_affine(self, by.as_ref())
}

/// Multiplies this element by the cofactor and output the
Expand Down
9 changes: 3 additions & 6 deletions ec/src/models/twisted_edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ use ark_std::{
use num_traits::{One, Zero};
use zeroize::Zeroize;

use ark_ff::{
fields::{Field, PrimeField},
ToConstraintField, UniformRand,
};
use ark_ff::{fields::Field, ToConstraintField, UniformRand};

#[cfg(feature = "parallel")]
use rayon::prelude::*;
Expand Down Expand Up @@ -234,8 +231,8 @@ impl<P: TECurveConfig> AffineCurve for Affine<P> {
})
}

fn mul_bigint<S: Into<<Self::ScalarField as PrimeField>::BigInt>>(&self, by: S) -> Self::Projective {
P::mul_affine(self, by.into().as_ref())
fn mul_bigint<S: AsRef<[u64]>>(&self, by: S) -> Self::Projective {
P::mul_affine(self, by.as_ref())
}

/// Multiplies this element by the cofactor and output the
Expand Down
2 changes: 1 addition & 1 deletion test-templates/src/curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn random_multiplication_test<G: ProjectiveCurve>() {
assert_eq!(tmp1, tmp2);
assert_eq!(tmp1, tmp3);

let expected = a_affine.mul_bigint(s);
let expected = a_affine.mul_bigint(s.into_bigint());
let got = a_affine.mul(&s);
assert_eq!(expected, got);
}
Expand Down

0 comments on commit 73fd19a

Please sign in to comment.