Skip to content

Commit

Permalink
Merge branch 'master' into more-generics
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Nov 19, 2024
2 parents 70f6eeb + 93fc31e commit 202324a
Show file tree
Hide file tree
Showing 29 changed files with 783 additions and 359 deletions.
4 changes: 2 additions & 2 deletions curves/bls12_377/src/curves/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ark_ec::{
CurveConfig,
};
use ark_ff::{AdditiveGroup, BigInt, Field, MontFp, PrimeField, Zero};
use ark_std::{ops::Neg, One};
use ark_std::One;

use super::g1_swu_iso::{SwuIsoConfig, ISOGENY_MAP_TO_G1};
use crate::{Fq, Fr};
Expand Down Expand Up @@ -165,7 +165,7 @@ impl TECurveConfig for Config {
/// Multiplication by `a` is multiply by `-1`.
#[inline(always)]
fn mul_by_a(elem: Self::BaseField) -> Self::BaseField {
elem.neg()
-elem
}
}

Expand Down
3 changes: 1 addition & 2 deletions curves/bls12_377/src/curves/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use ark_ec::{
};

use ark_ff::{AdditiveGroup, BigInt, Field, MontFp, PrimeField, Zero};
use ark_std::ops::Neg;

use crate::*;

Expand Down Expand Up @@ -201,7 +200,7 @@ fn double_p_power_endomorphism(p: &Projective<Config>) -> Projective<Config> {

res.x *= DOUBLE_P_POWER_ENDOMORPHISM_COEFF_0;
// u^((p^2 - 1)/2) == -1
res.y = res.y.neg();
res.y = -res.y;

res
}
Expand Down
22 changes: 9 additions & 13 deletions curves/bls12_377/src/fields/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use ark_ff::{
fields::{FftField, Field, Fp6Config, PrimeField},
Fp384, One, UniformRand, Zero,
};
use ark_std::{
cmp::Ordering,
ops::{AddAssign, MulAssign},
test_rng,
};
use ark_std::{cmp::Ordering, ops::MulAssign, test_rng};

use crate::{Fq, Fq12, Fq2, Fq6, Fq6Config, Fr};

Expand Down Expand Up @@ -105,17 +101,17 @@ fn test_fq2_ordering() {
let mut b = a.clone();

assert!(a.cmp(&b) == Ordering::Equal);
b.c0.add_assign(&Fq::one());
b.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c0.add_assign(&Fq::one());
a.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Equal);
b.c1.add_assign(&Fq::one());
b.c1 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c0.add_assign(&Fq::one());
a.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c1.add_assign(&Fq::one());
a.c1 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Greater);
b.c0.add_assign(&Fq::one());
b.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Equal);
}

Expand Down Expand Up @@ -150,7 +146,7 @@ fn test_fq6_mul_by_1() {
let mut b = a;

a.mul_by_1(&c1);
b.mul_assign(&Fq6::new(Fq2::zero(), c1, Fq2::zero()));
b *= &Fq6::new(Fq2::zero(), c1, Fq2::zero());

assert_eq!(a, b);
}
Expand All @@ -167,7 +163,7 @@ fn test_fq6_mul_by_01() {
let mut b = a;

a.mul_by_01(&c0, &c1);
b.mul_assign(&Fq6::new(c0, c1, Fq2::zero()));
b *= &Fq6::new(c0, c1, Fq2::zero());

assert_eq!(a, b);
}
Expand Down
2 changes: 1 addition & 1 deletion curves/bls12_381/src/curves/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fn double_p_power_endomorphism(p: &Projective<Config>) -> Projective<Config> {
let mut res = *p;

res.x *= DOUBLE_P_POWER_ENDOMORPHISM_COEFF_0;
res.y = res.y.neg();
res.y = -res.y;

res
}
Expand Down
20 changes: 10 additions & 10 deletions curves/bls12_381/src/fields/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,17 +1204,17 @@ fn test_fq2_ordering() {
let mut b = a.clone();

assert!(a.cmp(&b) == Ordering::Equal);
b.c0.add_assign(&Fq::one());
b.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c0.add_assign(&Fq::one());
a.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Equal);
b.c1.add_assign(&Fq::one());
b.c1 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c0.add_assign(&Fq::one());
a.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c1.add_assign(&Fq::one());
a.c1 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Greater);
b.c0.add_assign(&Fq::one());
b.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Equal);
}

