Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jotabulacios committed Jan 8, 2025
1 parent 38b0b73 commit fa86070
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions math/benches/fields/baby_bear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rand::Rng;
pub type U32Babybear31PrimeField = U32MontgomeryBackendPrimeField<2013265921>;
pub type F = FieldElement<U32Babybear31PrimeField>;
pub type F64 = FieldElement<Babybear31PrimeField>;
pub type Fp4E_u32 = FieldElement<Degree4BabyBearU32ExtensionField>;
pub type Fp4Eu32 = FieldElement<Degree4BabyBearU32ExtensionField>;
pub type Fp4E = FieldElement<Degree4BabyBearExtensionField>;
type EF4 = BinomialExtensionField<BabyBear, 4>;

Expand Down Expand Up @@ -63,17 +63,17 @@ pub fn rand_babybear_u64_fp4_elements(num: usize) -> Vec<(Fp4E, Fp4E)> {
}
result
}
pub fn rand_babybear_u32_fp4_elements(num: usize) -> Vec<(Fp4E_u32, Fp4E_u32)> {
pub fn rand_babybear_u32_fp4_elements(num: usize) -> Vec<(Fp4Eu32, Fp4Eu32)> {
let mut result = Vec::with_capacity(num);
for _ in 0..num {
result.push((
Fp4E_u32::new([
Fp4Eu32::new([
F::from(random::<u64>()),
F::from(random::<u64>()),
F::from(random::<u64>()),
F::from(random::<u64>()),
]),
Fp4E_u32::new([
Fp4Eu32::new([
F::from(random::<u64>()),
F::from(random::<u64>()),
F::from(random::<u64>()),
Expand Down Expand Up @@ -214,7 +214,7 @@ pub fn babybear_u64_ops_benchmarks(c: &mut Criterion) {
}
}
pub fn babybear_u32_extension_ops_benchmarks(c: &mut Criterion) {
let input: Vec<Vec<(Fp4E_u32, Fp4E_u32)>> = [1000000]
let input: Vec<Vec<(Fp4Eu32, Fp4Eu32)>> = [1000000]
.into_iter()
.map(rand_babybear_u32_fp4_elements)
.collect::<Vec<_>>();
Expand Down
40 changes: 20 additions & 20 deletions math/src/field/fields/fft_friendly/quartic_babybear_u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ impl IsField for Degree4BabyBearU32ExtensionField {
type BaseType = [FieldElement<Babybear31PrimeField>; 4];

fn add(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType {
[&a[0] + &b[0], &a[1] + &b[1], &a[2] + &b[2], &a[3] + &b[3]]
[a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]]
}

/// Result of multiplying two polynomials a = a0 + a1 * x + a2 * x^2 + a3 * x^3 and
/// b = b0 + b1 * x + b2 * x^2 + b3 * x^3 by applying distribution and taking
/// the remainder of the division by x^4 + 11.
fn mul(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType {
[
&a[0] * &b[0] - BETA * (&a[1] * &b[3] + &a[3] * &b[1] + &a[2] * &b[2]),
&a[0] * &b[1] + &a[1] * &b[0] - BETA * (&a[2] * &b[3] + &a[3] * &b[2]),
&a[0] * &b[2] + &a[2] * &b[0] + &a[1] * &b[1] - BETA * (&a[3] * &b[3]),
&a[0] * &b[3] + &a[3] * &b[0] + &a[1] * &b[2] + &a[2] * &b[1],
a[0] * b[0] - BETA * (a[1] * b[3] + a[3] * b[1] + a[2] * b[2]),
a[0] * b[1] + a[1] * b[0] - BETA * (a[2] * b[3] + a[3] * b[2]),
a[0] * b[2] + a[2] * b[0] + a[1] * b[1] - BETA * (a[3] * b[3]),
a[0] * b[3] + a[3] * b[0] + a[1] * b[2] + a[2] * b[1],
]
}

fn square(a: &Self::BaseType) -> Self::BaseType {
[
&a[0].square() - BETA * ((&a[1] * &a[3]).double() + &a[2].square()),
(&a[0] * &a[1] - BETA * (&a[2] * &a[3])).double(),
(&a[0] * &a[2]).double() + &a[1].square() - BETA * (&a[3].square()),
(&a[0] * &a[3] + &a[1] * &a[2]).double(),
a[0].square() - BETA * ((a[1] * a[3]).double() + a[2].square()),
(a[0] * a[1] - BETA * (a[2] * a[3])).double(),
(a[0] * a[2]).double() + a[1].square() - BETA * (a[3].square()),
(a[0] * a[3] + a[1] * a[2]).double(),
]
}

fn sub(a: &Self::BaseType, b: &Self::BaseType) -> Self::BaseType {
[&a[0] - &b[0], &a[1] - &b[1], &a[2] - &b[2], &a[3] - &b[3]]
[a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]]
}

fn neg(a: &Self::BaseType) -> Self::BaseType {
Expand All @@ -64,17 +64,17 @@ impl IsField for Degree4BabyBearU32ExtensionField {
/// This algorithm is inspired by Risc0 implementation:
/// <https://github.com/risc0/risc0/blob/4c41c739779ef2759a01ebcf808faf0fbffe8793/risc0/core/src/field/baby_bear.rs#L460>
fn inv(a: &Self::BaseType) -> Result<Self::BaseType, FieldError> {
let mut b0 = &a[0] * &a[0] + BETA * (&a[1] * (&a[3] + &a[3]) - &a[2] * &a[2]);
let mut b2 = &a[0] * (&a[2] + &a[2]) - &a[1] * &a[1] + BETA * (&a[3] * &a[3]);
let c = &b0.square() + BETA * b2.square();
let mut b0 = a[0] * a[0] + BETA * (a[1] * (a[3] + a[3]) - a[2] * a[2]);
let mut b2 = a[0] * (a[2] + a[2]) - a[1] * a[1] + BETA * (a[3] * a[3]);
let c = b0.square() + BETA * b2.square();
let c_inv = c.inv()?;
b0 *= &c_inv;
b2 *= &c_inv;
Ok([
&a[0] * &b0 + BETA * &a[2] * &b2,
-&a[1] * &b0 - BETA * &a[3] * &b2,
-&a[0] * &b2 + &a[2] * &b0,
&a[1] * &b2 - &a[3] * &b0,
a[0] * b0 + BETA * a[2] * b2,
-a[1] * b0 - BETA * a[3] * b2,
-a[0] * b2 + a[2] * b0,
a[1] * b2 - a[3] * b0,
])
}

Expand Down Expand Up @@ -131,10 +131,10 @@ impl IsField for Degree4BabyBearU32ExtensionField {
return Self::one();
}
if exponent == one {
return a.clone();
return *a;
}

let mut result = a.clone();
let mut result = *a;

// Fast path for powers of 2
while exponent & one == zero {
Expand All @@ -145,7 +145,7 @@ impl IsField for Degree4BabyBearU32ExtensionField {
}
}

let mut base = result.clone();
let mut base = result;
exponent >>= 1;

while exponent != zero {
Expand Down

0 comments on commit fa86070

Please sign in to comment.