Skip to content

Commit

Permalink
rm generics when useless
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Nov 13, 2024
1 parent fd6a826 commit edd468d
Show file tree
Hide file tree
Showing 28 changed files with 96 additions and 125 deletions.
8 changes: 4 additions & 4 deletions ec/src/models/mnt4/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ impl<P: MNT4Config> From<G2Affine<P>> for G2Prepared<P> {

let neg_g = g.neg();
for bit in P::ATE_LOOP_COUNT.iter().skip(1) {
let (r2, coeff) = MNT4::<P>::doubling_for_flipped_miller_loop(&r);
let (r2, coeff) = MNT4::doubling_for_flipped_miller_loop(&r);
g_prep.double_coefficients.push(coeff);
r = r2;

let (r_temp, add_coeff) = match bit {
1 => MNT4::<P>::mixed_addition_for_flipped_miller_loop(&g.x, &g.y, &r),
-1 => MNT4::<P>::mixed_addition_for_flipped_miller_loop(&neg_g.x, &neg_g.y, &r),
1 => MNT4::mixed_addition_for_flipped_miller_loop(&g.x, &g.y, &r),
-1 => MNT4::mixed_addition_for_flipped_miller_loop(&neg_g.x, &neg_g.y, &r),
0 => continue,
_ => unreachable!(),
};
Expand All @@ -76,7 +76,7 @@ impl<P: MNT4Config> From<G2Affine<P>> for G2Prepared<P> {
let minus_r_affine_x = r.x * &rz2_inv;
let minus_r_affine_y = -r.y * &rz3_inv;

let add_result = MNT4::<P>::mixed_addition_for_flipped_miller_loop(
let add_result = MNT4::mixed_addition_for_flipped_miller_loop(
&minus_r_affine_x,
&minus_r_affine_y,
&r,
Expand Down
2 changes: 1 addition & 1 deletion ec/src/models/mnt4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub trait MNT4Config: 'static + Sized {
.map(|(a, b)| (a.into(), b.into()))
.collect::<Vec<_>>();
let result = ark_std::cfg_into_iter!(pairs)
.map(|(a, b)| MNT4::<Self>::ate_miller_loop(&a, &b))
.map(|(a, b)| MNT4::ate_miller_loop(&a, &b))
.product();
MillerLoopOutput(result)
}
Expand Down
8 changes: 4 additions & 4 deletions ec/src/models/mnt6/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ impl<P: MNT6Config> From<G2Affine<P>> for G2Prepared<P> {

let neg_g = g.neg();
for bit in P::ATE_LOOP_COUNT.iter().skip(1) {
let (r2, coeff) = MNT6::<P>::doubling_for_flipped_miller_loop(&r);
let (r2, coeff) = MNT6::doubling_for_flipped_miller_loop(&r);
g_prep.double_coefficients.push(coeff);
r = r2;

let (r_temp, add_coeff) = match bit {
1 => MNT6::<P>::mixed_addition_for_flipper_miller_loop(&g.x, &g.y, &r),
-1 => MNT6::<P>::mixed_addition_for_flipper_miller_loop(&neg_g.x, &neg_g.y, &r),
1 => MNT6::mixed_addition_for_flipper_miller_loop(&g.x, &g.y, &r),
-1 => MNT6::mixed_addition_for_flipper_miller_loop(&neg_g.x, &neg_g.y, &r),
0 => continue,
_ => unreachable!(),
};
Expand All @@ -75,7 +75,7 @@ impl<P: MNT6Config> From<G2Affine<P>> for G2Prepared<P> {
let minus_r_y = -r.y * &rz3_inv;

let add_result =
MNT6::<P>::mixed_addition_for_flipper_miller_loop(&minus_r_x, &minus_r_y, &r);
MNT6::mixed_addition_for_flipper_miller_loop(&minus_r_x, &minus_r_y, &r);
g_prep.addition_coefficients.push(add_result.1);
}

Expand Down
2 changes: 1 addition & 1 deletion ec/src/models/mnt6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait MNT6Config: 'static + Sized {
.map(|(a, b)| (a.into(), b.into()))
.collect::<Vec<_>>();
let result = ark_std::cfg_into_iter!(pairs)
.map(|(a, b)| MNT6::<Self>::ate_miller_loop(&a, &b))
.map(|(a, b)| MNT6::ate_miller_loop(&a, &b))
.product();
MillerLoopOutput(result)
}
Expand Down
3 changes: 1 addition & 2 deletions ec/src/models/short_weierstrass/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ impl<P: SWCurveConfig> CanonicalSerialize for Projective<P> {
writer: W,
compress: Compress,
) -> Result<(), SerializationError> {
let aff = Affine::<P>::from(*self);
P::serialize_with_mode(&aff, writer, compress)
P::serialize_with_mode(&(*self).into(), writer, compress)
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions ec/src/models/short_weierstrass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ pub trait SWCurveConfig: super::CurveConfig {
},
};
if flags.is_infinity() {
Ok(Affine::<Self>::identity())
Ok(Affine::identity())
} else {
let point = Affine::<Self>::new_unchecked(x, y);
let point = Affine::new_unchecked(x, y);
if let Validate::Yes = validate {
point.check()?;
}
Expand Down
3 changes: 1 addition & 2 deletions ec/src/models/twisted_edwards/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ impl<P: TECurveConfig> CanonicalSerialize for Projective<P> {
writer: W,
compress: Compress,
) -> Result<(), SerializationError> {
let aff = Affine::<P>::from(*self);
P::serialize_with_mode(&aff, writer, compress)
P::serialize_with_mode(&(*self).into(), writer, compress)
}

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions ec/src/models/twisted_edwards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub trait TECurveConfig: super::CurveConfig {
/// Default implementation of group multiplication for projective
/// coordinates
fn mul_projective(base: &Projective<Self>, scalar: &[u64]) -> Projective<Self> {
let mut res = Projective::<Self>::zero();
let mut res = Projective::zero();
for b in ark_ff::BitIteratorBE::without_leading_zeros(scalar) {
res.double_in_place();
if b {
Expand All @@ -74,7 +74,7 @@ pub trait TECurveConfig: super::CurveConfig {
/// Default implementation of group multiplication for affine
/// coordinates
fn mul_affine(base: &Affine<Self>, scalar: &[u64]) -> Projective<Self> {
let mut res = Projective::<Self>::zero();
let mut res = Projective::zero();
for b in ark_ff::BitIteratorBE::without_leading_zeros(scalar) {
res.double_in_place();
if b {
Expand Down Expand Up @@ -141,7 +141,7 @@ pub trait TECurveConfig: super::CurveConfig {
(x, y)
},
};
let point = Affine::<Self>::new_unchecked(x, y);
let point = Affine::new_unchecked(x, y);
if let Validate::Yes = validate {
point.check()?;
}
Expand Down
4 changes: 2 additions & 2 deletions ec/src/scalar_mul/glv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub trait GLVConfig: Send + Sync + 'static + SWCurveConfig {
let iter_k1 = ark_ff::BitIteratorBE::new(k1.into_bigint());
let iter_k2 = ark_ff::BitIteratorBE::new(k2.into_bigint());

let mut res = Projective::<Self>::zero();
let mut res = Projective::zero();
let mut skip_zeros = true;
for pair in iter_k1.zip(iter_k2) {
if skip_zeros && pair == (false, false) {
Expand Down Expand Up @@ -141,7 +141,7 @@ pub trait GLVConfig: Send + Sync + 'static + SWCurveConfig {
let iter_k1 = ark_ff::BitIteratorBE::new(k1.into_bigint());
let iter_k2 = ark_ff::BitIteratorBE::new(k2.into_bigint());

let mut res = Projective::<Self>::zero();
let mut res = Projective::zero();
let mut skip_zeros = true;
for pair in iter_k1.zip(iter_k2) {
if skip_zeros && pair == (false, false) {
Expand Down
4 changes: 2 additions & 2 deletions ec/src/scalar_mul/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn sw_double_and_add_affine<P: SWCurveConfig>(
base: &Affine<P>,
scalar: impl AsRef<[u64]>,
) -> Projective<P> {
let mut res = Projective::<P>::zero();
let mut res = Projective::zero();
for b in ark_ff::BitIteratorBE::without_leading_zeros(scalar) {
res.double_in_place();
if b {
Expand All @@ -49,7 +49,7 @@ pub fn sw_double_and_add_projective<P: SWCurveConfig>(
base: &Projective<P>,
scalar: impl AsRef<[u64]>,
) -> Projective<P> {
let mut res = Projective::<P>::zero();
let mut res = Projective::zero();
for b in ark_ff::BitIteratorBE::without_leading_zeros(scalar) {
res.double_in_place();
if b {
Expand Down
2 changes: 1 addition & 1 deletion ec/src/scalar_mul/variable_base/stream_pippenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<G: VariableBaseMSM> HashMapPippenger<G> {
Self {
buffer: HashMap::with_capacity_and_hasher(
max_msm_buffer,
core::hash::BuildHasherDefault::<DefaultHasher>::default(),
core::hash::BuildHasherDefault::default(),
),
result: G::zero(),
buf_size: max_msm_buffer,
Expand Down
4 changes: 2 additions & 2 deletions ff-asm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn x86_64_asm_mul(input: TokenStream) -> TokenStream {
..
}) = &*num_limbs
{
lit_int.base10_parse::<usize>().unwrap()
lit_int.base10_parse().unwrap()
} else {
panic!("The number of limbs must be a literal");
};
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn x86_64_asm_square(input: TokenStream) -> TokenStream {
..
}) = &*num_limbs
{
lit_int.base10_parse::<usize>().unwrap()
lit_int.base10_parse().unwrap()
} else {
panic!("The number of limbs must be a literal");
};
Expand Down
2 changes: 1 addition & 1 deletion ff-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const ARG_MSG: &str = "Failed to parse unroll threshold; must be a positive inte
/// Attribute used to unroll for loops found inside a function block.
#[proc_macro_attribute]
pub fn unroll_for_loops(args: TokenStream, input: TokenStream) -> TokenStream {
let unroll_by = match syn::parse2::<syn::Lit>(args.into()).expect(ARG_MSG) {
let unroll_by = match syn::parse2(args.into()).expect(ARG_MSG) {
Lit::Int(int) => int.base10_parse().expect(ARG_MSG),
_ => panic!("{}", ARG_MSG),
};
Expand Down
2 changes: 1 addition & 1 deletion ff-macros/src/montgomery/sum_of_products.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(super) fn sum_of_products_impl(num_limbs: usize, modulus: &[u64]) -> proc_ma
let mut result = F::new_unchecked(result);
__subtract_modulus(&mut result);
debug_assert_eq!(
a.iter().zip(b).map(|(a, b)| *a * b).sum::<F>(),
a.iter().zip(b).map(|(a, b)| *a * b).sum(),
result
);
result
Expand Down
2 changes: 1 addition & 1 deletion ff-macros/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn str_to_limbs_u64(num: &str) -> (bool, Vec<u64>) {
}
this
})
.collect::<Vec<_>>();
.collect();

let sign_is_positive = sign != Sign::Minus;
(sign_is_positive, limbs)
Expand Down
13 changes: 6 additions & 7 deletions ff/src/biginteger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<const N: usize> CanonicalDeserialize for BigInt<N> {
compress: Compress,
validate: Validate,
) -> Result<Self, SerializationError> {
Ok(BigInt::<N>(<[u64; N]>::deserialize_with_mode(
Ok(BigInt(<[u64; N]>::deserialize_with_mode(
reader, compress, validate,
)?))
}
Expand Down Expand Up @@ -278,15 +278,14 @@ impl<const N: usize> BigInt<N> {
/// Computes the Montgomery R constant modulo `self`.
#[doc(hidden)]
pub const fn montgomery_r(&self) -> Self {
let two_pow_n_times_64 = crate::const_helpers::RBuffer::<N>([0u64; N], 1);
let two_pow_n_times_64 = crate::const_helpers::RBuffer([0u64; N], 1);
const_modulo!(two_pow_n_times_64, self)
}

/// Computes the Montgomery R2 constant modulo `self`.
#[doc(hidden)]
pub const fn montgomery_r2(&self) -> Self {
let two_pow_n_times_64_square =
crate::const_helpers::R2Buffer::<N>([0u64; N], [0u64; N], 1);
let two_pow_n_times_64_square = crate::const_helpers::R2Buffer([0u64; N], [0u64; N], 1);
const_modulo!(two_pow_n_times_64_square, self)
}
}
Expand Down Expand Up @@ -385,7 +384,7 @@ impl<const N: usize> BigInteger for BigInt<N> {
return (zero, zero);
}

let mut r = crate::const_helpers::MulBuffer::<N>::zeroed();
let mut r = crate::const_helpers::MulBuffer::zeroed();

let mut carry = 0;

Expand Down Expand Up @@ -595,7 +594,7 @@ impl<const N: usize> Distribution<BigInt<N>> for Standard {
for item in res.iter_mut() {
*item = rng.gen();
}
BigInt::<N>(res)
BigInt(res)
}
}

Expand Down Expand Up @@ -1241,7 +1240,7 @@ pub trait BigInteger:
/// assert_eq!(arr, vec);
/// ```
fn to_bits_be(&self) -> Vec<bool> {
BitIteratorBE::new(self).collect::<Vec<_>>()
BitIteratorBE::new(self).collect()
}

/// Returns the bit representation in a little endian boolean array,
Expand Down
2 changes: 1 addition & 1 deletion ff/src/fields/field_hashers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<F: Field, H: FixedOutputReset + Default + Clone, const SEC_PARAM: usize> Ha
};
F::from_base_prime_field_elems((0..m).map(base_prime_field_elem)).unwrap()
};
ark_std::array::from_fn::<F, N, _>(cb)
ark_std::array::from_fn(cb)
}
}

Expand Down
4 changes: 2 additions & 2 deletions ff/src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,15 @@ mod no_std_tests {

#[test]
fn test_batch_inversion() {
let mut random_coeffs = Vec::<Fr>::new();
let mut random_coeffs = Vec::new();
let vec_size = 1000;

for _ in 0..=vec_size {
random_coeffs.push(Fr::rand(&mut test_rng()));
}

let mut random_coeffs_inv = random_coeffs.clone();
batch_inversion::<Fr>(&mut random_coeffs_inv);
batch_inversion(&mut random_coeffs_inv);
for i in 0..=vec_size {
assert_eq!(random_coeffs_inv[i] * random_coeffs[i], Fr::one());
}
Expand Down
4 changes: 2 additions & 2 deletions ff/src/fields/models/cubic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ mod cube_ext_tests {
if d == ext_degree {
continue;
}
let mut random_coeffs = Vec::<Fq>::new();
let mut random_coeffs = Vec::new();
for _ in 0..d {
random_coeffs.push(Fq::rand(&mut test_rng()));
}
Expand All @@ -740,7 +740,7 @@ mod cube_ext_tests {
// We test consistency against Fq2::new
let number_of_tests = 10;
for _ in 0..number_of_tests {
let mut random_coeffs = Vec::<Fq>::new();
let mut random_coeffs = Vec::new();
for _ in 0..ext_degree {
random_coeffs.push(Fq::rand(&mut test_rng()));
}
Expand Down
2 changes: 1 addition & 1 deletion ff/src/fields/models/fp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ impl<P: FpConfig<N>, const N: usize> zeroize::Zeroize for Fp<P, N> {
impl<P: FpConfig<N>, const N: usize> From<num_bigint::BigUint> for Fp<P, N> {
#[inline]
fn from(val: num_bigint::BigUint) -> Fp<P, N> {
Fp::<P, N>::from_le_bytes_mod_order(&val.to_bytes_le())
Fp::from_le_bytes_mod_order(&val.to_bytes_le())
}
}

Expand Down
9 changes: 4 additions & 5 deletions ff/src/fields/models/fp/montgomery_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ pub trait MontConfig<const N: usize>: 'static + Sync + Send + Sized {
/// Precomputed material for use when computing square roots.
/// The default is to use the standard Tonelli-Shanks algorithm.
const SQRT_PRECOMP: Option<SqrtPrecomputation<Fp<MontBackend<Self, N>, N>>> =
sqrt_precomputation::<N, Self>();
sqrt_precomputation();

/// (MODULUS + 1) / 4 when MODULUS % 4 == 3. Used for square root precomputations.
#[doc(hidden)]
const MODULUS_PLUS_ONE_DIV_FOUR: Option<BigInt<N>> = {
match Self::MODULUS.mod_4() == 3 {
true => {
let (modulus_plus_one, carry) =
Self::MODULUS.const_add_with_carry(&BigInt::<N>::one());
let (modulus_plus_one, carry) = Self::MODULUS.const_add_with_carry(&BigInt::one());
let mut result = modulus_plus_one.divide_by_2_round_down();
// Since modulus_plus_one is even, dividing by 2 results in a MSB of 0.
// Thus we can set MSB to `carry` to get the correct result of (MODULUS + 1) // 2:
Expand Down Expand Up @@ -727,7 +726,7 @@ impl<T: MontConfig<N>, const N: usize> Fp<MontBackend<T, N>, N> {
/// of this method
#[doc(hidden)]
pub const fn from_sign_and_limbs(is_positive: bool, limbs: &[u64]) -> Self {
let mut repr = BigInt::<N>([0; N]);
let mut repr = BigInt([0; N]);
assert!(limbs.len() <= N);
crate::const_for!((i in 0..(limbs.len())) {
repr.0[i] = limbs[i];
Expand Down Expand Up @@ -853,7 +852,7 @@ mod test {
}
this
})
.collect::<Vec<_>>();
.collect();

let sign_is_positive = sign != Sign::Minus;
(sign_is_positive, limbs)
Expand Down
4 changes: 2 additions & 2 deletions ff/src/fields/models/quadratic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ mod quad_ext_tests {
if d == ext_degree {
continue;
}
let mut random_coeffs = Vec::<Fq>::new();
let mut random_coeffs = Vec::new();
for _ in 0..d {
random_coeffs.push(Fq::rand(&mut test_rng()));
}
Expand All @@ -799,7 +799,7 @@ mod quad_ext_tests {
// We test consistency against Fq2::new
let number_of_tests = 10;
for _ in 0..number_of_tests {
let mut random_coeffs = Vec::<Fq>::new();
let mut random_coeffs = Vec::new();
for _ in 0..ext_degree {
random_coeffs.push(Fq::rand(&mut test_rng()));
}
Expand Down
Loading

0 comments on commit edd468d

Please sign in to comment.