Skip to content

Commit

Permalink
rm more useless generics (#878)
Browse files Browse the repository at this point in the history
* rm more useless generics

* rm useless code
  • Loading branch information
tcoratger authored Nov 20, 2024
1 parent 93fc31e commit 1aa8ed5
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 46 deletions.
8 changes: 3 additions & 5 deletions curves/curve-constraint-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub mod fields {
AllocationMode::Constant,
];
for &mode in &modes {
let cs = ConstraintSystem::<ConstraintF>::new_ref();
let cs = ConstraintSystem::new_ref();
let mut rng = test_rng();
for i in 0..=maxpower {
let mut a = F::rand(&mut rng);
Expand Down Expand Up @@ -246,7 +246,7 @@ pub mod curves {
AllocationMode::Constant,
];
for &mode in &modes {
let cs = ConstraintSystem::<ConstraintF>::new_ref();
let cs = ConstraintSystem::new_ref();

let mut rng = test_rng();
let a_native = C::rand(&mut rng);
Expand Down Expand Up @@ -539,8 +539,6 @@ pub mod pairing {
use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
use ark_std::{test_rng, vec::*, UniformRand};

type BasePrimeField<P> = <<P as Pairing>::BaseField as Field>::BasePrimeField;

#[allow(dead_code)]
pub fn bilinearity_test<E: Pairing, P: PairingVar<E>>() -> Result<(), SynthesisError>
where
Expand All @@ -554,7 +552,7 @@ pub mod pairing {
AllocationMode::Constant,
];
for &mode in &modes {
let cs = ConstraintSystem::<BasePrimeField<E>>::new_ref();
let cs = ConstraintSystem::new_ref();

let mut rng = test_rng();
let a = E::G1::rand(&mut rng);
Expand Down
5 changes: 2 additions & 3 deletions curves/mnt6_298/src/curves/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ pub type MNT6_298 = MNT6<Config>;
pub struct Config;

impl MNT6Config for Config {
const TWIST: Fp3<Self::Fp3Config> = Fp3::<Self::Fp3Config>::new(Fq::ZERO, Fq::ONE, Fq::ZERO);
const TWIST_COEFF_A: Fp3<Self::Fp3Config> =
Fp3::<Self::Fp3Config>::new(Fq::ZERO, Fq::ZERO, g1::Config::COEFF_A);
const TWIST: Fp3<Self::Fp3Config> = Fp3::new(Fq::ZERO, Fq::ONE, Fq::ZERO);
const TWIST_COEFF_A: Fp3<Self::Fp3Config> = 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] = &[
Expand Down
7 changes: 2 additions & 5 deletions ec/src/hashing/curve_maps/elligator2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ mod test {
const COEFF_D: F101 = MontFp!("12");

const GENERATOR: Affine<TestElligator2MapToCurveConfig> =
Affine::<TestElligator2MapToCurveConfig>::new_unchecked(MontFp!("23"), MontFp!("24"));
Affine::new_unchecked(MontFp!("23"), MontFp!("24"));

type MontCurveConfig = TestElligator2MapToCurveConfig;
}
Expand Down Expand Up @@ -286,10 +286,7 @@ mod test {
// map is not constant on that set.
for current_field_element in 0..101 {
map_range.push(
Elligator2Map::<TestElligator2MapToCurveConfig>::map_to_curve(F101::from(
current_field_element as u64,
))
.unwrap(),
Elligator2Map::map_to_curve(F101::from(current_field_element as u64)).unwrap(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion ec/src/hashing/curve_maps/swu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ mod test {
let mut map_range: Vec<Affine<TestSWUMapToCurveConfig>> = vec![];
for current_field_element in 0..127 {
let element = F127::from(current_field_element as u64);
map_range.push(SWUMap::<TestSWUMapToCurveConfig>::map_to_curve(element).unwrap());
map_range.push(SWUMap::map_to_curve(element).unwrap());
}

let mut counts =
Expand Down
2 changes: 1 addition & 1 deletion ec/src/hashing/curve_maps/wb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<P: WBConfig> MapToCurve<Projective<P>> for WBMap<P> {
element: <Affine<P> as AffineRepr>::BaseField,
) -> Result<Affine<P>, HashToCurveError> {
// first we need to map the field point to the isogenous curve
let point_on_isogenious_curve = SWUMap::<P::IsogenousCurve>::map_to_curve(element).unwrap();
let point_on_isogenious_curve = SWUMap::map_to_curve(element).unwrap();
P::ISOGENY_MAP.apply(point_on_isogenious_curve)
}
}
Expand Down
8 changes: 4 additions & 4 deletions ec/src/models/mnt4/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ impl<P: MNT4Config> From<G2Affine<P>> for G2Prepared<P> {

let neg_g = -g;
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 @@ -74,7 +74,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;
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
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
13 changes: 6 additions & 7 deletions ff/src/biginteger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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 @@ -279,15 +279,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 @@ -386,7 +385,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 @@ -1231,7 +1230,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 All @@ -1248,7 +1247,7 @@ pub trait BigInteger:
/// assert_eq!(arr, vec);
/// ```
fn to_bits_le(&self) -> Vec<bool> {
BitIteratorLE::new(self).collect::<Vec<_>>()
BitIteratorLE::new(self).collect()
}

/// Returns the byte representation in a big endian byte array,
Expand Down
2 changes: 1 addition & 1 deletion ff/src/fields/field_hashers/expander/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct TestExpander {
#[test]
fn expander() {
let args = Arguments::from_args();
let mut tests = Vec::<Trial>::new();
let mut tests = Vec::new();

for filename in read_dir("./src/fields/field_hashers/expander/testdata").unwrap() {
let ff = filename.unwrap();
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 @@ -701,7 +701,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 @@ -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::<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 @@ -990,7 +990,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
7 changes: 3 additions & 4 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
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 @@ -786,7 +786,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 @@ -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::<Fq>::new();
let mut random_coeffs = Vec::new();
for _ in 0..ext_degree {
random_coeffs.push(Fq::rand(&mut test_rng()));
}
Expand Down

0 comments on commit 1aa8ed5

Please sign in to comment.