From 1aa8ed55cc743eef8a5b690a27c1591fd48a3462 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:56:17 +0100 Subject: [PATCH] rm more useless generics (#878) * rm more useless generics * rm useless code --- curves/curve-constraint-tests/src/lib.rs | 8 +++----- curves/mnt6_298/src/curves/mod.rs | 5 ++--- ec/src/hashing/curve_maps/elligator2.rs | 7 ++----- ec/src/hashing/curve_maps/swu.rs | 2 +- ec/src/hashing/curve_maps/wb.rs | 2 +- ec/src/models/mnt4/g2.rs | 8 ++++---- ec/src/models/mnt4/mod.rs | 2 +- ec/src/models/mnt6/g2.rs | 8 ++++---- ec/src/models/mnt6/mod.rs | 2 +- ec/src/scalar_mul/variable_base/stream_pippenger.rs | 2 +- ff/src/biginteger/mod.rs | 13 ++++++------- ff/src/fields/field_hashers/expander/tests.rs | 2 +- ff/src/fields/field_hashers/mod.rs | 2 +- ff/src/fields/mod.rs | 4 ++-- ff/src/fields/models/cubic_extension.rs | 4 ++-- ff/src/fields/models/fp/mod.rs | 2 +- ff/src/fields/models/fp/montgomery_backend.rs | 7 +++---- ff/src/fields/models/quadratic_extension.rs | 4 ++-- 18 files changed, 38 insertions(+), 46 deletions(-) diff --git a/curves/curve-constraint-tests/src/lib.rs b/curves/curve-constraint-tests/src/lib.rs index 0a0077f09..d8dc4675d 100644 --- a/curves/curve-constraint-tests/src/lib.rs +++ b/curves/curve-constraint-tests/src/lib.rs @@ -205,7 +205,7 @@ pub mod fields { AllocationMode::Constant, ]; for &mode in &modes { - let cs = ConstraintSystem::::new_ref(); + let cs = ConstraintSystem::new_ref(); let mut rng = test_rng(); for i in 0..=maxpower { let mut a = F::rand(&mut rng); @@ -246,7 +246,7 @@ pub mod curves { AllocationMode::Constant, ]; for &mode in &modes { - let cs = ConstraintSystem::::new_ref(); + let cs = ConstraintSystem::new_ref(); let mut rng = test_rng(); let a_native = C::rand(&mut rng); @@ -539,8 +539,6 @@ pub mod pairing { use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; use ark_std::{test_rng, vec::*, UniformRand}; - type BasePrimeField

= <

::BaseField as Field>::BasePrimeField; - #[allow(dead_code)] pub fn bilinearity_test>() -> Result<(), SynthesisError> where @@ -554,7 +552,7 @@ pub mod pairing { AllocationMode::Constant, ]; for &mode in &modes { - let cs = ConstraintSystem::>::new_ref(); + let cs = ConstraintSystem::new_ref(); let mut rng = test_rng(); let a = E::G1::rand(&mut rng); diff --git a/curves/mnt6_298/src/curves/mod.rs b/curves/mnt6_298/src/curves/mod.rs index 6a04f9b91..cc4b52ea2 100644 --- a/curves/mnt6_298/src/curves/mod.rs +++ b/curves/mnt6_298/src/curves/mod.rs @@ -22,9 +22,8 @@ pub type MNT6_298 = MNT6; pub struct Config; impl MNT6Config for Config { - const TWIST: Fp3 = Fp3::::new(Fq::ZERO, Fq::ONE, Fq::ZERO); - const TWIST_COEFF_A: Fp3 = - Fp3::::new(Fq::ZERO, Fq::ZERO, g1::Config::COEFF_A); + const TWIST: Fp3 = Fp3::new(Fq::ZERO, Fq::ONE, Fq::ZERO); + const TWIST_COEFF_A: Fp3 = Fp3::new(Fq::ZERO, Fq::ZERO, g1::Config::COEFF_A); // https://github.com/o1-labs/snarky/blob/9c21ab2bb23874604640740d646a932e813432c3/snarkette/mnt6_80.ml#L118 const ATE_LOOP_COUNT: &'static [i8] = &[ diff --git a/ec/src/hashing/curve_maps/elligator2.rs b/ec/src/hashing/curve_maps/elligator2.rs index 183b3541e..b80d83514 100644 --- a/ec/src/hashing/curve_maps/elligator2.rs +++ b/ec/src/hashing/curve_maps/elligator2.rs @@ -226,7 +226,7 @@ mod test { const COEFF_D: F101 = MontFp!("12"); const GENERATOR: Affine = - Affine::::new_unchecked(MontFp!("23"), MontFp!("24")); + Affine::new_unchecked(MontFp!("23"), MontFp!("24")); type MontCurveConfig = TestElligator2MapToCurveConfig; } @@ -286,10 +286,7 @@ mod test { // map is not constant on that set. for current_field_element in 0..101 { map_range.push( - Elligator2Map::::map_to_curve(F101::from( - current_field_element as u64, - )) - .unwrap(), + Elligator2Map::map_to_curve(F101::from(current_field_element as u64)).unwrap(), ); } diff --git a/ec/src/hashing/curve_maps/swu.rs b/ec/src/hashing/curve_maps/swu.rs index c5d6b998b..fa88ae3d2 100644 --- a/ec/src/hashing/curve_maps/swu.rs +++ b/ec/src/hashing/curve_maps/swu.rs @@ -270,7 +270,7 @@ mod test { let mut map_range: Vec> = vec![]; for current_field_element in 0..127 { let element = F127::from(current_field_element as u64); - map_range.push(SWUMap::::map_to_curve(element).unwrap()); + map_range.push(SWUMap::map_to_curve(element).unwrap()); } let mut counts = diff --git a/ec/src/hashing/curve_maps/wb.rs b/ec/src/hashing/curve_maps/wb.rs index 11e79afbb..4d96c34f5 100644 --- a/ec/src/hashing/curve_maps/wb.rs +++ b/ec/src/hashing/curve_maps/wb.rs @@ -105,7 +105,7 @@ impl MapToCurve> for WBMap

{ element: as AffineRepr>::BaseField, ) -> Result, HashToCurveError> { // first we need to map the field point to the isogenous curve - let point_on_isogenious_curve = SWUMap::::map_to_curve(element).unwrap(); + let point_on_isogenious_curve = SWUMap::map_to_curve(element).unwrap(); P::ISOGENY_MAP.apply(point_on_isogenious_curve) } } diff --git a/ec/src/models/mnt4/g2.rs b/ec/src/models/mnt4/g2.rs index 17e9a79ec..64a88f2f7 100644 --- a/ec/src/models/mnt4/g2.rs +++ b/ec/src/models/mnt4/g2.rs @@ -52,13 +52,13 @@ impl From> for G2Prepared

{ let neg_g = -g; for bit in P::ATE_LOOP_COUNT.iter().skip(1) { - let (r2, coeff) = MNT4::

::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::

::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), + 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!(), }; @@ -74,7 +74,7 @@ impl From> for G2Prepared

{ let minus_r_affine_x = r.x * &rz2_inv; let minus_r_affine_y = -r.y * &rz3_inv; - let add_result = MNT4::

::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, diff --git a/ec/src/models/mnt4/mod.rs b/ec/src/models/mnt4/mod.rs index 0b077286a..2ebf3085a 100644 --- a/ec/src/models/mnt4/mod.rs +++ b/ec/src/models/mnt4/mod.rs @@ -54,7 +54,7 @@ pub trait MNT4Config: 'static + Sized { .map(|(a, b)| (a.into(), b.into())) .collect::>(); let result = ark_std::cfg_into_iter!(pairs) - .map(|(a, b)| MNT4::::ate_miller_loop(&a, &b)) + .map(|(a, b)| MNT4::ate_miller_loop(&a, &b)) .product(); MillerLoopOutput(result) } diff --git a/ec/src/models/mnt6/g2.rs b/ec/src/models/mnt6/g2.rs index 29268cffc..272674fd2 100644 --- a/ec/src/models/mnt6/g2.rs +++ b/ec/src/models/mnt6/g2.rs @@ -52,13 +52,13 @@ impl From> for G2Prepared

{ let neg_g = -g; for bit in P::ATE_LOOP_COUNT.iter().skip(1) { - let (r2, coeff) = MNT6::

::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::

::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), + 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!(), }; @@ -75,7 +75,7 @@ impl From> for G2Prepared

{ let minus_r_y = -r.y * &rz3_inv; let add_result = - MNT6::

::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); } diff --git a/ec/src/models/mnt6/mod.rs b/ec/src/models/mnt6/mod.rs index 233c6d9de..14ce47999 100644 --- a/ec/src/models/mnt6/mod.rs +++ b/ec/src/models/mnt6/mod.rs @@ -55,7 +55,7 @@ pub trait MNT6Config: 'static + Sized { .map(|(a, b)| (a.into(), b.into())) .collect::>(); let result = ark_std::cfg_into_iter!(pairs) - .map(|(a, b)| MNT6::::ate_miller_loop(&a, &b)) + .map(|(a, b)| MNT6::ate_miller_loop(&a, &b)) .product(); MillerLoopOutput(result) } diff --git a/ec/src/scalar_mul/variable_base/stream_pippenger.rs b/ec/src/scalar_mul/variable_base/stream_pippenger.rs index cb5fe4269..79f121dba 100644 --- a/ec/src/scalar_mul/variable_base/stream_pippenger.rs +++ b/ec/src/scalar_mul/variable_base/stream_pippenger.rs @@ -78,7 +78,7 @@ impl HashMapPippenger { Self { buffer: HashMap::with_capacity_and_hasher( max_msm_buffer, - core::hash::BuildHasherDefault::::default(), + core::hash::BuildHasherDefault::default(), ), result: G::zero(), buf_size: max_msm_buffer, diff --git a/ff/src/biginteger/mod.rs b/ff/src/biginteger/mod.rs index c471b4f09..c5a7c6907 100644 --- a/ff/src/biginteger/mod.rs +++ b/ff/src/biginteger/mod.rs @@ -65,7 +65,7 @@ impl CanonicalDeserialize for BigInt { compress: Compress, validate: Validate, ) -> Result { - Ok(BigInt::(<[u64; N]>::deserialize_with_mode( + Ok(BigInt(<[u64; N]>::deserialize_with_mode( reader, compress, validate, )?)) } @@ -279,15 +279,14 @@ impl BigInt { /// 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::([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::([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) } } @@ -386,7 +385,7 @@ impl BigInteger for BigInt { return (zero, zero); } - let mut r = crate::const_helpers::MulBuffer::::zeroed(); + let mut r = crate::const_helpers::MulBuffer::zeroed(); let mut carry = 0; @@ -1231,7 +1230,7 @@ pub trait BigInteger: /// assert_eq!(arr, vec); /// ``` fn to_bits_be(&self) -> Vec { - BitIteratorBE::new(self).collect::>() + BitIteratorBE::new(self).collect() } /// Returns the bit representation in a little endian boolean array, @@ -1248,7 +1247,7 @@ pub trait BigInteger: /// assert_eq!(arr, vec); /// ``` fn to_bits_le(&self) -> Vec { - BitIteratorLE::new(self).collect::>() + BitIteratorLE::new(self).collect() } /// Returns the byte representation in a big endian byte array, diff --git a/ff/src/fields/field_hashers/expander/tests.rs b/ff/src/fields/field_hashers/expander/tests.rs index eeebc64a7..2b59496f8 100644 --- a/ff/src/fields/field_hashers/expander/tests.rs +++ b/ff/src/fields/field_hashers/expander/tests.rs @@ -34,7 +34,7 @@ pub struct TestExpander { #[test] fn expander() { let args = Arguments::from_args(); - let mut tests = Vec::::new(); + let mut tests = Vec::new(); for filename in read_dir("./src/fields/field_hashers/expander/testdata").unwrap() { let ff = filename.unwrap(); diff --git a/ff/src/fields/field_hashers/mod.rs b/ff/src/fields/field_hashers/mod.rs index f8bd0b26b..b4f7170e1 100644 --- a/ff/src/fields/field_hashers/mod.rs +++ b/ff/src/fields/field_hashers/mod.rs @@ -80,7 +80,7 @@ impl Ha }; F::from_base_prime_field_elems((0..m).map(base_prime_field_elem)).unwrap() }; - ark_std::array::from_fn::(cb) + ark_std::array::from_fn(cb) } } diff --git a/ff/src/fields/mod.rs b/ff/src/fields/mod.rs index f51a8ac24..dcacfe356 100644 --- a/ff/src/fields/mod.rs +++ b/ff/src/fields/mod.rs @@ -450,7 +450,7 @@ mod no_std_tests { #[test] fn test_batch_inversion() { - let mut random_coeffs = Vec::::new(); + let mut random_coeffs = Vec::new(); let vec_size = 1000; for _ in 0..=vec_size { @@ -458,7 +458,7 @@ mod no_std_tests { } let mut random_coeffs_inv = random_coeffs.clone(); - batch_inversion::(&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()); } diff --git a/ff/src/fields/models/cubic_extension.rs b/ff/src/fields/models/cubic_extension.rs index 9c3e05181..61e90bcd1 100644 --- a/ff/src/fields/models/cubic_extension.rs +++ b/ff/src/fields/models/cubic_extension.rs @@ -701,7 +701,7 @@ mod cube_ext_tests { if d == ext_degree { continue; } - let mut random_coeffs = Vec::::new(); + let mut random_coeffs = Vec::new(); for _ in 0..d { random_coeffs.push(Fq::rand(&mut test_rng())); } @@ -712,7 +712,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::::new(); + let mut random_coeffs = Vec::new(); for _ in 0..ext_degree { random_coeffs.push(Fq::rand(&mut test_rng())); } diff --git a/ff/src/fields/models/fp/mod.rs b/ff/src/fields/models/fp/mod.rs index 76f65b7fc..2ecf317c6 100644 --- a/ff/src/fields/models/fp/mod.rs +++ b/ff/src/fields/models/fp/mod.rs @@ -990,7 +990,7 @@ impl, const N: usize> zeroize::Zeroize for Fp { impl, const N: usize> From for Fp { #[inline] fn from(val: num_bigint::BigUint) -> Fp { - Fp::::from_le_bytes_mod_order(&val.to_bytes_le()) + Fp::from_le_bytes_mod_order(&val.to_bytes_le()) } } diff --git a/ff/src/fields/models/fp/montgomery_backend.rs b/ff/src/fields/models/fp/montgomery_backend.rs index 06fc84a6a..7b194f5a9 100644 --- a/ff/src/fields/models/fp/montgomery_backend.rs +++ b/ff/src/fields/models/fp/montgomery_backend.rs @@ -75,15 +75,14 @@ pub trait MontConfig: '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, N>>> = - sqrt_precomputation::(); + sqrt_precomputation(); /// (MODULUS + 1) / 4 when MODULUS % 4 == 3. Used for square root precomputations. #[doc(hidden)] const MODULUS_PLUS_ONE_DIV_FOUR: Option> = { match Self::MODULUS.mod_4() == 3 { true => { - let (modulus_plus_one, carry) = - Self::MODULUS.const_add_with_carry(&BigInt::::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: @@ -727,7 +726,7 @@ impl, const N: usize> Fp, N> { /// of this method #[doc(hidden)] pub const fn from_sign_and_limbs(is_positive: bool, limbs: &[u64]) -> Self { - let mut repr = BigInt::([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]; diff --git a/ff/src/fields/models/quadratic_extension.rs b/ff/src/fields/models/quadratic_extension.rs index 1eaa1ed47..f4b92a520 100644 --- a/ff/src/fields/models/quadratic_extension.rs +++ b/ff/src/fields/models/quadratic_extension.rs @@ -786,7 +786,7 @@ mod quad_ext_tests { if d == ext_degree { continue; } - let mut random_coeffs = Vec::::new(); + let mut random_coeffs = Vec::new(); for _ in 0..d { random_coeffs.push(Fq::rand(&mut test_rng())); } @@ -797,7 +797,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::::new(); + let mut random_coeffs = Vec::new(); for _ in 0..ext_degree { random_coeffs.push(Fq::rand(&mut test_rng())); }