Skip to content

Commit 3dc7620

Browse files
rex4539Pratyush
andauthored
chore: avoid duplicate crates (#942)
* chore: avoid duplicate crates * fix clippy warnings --------- Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
1 parent fcd7673 commit 3dc7620

File tree

13 files changed

+15
-15
lines changed

13 files changed

+15
-15
lines changed

ec/src/hashing/curve_maps/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ pub fn parity<F: Field>(element: &F) -> bool {
1010
element
1111
.to_base_prime_field_elements()
1212
.find(|&x| !x.is_zero())
13-
.map_or(false, |x| x.into_bigint().is_odd())
13+
.is_some_and(|x| x.into_bigint().is_odd())
1414
}

ec/src/models/bn/g2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<P: BnConfig> From<G2Affine<P>> for G2Prepared<P> {
120120
match bit {
121121
1 => ell_coeffs.push(r.add_in_place(&q)),
122122
-1 => ell_coeffs.push(r.add_in_place(&neg_q)),
123-
_ => continue,
123+
_ => {},
124124
}
125125
}
126126

ec/src/models/bw6/g2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<P: BW6Config> From<G2Affine<P>> for G2Prepared<P> {
101101
match bit {
102102
1 => ell_coeffs_2.push(r.add_in_place(&qu)),
103103
-1 => ell_coeffs_2.push(r.add_in_place(&neg_qu)),
104-
_ => continue,
104+
_ => {},
105105
}
106106
}
107107

ff/src/fields/field_hashers/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ const fn get_len_per_elem<F: Field, const SEC_PARAM: usize>() -> usize {
113113
let base_field_size_with_security_padding_in_bits = base_field_size_in_bits + SEC_PARAM;
114114
// ceil( (ceil(log(p)) + security_parameter) / 8)
115115
let bytes_per_base_field_elem =
116-
((base_field_size_with_security_padding_in_bits + 7) / 8) as u64;
116+
base_field_size_with_security_padding_in_bits.div_ceil(8) as u64;
117117
bytes_per_base_field_elem as usize
118118
}

ff/src/fields/prime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub trait PrimeField:
7070
/// If the integer represented by `bytes` is larger than the modulus `p`, this method
7171
/// performs the appropriate reduction.
7272
fn from_le_bytes_mod_order(bytes: &[u8]) -> Self {
73-
let num_modulus_bytes = ((Self::MODULUS_BIT_SIZE + 7) / 8) as usize;
73+
let num_modulus_bytes = Self::MODULUS_BIT_SIZE.div_ceil(8) as usize;
7474
let num_bytes_to_directly_convert = min(num_modulus_bytes - 1, bytes.len());
7575
// Copy the leading little-endian bytes directly into a field element.
7676
// The number of bytes directly converted must be less than the

poly/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ark-test-curves = { path = "../test-curves", default-features = false, features
3838
"bn384_small_two_adicity_curve",
3939
"mnt4_753_curve",
4040
] }
41-
criterion = "0.5.1"
41+
criterion = { workspace = true }
4242

4343

4444
[features]

poly/src/domain/radix2/fft.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<F: FftField> Radix2EvaluationDomain<F> {
167167

168168
// recursive case:
169169
// 1. split log_powers in half
170-
let (lr_lo, lr_hi) = log_powers.split_at((1 + log_powers.len()) / 2);
170+
let (lr_lo, lr_hi) = log_powers.split_at(log_powers.len().div_ceil(2));
171171
let mut scr_lo = vec![F::default(); 1 << lr_lo.len()];
172172
let mut scr_hi = vec![F::default(); 1 << lr_hi.len()];
173173
// 2. compute each half individually

poly/src/evaluations/multivariate/multilinear/sparse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<F: Field> MultilinearExtension<F> for SparseMultilinearExtension<F> {
194194
self.evaluations
195195
.iter()
196196
.map(|(&i, &v)| evaluations[i] = v)
197-
.last();
197+
.next_back();
198198
evaluations
199199
}
200200
}

poly/src/polynomial/multivariate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Term for SparseTerm {
104104

105105
/// Returns whether `self` is a constant
106106
fn is_constant(&self) -> bool {
107-
self.len() == 0 || self.degree() == 0
107+
self.is_empty() || self.degree() == 0
108108
}
109109

110110
/// Evaluates `self` at the given `point` in the field.

poly/src/polynomial/univariate/dense.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<F: Field> Polynomial<F> for DensePolynomial<F> {
3232
if self.is_zero() {
3333
0
3434
} else {
35-
assert!(self.coeffs.last().map_or(false, |coeff| !coeff.is_zero()));
35+
assert!(self.coeffs.last().is_some_and(|coeff| !coeff.is_zero()));
3636
self.coeffs.len() - 1
3737
}
3838
}
@@ -211,7 +211,7 @@ impl<F: FftField> DensePolynomial<F> {
211211

212212
impl<F: Field> DensePolynomial<F> {
213213
fn truncate_leading_zeros(&mut self) {
214-
while self.coeffs.last().map_or(false, |c| c.is_zero()) {
214+
while self.coeffs.last().is_some_and(|c| c.is_zero()) {
215215
self.coeffs.pop();
216216
}
217217
}

poly/src/polynomial/univariate/sparse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<F: Field> Polynomial<F> for SparsePolynomial<F> {
6363
if self.is_zero() {
6464
0
6565
} else {
66-
assert!(self.coeffs.last().map_or(false, |(_, c)| !c.is_zero()));
66+
assert!(self.coeffs.last().is_some_and(|(_, c)| !c.is_zero()));
6767
self.coeffs.last().unwrap().0
6868
}
6969
}
@@ -240,7 +240,7 @@ impl<F: Field> SparsePolynomial<F> {
240240
/// of the same degree are ignored.
241241
pub fn from_coefficients_vec(mut coeffs: Vec<(usize, F)>) -> Self {
242242
// While there are zeros at the end of the coefficient vector, pop them off.
243-
while coeffs.last().map_or(false, |(_, c)| c.is_zero()) {
243+
while coeffs.last().is_some_and(|(_, c)| c.is_zero()) {
244244
coeffs.pop();
245245
}
246246
// Ensure that coeffs are in ascending order.

serialize/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,5 @@ pub const fn buffer_bit_byte_size(modulus_bits: usize) -> (usize, usize) {
241241
/// into the number of bytes required to represent it.
242242
#[inline]
243243
pub const fn buffer_byte_size(modulus_bits: usize) -> usize {
244-
(modulus_bits + 7) / 8
244+
modulus_bits.div_ceil(8)
245245
}

test-templates/src/glv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn glv_scalar_decomposition<P: GLVConfig>() {
2828
}
2929

3030
// check if k1 and k2 are indeed small.
31-
let expected_max_bits = (P::ScalarField::MODULUS_BIT_SIZE + 1) / 2;
31+
let expected_max_bits = P::ScalarField::MODULUS_BIT_SIZE.div_ceil(2);
3232
assert!(
3333
k1.into_bigint().num_bits() <= expected_max_bits,
3434
"k1 has {} bits",

0 commit comments

Comments
 (0)