Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Zero::is_zero in map #875

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ec/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ark_ff::{Field, PrimeField};
use ark_ff::{Field, PrimeField, Zero};

pub mod bls12;
pub mod bn;
Expand Down Expand Up @@ -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)
}
}
3 changes: 2 additions & 1 deletion ff/src/biginteger/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ark_std::Zero;
use ark_std::{vec, vec::*};

macro_rules! adc {
Expand Down Expand Up @@ -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<i8> {
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()];
Expand Down
3 changes: 2 additions & 1 deletion ff/src/biginteger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use ark_std::{
},
str::FromStr,
vec::*,
Zero,
};
use num_bigint::BigUint;
use zeroize::Zeroize;
Expand Down Expand Up @@ -475,7 +476,7 @@ impl<const N: usize> BigInteger for BigInt<N> {

#[inline]
fn is_zero(&self) -> bool {
self.0.iter().all(|&e| e == 0)
self.0.iter().all(Zero::is_zero)
}

#[inline]
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 @@ -400,7 +400,7 @@ impl<P: FpConfig<N>, const N: usize> From<u128> for Fp<P, N> {
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;
Expand Down
2 changes: 1 addition & 1 deletion test-templates/src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading