Skip to content

Commit fc33967

Browse files
nicole-grausjotabulaciosNicole
authored
Fix Cargo clippy (lambdaclass#944)
* fix clippy * fix clippy * change div_ceil and comment on expect() * fix div_ceil --------- Co-authored-by: jotabulacios <jbulacios@fi.uba.ar> Co-authored-by: Nicole <nicole@Nicoles-MacBook-Air.local>
1 parent d016a73 commit fc33967

File tree

7 files changed

+18
-25
lines changed

7 files changed

+18
-25
lines changed

crypto/src/hash/poseidon/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<P: PermutationParameters> Poseidon for P {
7777
// Pad input with 1 followed by 0's (if necessary).
7878
let mut values = inputs.to_owned();
7979
values.push(FE::from(1));
80-
values.resize(((values.len() + r - 1) / r) * r, FE::zero());
80+
values.resize(values.len().div_ceil(r) * r, FE::zero());
8181

8282
assert!(values.len() % r == 0);
8383
let mut state: Vec<FE<Self::F>> = vec![FE::zero(); m];

crypto/src/hash/sha3/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Sha3Hasher {
1616
pub fn expand_message(msg: &[u8], dst: &[u8], len_in_bytes: u64) -> Result<Vec<u8>, String> {
1717
let b_in_bytes = Sha3_256::output_size() as u64;
1818

19-
let ell = (len_in_bytes + b_in_bytes - 1) / b_in_bytes;
19+
let ell = len_in_bytes.div_ceil(b_in_bytes);
2020
if ell > 255 {
2121
return Err("Abort".to_string());
2222
}

math/src/elliptic_curve/short_weierstrass/curves/bls12_377/pairing.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,11 @@ fn frobenius_square(
232232
}
233233

234234
////////////////// CYCLOTOMIC SUBGROUP OPERATIONS //////////////////
235-
/// Since the result of the Easy Part of the Final Exponentiation belongs to the cyclotomic
236-
/// subgroup of Fp12, we can optimize the square and pow operations used in the Hard Part.
237-
235+
// Since the result of the Easy Part of the Final Exponentiation belongs to the cyclotomic
236+
// subgroup of Fp12, we can optimize the square and pow operations used in the Hard Part.
238237
/// Computes the square of an element of a cyclotomic subgroup of Fp12.
239238
/// Algorithm from Constantine's cyclotomic_square_quad_over_cube
240239
/// https://github.com/mratsim/constantine/blob/master/constantine/math/pairings/cyclotomic_subgroups.nim#L354
241-
242240
pub fn cyclotomic_square(a: &Fp12E) -> Fp12E {
243241
// a = g + h * w
244242
let [g, h] = a.value();

math/src/elliptic_curve/short_weierstrass/curves/bls12_381/pairing.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ pub const X_BINARY: &[bool] = &[
4040
];
4141

4242
// GAMMA constants used to compute the Frobenius morphisms
43-
/// We took these constants from https://github.com/hecmas/zkNotebook/blob/main/src/BLS12381/constants.ts
44-
43+
// We took these constants from https://github.com/hecmas/zkNotebook/blob/main/src/BLS12381/constants.ts
4544
pub const GAMMA_11: Fp2E = Fp2E::const_from_raw([
4645
FpE::from_hex_unchecked("1904D3BF02BB0667C231BEB4202C0D1F0FD603FD3CBD5F4F7B2443D784BAB9C4F67EA53D63E7813D8D0775ED92235FB8"),
4746
FpE::from_hex_unchecked("FC3E2B36C4E03288E9E902231F9FB854A14787B6C7B36FEC0C8EC971F63C5F282D5AC14D6C7EC22CF78A126DDC4AF3"),
@@ -315,8 +314,8 @@ fn frobenius_square(
315314
}
316315

317316
////////////////// CYCLOTOMIC SUBGROUP OPERATIONS //////////////////
318-
/// Since the result of the Easy Part of the Final Exponentiation belongs to the cyclotomic
319-
/// subgroup of Fp12, we can optimize the square and pow operations used in the Hard Part.
317+
// Since the result of the Easy Part of the Final Exponentiation belongs to the cyclotomic
318+
// subgroup of Fp12, we can optimize the square and pow operations used in the Hard Part.
320319

321320
/// Computes the square of an element of a cyclotomic subgroup of Fp12.
322321
/// Algorithm from Constantine's cyclotomic_square_quad_over_cube

math/src/elliptic_curve/short_weierstrass/curves/bn_254/compression.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type BN254FieldElement = FieldElement<BN254PrimeField>;
2626
/// 01: compressed infinity point
2727
/// the "uncompressed infinity point" will just have 00 (uncompressed) followed by zeroes (infinity = 0,0 in affine coordinates).
2828
/// adapted from gnark https://github.com/consensys/gnark-crypto/blob/v0.13.0/ecc/bn254/marshal.go
29-
3029
impl Compress for BN254Curve {
3130
type G1Point = G1Point;
3231

math/src/elliptic_curve/short_weierstrass/curves/bn_254/pairing.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ type Fp12E = FieldElement<Degree12ExtensionField>;
3232
type G1Point = ShortWeierstrassProjectivePoint<BN254Curve>;
3333
type G2Point = ShortWeierstrassProjectivePoint<BN254TwistCurve>;
3434

35-
/// You can find an explanation of the next implemetation in our post
36-
/// https://blog.lambdaclass.com/how-we-implemented-the-bn254-ate-pairing-in-lambdaworks/
37-
/// There you'll come across a path to understand the naive implementation of the pairing
38-
/// using the functions miller_naive() and final_exponentiation_naive().
39-
/// We then optimized the pairing using the functions miller_optimized() and final_exponentiation_optimized().
40-
/// You'll find both the naive and optimized versions below.
35+
// You can find an explanation of the next implemetation in our post
36+
// https://blog.lambdaclass.com/how-we-implemented-the-bn254-ate-pairing-in-lambdaworks/
37+
// There you'll come across a path to understand the naive implementation of the pairing
38+
// using the functions miller_naive() and final_exponentiation_naive().
39+
// We then optimized the pairing using the functions miller_optimized() and final_exponentiation_optimized().
40+
// You'll find both the naive and optimized versions below.
4141

4242
////////////////// CONSTANTS //////////////////
4343

@@ -492,12 +492,12 @@ pub fn frobenius_cube(
492492

493493
////////////////// CYCLOTOMIC SUBGROUP OPERATIONS //////////////////
494494

495-
/// Since the result of the Easy Part of the Final Exponentiation belongs to the cyclotomic
496-
/// subgroup of Fp12, we can optimize the square and pow operations used in the Hard Part.
495+
// Since the result of the Easy Part of the Final Exponentiation belongs to the cyclotomic
496+
// subgroup of Fp12, we can optimize the square and pow operations used in the Hard Part.
497497

498-
/// Computes the square of an element of a cyclotomic subgroup of Fp12.
499-
/// Algorithm from Constantine's cyclotomic_square_quad_over_cube
500-
/// https://github.com/mratsim/constantine/blob/master/constantine/math/pairings/cyclotomic_subgroups.nim#L354
498+
/// Compute the square of an element of a cyclotomic subgroup of Fp12.
499+
/// Algorithm from Constantine's cyclotomic_square_quad_over_cube:
500+
/// <https://github.com/mratsim/constantine/blob/master/constantine/math/pairings/cyclotomic_subgroups.nim#L354>
501501
pub fn cyclotomic_square(a: &Fp12E) -> Fp12E {
502502
// a = g + h * w
503503
let [g, h] = a.value();

math/src/unsigned_integer/element.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ impl<const NUM_LIMBS: usize> ShrAssign<usize> for UnsignedInteger<NUM_LIMBS> {
327327
}
328328

329329
/// Impl BitAnd
330-
331330
impl<const NUM_LIMBS: usize> BitAnd for UnsignedInteger<NUM_LIMBS> {
332331
type Output = Self;
333332

@@ -348,7 +347,6 @@ impl<const NUM_LIMBS: usize> BitAndAssign for UnsignedInteger<NUM_LIMBS> {
348347
}
349348

350349
/// Impl BitOr
351-
352350
impl<const NUM_LIMBS: usize> BitOr for UnsignedInteger<NUM_LIMBS> {
353351
type Output = Self;
354352

@@ -370,7 +368,6 @@ impl<const NUM_LIMBS: usize> BitOrAssign for UnsignedInteger<NUM_LIMBS> {
370368
}
371369

372370
/// Impl BitXor
373-
374371
impl<const NUM_LIMBS: usize> BitXor for UnsignedInteger<NUM_LIMBS> {
375372
type Output = Self;
376373

0 commit comments

Comments
 (0)