Skip to content

Commit

Permalink
Fix some clippy lints (arkworks-rs#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush authored Dec 30, 2022
1 parent de86562 commit 7300a0d
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 49 deletions.
2 changes: 1 addition & 1 deletion ec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub trait AffineRepr:
/// `Self::ScalarField`.
#[must_use]
fn mul_by_cofactor_inv(&self) -> Self {
self.mul_bigint(&Self::Config::COFACTOR_INV.into_bigint())
self.mul_bigint(Self::Config::COFACTOR_INV.into_bigint())
.into()
}
}
Expand Down
2 changes: 1 addition & 1 deletion ec/src/models/bn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<P: BnConfig> Bn<P> {
}

fn exp_by_neg_x(mut f: Fp12<P::Fp12Config>) -> Fp12<P::Fp12Config> {
f = f.cyclotomic_exp(&P::X);
f = f.cyclotomic_exp(P::X);
if !P::X_IS_NEGATIVE {
f.cyclotomic_inverse_in_place();
}
Expand Down
2 changes: 1 addition & 1 deletion ec/src/models/bw6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<P: BW6Config> BW6<P> {
}

fn exp_by_x(mut f: Fp6<P::Fp6Config>) -> Fp6<P::Fp6Config> {
f = f.cyclotomic_exp(&P::X);
f = f.cyclotomic_exp(P::X);
if P::X_IS_NEGATIVE {
f.cyclotomic_inverse_in_place();
}
Expand Down
6 changes: 3 additions & 3 deletions ec/src/models/mnt4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ impl<P: MNT4Config> MNT4<P> {
let mut elt_q = *elt;
elt_q.frobenius_map_in_place(1);

let w1_part = elt_q.cyclotomic_exp(&P::FINAL_EXPONENT_LAST_CHUNK_1);
let w1_part = elt_q.cyclotomic_exp(P::FINAL_EXPONENT_LAST_CHUNK_1);
let w0_part = if P::FINAL_EXPONENT_LAST_CHUNK_W0_IS_NEG {
elt_inv_clone.cyclotomic_exp(&P::FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0)
elt_inv_clone.cyclotomic_exp(P::FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0)
} else {
elt_clone.cyclotomic_exp(&P::FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0)
elt_clone.cyclotomic_exp(P::FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0)
};

w1_part * &w0_part
Expand Down
6 changes: 3 additions & 3 deletions ec/src/models/mnt6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ impl<P: MNT6Config> MNT6<P> {
let mut elt_q = *elt;
elt_q.frobenius_map_in_place(1);

let w1_part = elt_q.cyclotomic_exp(&P::FINAL_EXPONENT_LAST_CHUNK_1);
let w1_part = elt_q.cyclotomic_exp(P::FINAL_EXPONENT_LAST_CHUNK_1);
let w0_part = if P::FINAL_EXPONENT_LAST_CHUNK_W0_IS_NEG {
elt_inv_clone.cyclotomic_exp(&P::FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0)
elt_inv_clone.cyclotomic_exp(P::FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0)
} else {
elt_clone.cyclotomic_exp(&P::FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0)
elt_clone.cyclotomic_exp(P::FINAL_EXPONENT_LAST_CHUNK_ABS_OF_W0)
};

w1_part * &w0_part
Expand Down
2 changes: 1 addition & 1 deletion ec/src/models/short_weierstrass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub trait SWCurveConfig: super::CurveConfig {
) -> Result<Projective<Self>, usize> {
(bases.len() == scalars.len())
.then(|| VariableBaseMSM::msm_unchecked(bases, scalars))
.ok_or(usize::min(bases.len(), scalars.len()))
.ok_or(bases.len().min(scalars.len()))
}

/// If uncompressed, serializes both x and y coordinates as well as a bit for whether it is
Expand Down
2 changes: 1 addition & 1 deletion ec/src/models/twisted_edwards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub trait TECurveConfig: super::CurveConfig {
) -> Result<Projective<Self>, usize> {
(bases.len() == scalars.len())
.then(|| VariableBaseMSM::msm_unchecked(bases, scalars))
.ok_or(usize::min(bases.len(), scalars.len()))
.ok_or(bases.len().min(scalars.len()))
}

/// If uncompressed, serializes both x and y coordinates.
Expand Down
2 changes: 1 addition & 1 deletion ec/src/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<P: Pairing> CanonicalSerialize for PairingOutput<P> {

impl<P: Pairing> Valid for PairingOutput<P> {
fn check(&self) -> Result<(), SerializationError> {
if self.0.pow(&P::ScalarField::characteristic()).is_one() {
if self.0.pow(P::ScalarField::characteristic()).is_one() {
Ok(())
} else {
Err(SerializationError::InvalidData)
Expand Down
11 changes: 5 additions & 6 deletions ec/src/scalar_mul/variable_base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub trait VariableBaseMSM: ScalarMul {
fn msm(bases: &[Self::MulBase], scalars: &[Self::ScalarField]) -> Result<Self, usize> {
(bases.len() == scalars.len())
.then(|| Self::msm_unchecked(bases, scalars))
.ok_or(usize::min(bases.len(), scalars.len()))
.ok_or(bases.len().min(scalars.len()))
}

/// Optimized implementation of multi-scalar multiplication.
Expand Down Expand Up @@ -265,15 +265,14 @@ fn make_digits(a: &impl BigInteger, w: usize, num_bits: usize) -> Vec<i64> {
let u64_idx = bit_offset / 64;
let bit_idx = bit_offset % 64;
// Read the bits from the scalar
let bit_buf: u64;
if bit_idx < 64 - w || u64_idx == scalar.len() - 1 {
let bit_buf = if bit_idx < 64 - w || u64_idx == scalar.len() - 1 {
// This window's bits are contained in a single u64,
// or it's the last u64 anyway.
bit_buf = scalar[u64_idx] >> bit_idx;
scalar[u64_idx] >> bit_idx
} else {
// Combine the current u64's bits with the bits from the next u64
bit_buf = (scalar[u64_idx] >> bit_idx) | (scalar[1 + u64_idx] << (64 - bit_idx));
}
(scalar[u64_idx] >> bit_idx) | (scalar[1 + u64_idx] << (64 - bit_idx))
};

// Read the actual coefficient value from the window
let coef = carry + (bit_buf & window_mask); // coef = [0, 2^r)
Expand Down
2 changes: 1 addition & 1 deletion ff-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn unroll_for_loops(args: TokenStream, input: TokenStream) -> TokenStream {
block: ref box_block,
..
} = &item_fn;
unroll::unroll_in_block(&**box_block, unroll_by)
unroll::unroll_in_block(box_block, unroll_by)
};
let new_item = Item::Fn(ItemFn {
block: Box::new(new_block),
Expand Down
2 changes: 0 additions & 2 deletions ff-macros/src/montgomery/biginteger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub(super) fn add_with_carry_impl(num_limbs: usize) -> proc_macro2::TokenStream
#body
}
}
.into()
}

pub(super) fn sub_with_borrow_impl(num_limbs: usize) -> proc_macro2::TokenStream {
Expand All @@ -49,7 +48,6 @@ pub(super) fn sub_with_borrow_impl(num_limbs: usize) -> proc_macro2::TokenStream
#body
}
}
.into()
}

pub(super) fn subtract_modulus_impl(
Expand Down
1 change: 0 additions & 1 deletion ff-macros/src/montgomery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,4 @@ pub fn mont_config_helper(
#sub_with_borrow
}
}
.into()
}
3 changes: 1 addition & 2 deletions ff-macros/src/montgomery/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ pub(super) fn mul_assign_impl(
let mut carry2 = 0u64;
fa::mac_discard(r[0], k, #modulus_0, &mut carry2);
});
for j in 1..num_limbs {
let modulus_j = modulus_limbs[j];
for (j, modulus_j) in modulus_limbs.iter().enumerate().take(num_limbs).skip(1) {
let idx = j - 1;
default.extend(quote! {
r[#j] = fa::mac_with_carry(r[#j], (a.0).0[#j], (b.0).0[#i], &mut carry1);
Expand Down
3 changes: 1 addition & 2 deletions ff-macros/src/montgomery/square.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ pub(super) fn square_in_place_impl(
let mut carry = 0;
fa::mac_discard(r[#i], k, #modulus_0, &mut carry);
});
for j in 1..num_limbs {
for (j, modulus_j) in modulus_limbs.iter().enumerate().take(num_limbs).skip(1) {
let idx = j + i;
let modulus_j = modulus_limbs[j];
default.extend(quote! {
r[#idx] = fa::mac_with_carry(r[#idx], k, #modulus_j, &mut carry);
});
Expand Down
3 changes: 1 addition & 2 deletions ff-macros/src/montgomery/sum_of_products.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ pub(super) fn sum_of_products_impl(num_limbs: usize, modulus: &[u64]) -> proc_ma
});
}
let mut mont_red_body = proc_macro2::TokenStream::new();
for i in 1..num_limbs {
let modulus_i = modulus[i];
for (i, modulus_i) in modulus.iter().enumerate().take(num_limbs).skip(1) {
mont_red_body.extend(quote! {
result.0[#i - 1] = fa::mac_with_carry(result.0[#i], k, #modulus_i, &mut carry2);
});
Expand Down
6 changes: 3 additions & 3 deletions ff-macros/src/unroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,17 @@ fn unroll(expr: &Expr, unroll_by: usize) -> Expr {
..
} = *if_expr;
Expr::If(ExprIf {
cond: Box::new(unroll(&**cond, unroll_by)),
cond: Box::new(unroll(cond, unroll_by)),
then_branch: unroll_in_block(then_branch, unroll_by),
else_branch: else_branch
.as_ref()
.map(|x| (x.0, Box::new(unroll(&*x.1, unroll_by)))),
.map(|x| (x.0, Box::new(unroll(&x.1, unroll_by)))),
..(*if_expr).clone()
})
} else if let Expr::Let(let_expr) = expr {
let ExprLet { ref expr, .. } = *let_expr;
Expr::Let(ExprLet {
expr: Box::new(unroll(&**expr, unroll_by)),
expr: Box::new(unroll(expr, unroll_by)),
..(*let_expr).clone()
})
} else if let Expr::Block(expr_block) = expr {
Expand Down
6 changes: 1 addition & 5 deletions ff/src/biginteger/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ macro_rules! sbb {
pub(crate) fn sbb(a: &mut u64, b: u64, borrow: u64) -> u64 {
let tmp = (1u128 << 64) + (*a as u128) - (b as u128) - (borrow as u128);
*a = tmp as u64;
if tmp >> 64 == 0 {
1
} else {
0
}
(tmp >> 64 == 0) as u64
}

/// Sets a = a - b - borrow, and returns the borrow.
Expand Down
2 changes: 1 addition & 1 deletion ff/src/fields/fft_friendly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub trait FftField: crate::Field {

omega = large_subgroup_root_of_unity;
for _ in q_adicity..small_subgroup_base_adicity {
omega = omega.pow(&[q as u64]);
omega = omega.pow([q as u64]);
}

for _ in two_adicity..Self::TWO_ADICITY {
Expand Down
2 changes: 1 addition & 1 deletion poly/src/evaluations/multivariate/multilinear/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn precompute_eq<F: Field>(g: &[F]) -> Vec<F> {
dp[0] = F::one() - g[0];
dp[1] = g[0];
for i in 1..dim {
let dp_prev = (&dp[0..(1 << i)]).to_vec();
let dp_prev = dp[0..(1 << i)].to_vec();
for b in 0..(1 << i) {
dp[b] = dp_prev[b] * (F::one() - g[i]);
dp[b + (1 << i)] = dp_prev[b] * g[i];
Expand Down
2 changes: 1 addition & 1 deletion poly/src/polynomial/multivariate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Term for SparseTerm {
/// Evaluates `self` at the given `point` in the field.
fn evaluate<F: Field>(&self, point: &[F]) -> F {
cfg_into_iter!(self)
.map(|(var, power)| point[*var].pow(&[*power as u64]))
.map(|(var, power)| point[*var].pow([*power as u64]))
.product()
}
}
Expand Down
2 changes: 1 addition & 1 deletion poly/src/polynomial/multivariate/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<F: Field, T: Term> Neg for SparsePolynomial<F, T> {
#[inline]
fn neg(mut self) -> SparsePolynomial<F, T> {
for coeff in &mut self.terms {
(*coeff).0 = -coeff.0;
(coeff).0 = -coeff.0;
}
self
}
Expand Down
8 changes: 4 additions & 4 deletions poly/src/polynomial/univariate/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ impl<F: Field> Polynomial<F> for SparsePolynomial<F> {
.iter()
.map(|(i, c)| {
debug_assert_eq!(
F::pow_with_table(&powers_of_2[..], &[*i as u64]).unwrap(),
point.pow(&[*i as u64]),
F::pow_with_table(&powers_of_2[..], [*i as u64]).unwrap(),
point.pow([*i as u64]),
"pows not equal"
);
*c * F::pow_with_table(&powers_of_2[..], &[*i as u64]).unwrap()
*c * F::pow_with_table(&powers_of_2[..], [*i as u64]).unwrap()
})
.sum();
total
Expand Down Expand Up @@ -207,7 +207,7 @@ impl<'b, F: Field> Mul<F> for &'b SparsePolynomial<F> {
} else {
let mut result = self.clone();
cfg_iter_mut!(result).for_each(|e| {
(*e).1 *= elem;
e.1 *= elem;
});
result
}
Expand Down
20 changes: 15 additions & 5 deletions test-templates/src/h2c/json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[derive(
Default, Debug, Clone, PartialEq, Eq, serde_derive::Serialize, serde_derive::Deserialize,
)]
#[serde(rename_all = "camelCase")]
pub struct SuiteVector {
pub ciphersuite: String,
Expand All @@ -11,20 +13,26 @@ pub struct SuiteVector {
pub vectors: Vec<Vector>,
}

#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[derive(
Default, Debug, Clone, PartialEq, Eq, serde_derive::Serialize, serde_derive::Deserialize,
)]
#[serde(rename_all = "camelCase")]
pub struct Field {
pub m: String,
pub p: String,
}

#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[derive(
Default, Debug, Clone, PartialEq, Eq, serde_derive::Serialize, serde_derive::Deserialize,
)]
#[serde(rename_all = "camelCase")]
pub struct Map {
pub name: String,
}

#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[derive(
Default, Debug, Clone, PartialEq, Eq, serde_derive::Serialize, serde_derive::Deserialize,
)]
#[serde(rename_all = "camelCase")]
pub struct Vector {
#[serde(rename = "P")]
Expand All @@ -33,7 +41,9 @@ pub struct Vector {
pub u: Vec<String>,
}

#[derive(Default, Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[derive(
Default, Debug, Clone, PartialEq, Eq, serde_derive::Serialize, serde_derive::Deserialize,
)]
#[serde(rename_all = "camelCase")]
pub struct P {
pub x: String,
Expand Down

0 comments on commit 7300a0d

Please sign in to comment.