diff --git a/crypto/src/hash/poseidon/mod.rs b/crypto/src/hash/poseidon/mod.rs index 547806999..67748081e 100644 --- a/crypto/src/hash/poseidon/mod.rs +++ b/crypto/src/hash/poseidon/mod.rs @@ -77,7 +77,7 @@ impl 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> = vec![FE::zero(); m]; diff --git a/crypto/src/hash/sha3/mod.rs b/crypto/src/hash/sha3/mod.rs index d55179cdd..9404e78f3 100644 --- a/crypto/src/hash/sha3/mod.rs +++ b/crypto/src/hash/sha3/mod.rs @@ -16,7 +16,7 @@ impl Sha3Hasher { pub fn expand_message(msg: &[u8], dst: &[u8], len_in_bytes: u64) -> Result, 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()); } diff --git a/math/src/elliptic_curve/short_weierstrass/curves/bls12_377/pairing.rs b/math/src/elliptic_curve/short_weierstrass/curves/bls12_377/pairing.rs index 0560adc20..ff61e4edd 100644 --- a/math/src/elliptic_curve/short_weierstrass/curves/bls12_377/pairing.rs +++ b/math/src/elliptic_curve/short_weierstrass/curves/bls12_377/pairing.rs @@ -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(); diff --git a/math/src/elliptic_curve/short_weierstrass/curves/bls12_381/pairing.rs b/math/src/elliptic_curve/short_weierstrass/curves/bls12_381/pairing.rs index 8107f69ec..0cf9ea067 100644 --- a/math/src/elliptic_curve/short_weierstrass/curves/bls12_381/pairing.rs +++ b/math/src/elliptic_curve/short_weierstrass/curves/bls12_381/pairing.rs @@ -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"), @@ -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 diff --git a/math/src/elliptic_curve/short_weierstrass/curves/bn_254/compression.rs b/math/src/elliptic_curve/short_weierstrass/curves/bn_254/compression.rs index 2daa32534..1c9a15c9a 100644 --- a/math/src/elliptic_curve/short_weierstrass/curves/bn_254/compression.rs +++ b/math/src/elliptic_curve/short_weierstrass/curves/bn_254/compression.rs @@ -26,7 +26,6 @@ type BN254FieldElement = FieldElement; /// 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; diff --git a/math/src/elliptic_curve/short_weierstrass/curves/bn_254/pairing.rs b/math/src/elliptic_curve/short_weierstrass/curves/bn_254/pairing.rs index 2fe67169e..b550d5013 100644 --- a/math/src/elliptic_curve/short_weierstrass/curves/bn_254/pairing.rs +++ b/math/src/elliptic_curve/short_weierstrass/curves/bn_254/pairing.rs @@ -32,12 +32,12 @@ type Fp12E = FieldElement; type G1Point = ShortWeierstrassProjectivePoint; type G2Point = ShortWeierstrassProjectivePoint; -/// 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 ////////////////// @@ -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: +/// pub fn cyclotomic_square(a: &Fp12E) -> Fp12E { // a = g + h * w let [g, h] = a.value(); diff --git a/math/src/unsigned_integer/element.rs b/math/src/unsigned_integer/element.rs index 1613e192b..e4b4a4d7c 100644 --- a/math/src/unsigned_integer/element.rs +++ b/math/src/unsigned_integer/element.rs @@ -327,7 +327,6 @@ impl ShrAssign for UnsignedInteger { } /// Impl BitAnd - impl BitAnd for UnsignedInteger { type Output = Self; @@ -348,7 +347,6 @@ impl BitAndAssign for UnsignedInteger { } /// Impl BitOr - impl BitOr for UnsignedInteger { type Output = Self; @@ -370,7 +368,6 @@ impl BitOrAssign for UnsignedInteger { } /// Impl BitXor - impl BitXor for UnsignedInteger { type Output = Self;