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

Fix Cargo clippy #944

Merged
merged 4 commits into from
Nov 29, 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
2 changes: 1 addition & 1 deletion crypto/src/hash/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<P: PermutationParameters> Poseidon for P {
// Pad input with 1 followed by 0's (if necessary).
let mut values = inputs.to_owned();
values.push(FE::from(1));
values.resize(((values.len() + r - 1) / r) * r, FE::zero());
values.resize(values.len().div_ceil(r) * r, FE::zero());

assert!(values.len() % r == 0);
let mut state: Vec<FE<Self::F>> = vec![FE::zero(); m];
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/hash/sha3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Sha3Hasher {
pub fn expand_message(msg: &[u8], dst: &[u8], len_in_bytes: u64) -> Result<Vec<u8>, String> {
let b_in_bytes = Sha3_256::output_size() as u64;

let ell = (len_in_bytes + b_in_bytes - 1) / b_in_bytes;
let ell = len_in_bytes.div_ceil(b_in_bytes);
if ell > 255 {
return Err("Abort".to_string());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,11 @@ fn frobenius_square(
}

////////////////// CYCLOTOMIC SUBGROUP OPERATIONS //////////////////
/// Since the result of the Easy Part of the Final Exponentiation belongs to the cyclotomic
/// subgroup of Fp12, we can optimize the square and pow operations used in the Hard Part.
// Since the result of the Easy Part of the Final Exponentiation belongs to the cyclotomic
// subgroup of Fp12, we can optimize the square and pow operations used in the Hard Part.
/// Computes the square of an element of a cyclotomic subgroup of Fp12.
/// Algorithm from Constantine's cyclotomic_square_quad_over_cube
/// https://github.com/mratsim/constantine/blob/master/constantine/math/pairings/cyclotomic_subgroups.nim#L354
pub fn cyclotomic_square(a: &Fp12E) -> Fp12E {
// a = g + h * w
let [g, h] = a.value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ pub const X_BINARY: &[bool] = &[
];

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

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

/// Computes the square of an element of a cyclotomic subgroup of Fp12.
/// Algorithm from Constantine's cyclotomic_square_quad_over_cube
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type BN254FieldElement = FieldElement<BN254PrimeField>;
/// 01: compressed infinity point
/// the "uncompressed infinity point" will just have 00 (uncompressed) followed by zeroes (infinity = 0,0 in affine coordinates).
/// adapted from gnark https://github.com/consensys/gnark-crypto/blob/v0.13.0/ecc/bn254/marshal.go
impl Compress for BN254Curve {
type G1Point = G1Point;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ type Fp12E = FieldElement<Degree12ExtensionField>;
type G1Point = ShortWeierstrassProjectivePoint<BN254Curve>;
type G2Point = ShortWeierstrassProjectivePoint<BN254TwistCurve>;

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

////////////////// CONSTANTS //////////////////

Expand Down Expand Up @@ -492,12 +492,12 @@ pub fn frobenius_cube(

////////////////// CYCLOTOMIC SUBGROUP OPERATIONS //////////////////

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

/// Computes the square of an element of a cyclotomic subgroup of Fp12.
/// Algorithm from Constantine's cyclotomic_square_quad_over_cube
/// https://github.com/mratsim/constantine/blob/master/constantine/math/pairings/cyclotomic_subgroups.nim#L354
/// Compute the square of an element of a cyclotomic subgroup of Fp12.
/// Algorithm from Constantine's cyclotomic_square_quad_over_cube:
/// <https://github.com/mratsim/constantine/blob/master/constantine/math/pairings/cyclotomic_subgroups.nim#L354>
pub fn cyclotomic_square(a: &Fp12E) -> Fp12E {
// a = g + h * w
let [g, h] = a.value();
Expand Down
3 changes: 0 additions & 3 deletions math/src/unsigned_integer/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ impl<const NUM_LIMBS: usize> ShrAssign<usize> for UnsignedInteger<NUM_LIMBS> {
}

/// Impl BitAnd
impl<const NUM_LIMBS: usize> BitAnd for UnsignedInteger<NUM_LIMBS> {
type Output = Self;

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

/// Impl BitOr
impl<const NUM_LIMBS: usize> BitOr for UnsignedInteger<NUM_LIMBS> {
type Output = Self;

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

/// Impl BitXor
impl<const NUM_LIMBS: usize> BitXor for UnsignedInteger<NUM_LIMBS> {
type Output = Self;

Expand Down
Loading