Expand Down Expand Up @@ -1732,7 +1732,7 @@ fn test_fq2_mul_nonresidue() {
let mut a = Fq2::rand(&mut rng);
let mut b = a;
Fq6Config::mul_fp2_by_nonresidue_in_place(&mut a);
b.mul_assign(&nqr);
b *= &nqr;

assert_eq!(a, b);
}
Expand All @@ -1748,7 +1748,7 @@ fn test_fq6_mul_nonresidue() {
let mut a = Fq6::rand(&mut rng);
let mut b = a;
Fq12Config::mul_fp6_by_nonresidue_in_place(&mut a);
b.mul_assign(&nqr);
b *= &nqr;

assert_eq!(a, b);
}
Expand All @@ -1764,7 +1764,7 @@ fn test_fq6_mul_by_1() {
let mut b = a;

a.mul_by_1(&c1);
b.mul_assign(&Fq6::new(Fq2::zero(), c1, Fq2::zero()));
b *= &Fq6::new(Fq2::zero(), c1, Fq2::zero());

assert_eq!(a, b);
}
Expand All @@ -1781,7 +1781,7 @@ fn test_fq6_mul_by_01() {
let mut b = a;

a.mul_by_01(&c0, &c1);
b.mul_assign(&Fq6::new(c0, c1, Fq2::zero()));
b *= &Fq6::new(c0, c1, Fq2::zero());

assert_eq!(a, b);
}
Expand Down
21 changes: 9 additions & 12 deletions curves/bn254/src/fields/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use ark_ff::{
fields::{FftField, Field, Fp6Config, PrimeField},
One, UniformRand, Zero,
};
use ark_std::{
cmp::Ordering,
ops::{AddAssign, MulAssign},
};
use ark_std::{cmp::Ordering, ops::MulAssign};

use crate::{Fq, Fq12, Fq2, Fq6, Fq6Config, Fr};

Expand Down Expand Up @@ -108,17 +105,17 @@ fn test_fq2_ordering() {
let mut b = a.clone();

assert!(a.cmp(&b) == Ordering::Equal);
b.c0.add_assign(&Fq::one());
b.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c0.add_assign(&Fq::one());
a.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Equal);
b.c1.add_assign(&Fq::one());
b.c1 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c0.add_assign(&Fq::one());
a.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Less);
a.c1.add_assign(&Fq::one());
a.c1 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Greater);
b.c0.add_assign(&Fq::one());
b.c0 += &Fq::one();
assert!(a.cmp(&b) == Ordering::Equal);
}

Expand Down Expand Up @@ -153,7 +150,7 @@ fn test_fq6_mul_by_1() {
let mut b = a;

a.mul_by_1(&c1);
b.mul_assign(&Fq6::new(Fq2::zero(), c1, Fq2::zero()));
b *= &Fq6::new(Fq2::zero(), c1, Fq2::zero());

assert_eq!(a, b);
}
Expand All @@ -170,7 +167,7 @@ fn test_fq6_mul_by_01() {
let mut b = a;

a.mul_by_01(&c0, &c1);
b.mul_assign(&Fq6::new(c0, c1, Fq2::zero()));
b *= &Fq6::new(c0, c1, Fq2::zero());

assert_eq!(a, b);
}
Expand Down
4 changes: 1 addition & 3 deletions ec/src/models/mnt4/g2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use ark_std::ops::Neg;

use crate::{
mnt4::MNT4Config,
models::mnt4::MNT4,
Expand Down Expand Up @@ -52,7 +50,7 @@ impl<P: MNT4Config> From<G2Affine<P>> for G2Prepared<P> {
t: <Fp2<P::Fp2Config>>::one(),
};

let neg_g = g.neg();
let neg_g = -g;
for bit in P::ATE_LOOP_COUNT.iter().skip(1) {
let (r2, coeff) = MNT4::doubling_for_flipped_miller_loop(&r);
g_prep.double_coefficients.push(coeff);
Expand Down
4 changes: 2 additions & 2 deletions ec/src/models/mnt6/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use ark_ff::fields::{Field, Fp3};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{ops::Neg, vec::*};
use ark_std::vec::*;
use educe::Educe;
use num_traits::One;

Expand Down Expand Up @@ -50,7 +50,7 @@ impl<P: MNT6Config> From<G2Affine<P>> for G2Prepared<P> {
t: <Fp3<P::Fp3Config>>::one(),
};

let neg_g = g.neg();
let neg_g = -g;
for bit in P::ATE_LOOP_COUNT.iter().skip(1) {
let (r2, coeff) = MNT6::doubling_for_flipped_miller_loop(&r);
g_prep.double_coefficients.push(coeff);
Expand Down
6 changes: 3 additions & 3 deletions ec/src/scalar_mul/glv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
AdditiveGroup, CurveGroup,
};
use ark_ff::{PrimeField, Zero};
use ark_std::ops::{AddAssign, Neg};
use ark_std::ops::Neg;
use num_bigint::{BigInt, BigUint, Sign};
use num_integer::Integer;
use num_traits::{One, Signed};
Expand Down Expand Up @@ -44,14 +44,14 @@ pub trait GLVConfig: Send + Sync + 'static + SWCurveConfig {
let beta_1 = {
let (mut div, rem) = (&scalar * &n22).div_rem(&r);
if (&rem + &rem) > r {
div.add_assign(BigInt::one());
div += BigInt::one();
}
div
};
let beta_2 = {
let (mut div, rem) = (&scalar * &n12.clone().neg()).div_rem(&r);
if (&rem + &rem) > r {
div.add_assign(BigInt::one());
div += BigInt::one();
}
div
};
Expand Down
Loading

0 comments on commit 202324a

Please sign in to comment.