From 4b35a3bcaefac3d82275d00a0ba701af441fde72 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Wed, 13 Nov 2024 22:39:49 +0100 Subject: [PATCH] use Zero::is_zero in map --- ec/src/models/mod.rs | 4 ++-- ff/src/biginteger/arithmetic.rs | 3 ++- ff/src/biginteger/mod.rs | 3 ++- ff/src/fields/models/fp/mod.rs | 2 +- test-templates/src/fields.rs | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ec/src/models/mod.rs b/ec/src/models/mod.rs index 1ec3c2d61..c6b7e44a2 100644 --- a/ec/src/models/mod.rs +++ b/ec/src/models/mod.rs @@ -1,4 +1,4 @@ -use ark_ff::{Field, PrimeField}; +use ark_ff::{Field, PrimeField, Zero}; pub mod bls12; pub mod bn; @@ -27,6 +27,6 @@ pub trait CurveConfig: Send + Sync + Sized + 'static { const COFACTOR_INV: Self::ScalarField; fn cofactor_is_one() -> bool { - Self::COFACTOR[0] == 1 && Self::COFACTOR.iter().skip(1).all(|&e| e == 0) + Self::COFACTOR[0] == 1 && Self::COFACTOR.iter().skip(1).all(Zero::is_zero) } } diff --git a/ff/src/biginteger/arithmetic.rs b/ff/src/biginteger/arithmetic.rs index ac15a26ae..90ebe0a6e 100644 --- a/ff/src/biginteger/arithmetic.rs +++ b/ff/src/biginteger/arithmetic.rs @@ -1,3 +1,4 @@ +use ark_std::Zero; use ark_std::{vec, vec::*}; macro_rules! adc { @@ -152,7 +153,7 @@ pub fn mac_with_carry(a: u64, b: u64, c: u64, carry: &mut u64) -> u64 { /// Compute the NAF (non-adjacent form) of num pub fn find_naf(num: &[u64]) -> Vec { - let is_zero = |num: &[u64]| num.iter().all(|x| *x == 0u64); + let is_zero = |num: &[u64]| num.iter().all(Zero::is_zero); let is_odd = |num: &[u64]| num[0] & 1 == 1; let sub_noborrow = |num: &mut [u64], z: u64| { let mut other = vec![0u64; num.len()]; diff --git a/ff/src/biginteger/mod.rs b/ff/src/biginteger/mod.rs index f131eaf37..65f77bbfe 100644 --- a/ff/src/biginteger/mod.rs +++ b/ff/src/biginteger/mod.rs @@ -22,6 +22,7 @@ use ark_std::{ }, str::FromStr, vec::*, + Zero, }; use num_bigint::BigUint; use zeroize::Zeroize; @@ -475,7 +476,7 @@ impl BigInteger for BigInt { #[inline] fn is_zero(&self) -> bool { - self.0.iter().all(|&e| e == 0) + self.0.iter().all(Zero::is_zero) } #[inline] diff --git a/ff/src/fields/models/fp/mod.rs b/ff/src/fields/models/fp/mod.rs index 25fa86a9d..ed29a7d14 100644 --- a/ff/src/fields/models/fp/mod.rs +++ b/ff/src/fields/models/fp/mod.rs @@ -400,7 +400,7 @@ impl, const N: usize> From for Fp { let mut result = BigInt::default(); if N == 1 { result.0[0] = (other % u128::from(P::MODULUS.0[0])) as u64; - } else if N == 2 || P::MODULUS.0[2..].iter().all(|&x| x == 0) { + } else if N == 2 || P::MODULUS.0[2..].iter().all(Zero::is_zero) { let mod_as_u128 = P::MODULUS.0[0] as u128 + ((P::MODULUS.0[1] as u128) << 64); other %= mod_as_u128; result.0[0] = ((other << 64) >> 64) as u64; diff --git a/test-templates/src/fields.rs b/test-templates/src/fields.rs index 4e0417a6f..de95dc276 100644 --- a/test-templates/src/fields.rs +++ b/test-templates/src/fields.rs @@ -461,7 +461,7 @@ macro_rules! __test_field { let check = ((&modulus + 1u8) / 4u8).to_u64_digits(); let len = check.len(); assert_eq!(&modulus_plus_one_div_four[..len], &check); - assert!(modulus_plus_one_div_four[len..].iter().all(|l| *l == 0)); + assert!(modulus_plus_one_div_four[len..].iter().all(Zero::is_zero)); } let mut two_adicity = 0;