Browse Source

Add `frobenius_map_in_place` (#140)

cherry-pick
Pratyush Mishra 1 year ago
committed by GitHub
parent
commit
cba0c7ef0d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 15 deletions
  1. +4
    -4
      Cargo.toml
  2. +2
    -2
      bls12_381/src/curves/g2.rs
  3. +5
    -5
      bls12_381/src/fields/tests.rs
  4. +3
    -3
      cp6_782/src/curves/mod.rs
  5. +1
    -1
      curve-constraint-tests/src/lib.rs

+ 4
- 4
Cargo.toml

@ -64,9 +64,9 @@ debug-assertions = true
debug = true debug = true
[patch.crates-io] [patch.crates-io]
ark-ff = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4-debug-secp256k1" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4-debug-secp256k1" }
ark-ff = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4" } ark-poly = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4-debug-secp256k1" }
ark-algebra-test-templates = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4-debug-secp256k1" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4" }
ark-algebra-test-templates = { git = "https://github.com/arkworks-rs/algebra/", branch = "release-0.4" }
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/", branch = "release-0.4" } ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/", branch = "release-0.4" }

+ 2
- 2
bls12_381/src/curves/g2.rs

@ -240,8 +240,8 @@ pub fn p_power_endomorphism(p: &Affine) -> Affine {
// as implemented in the code as follows. // as implemented in the code as follows.
let mut res = *p; let mut res = *p;
res.x.frobenius_map(1);
res.y.frobenius_map(1);
res.x.frobenius_map_in_place(1);
res.y.frobenius_map_in_place(1);
let tmp_x = res.x.clone(); let tmp_x = res.x.clone();
res.x.c0 = -P_POWER_ENDOMORPHISM_COEFF_0.c1 * &tmp_x.c1; res.x.c0 = -P_POWER_ENDOMORPHISM_COEFF_0.c1 * &tmp_x.c1;

+ 5
- 5
bls12_381/src/fields/tests.rs

@ -1601,7 +1601,7 @@ fn test_fq2_doubling() {
} }
#[test] #[test]
fn test_fq2_frobenius_map() {
fn test_fq2_frobenius_map_in_place() {
let mut a = Fq2::new( let mut a = Fq2::new(
Fq::from(BigInt::new([ Fq::from(BigInt::new([
0x2d0078036923ffc7, 0x2d0078036923ffc7,
@ -1620,7 +1620,7 @@ fn test_fq2_frobenius_map() {
0x12d1137b8a6a837, 0x12d1137b8a6a837,
])), ])),
); );
a.frobenius_map(0);
a.frobenius_map_in_place(0);
assert_eq!( assert_eq!(
a, a,
Fq2::new( Fq2::new(
@ -1642,7 +1642,7 @@ fn test_fq2_frobenius_map() {
])), ])),
) )
); );
a.frobenius_map(1);
a.frobenius_map_in_place(1);
assert_eq!( assert_eq!(
a, a,
Fq2::new( Fq2::new(
@ -1664,7 +1664,7 @@ fn test_fq2_frobenius_map() {
])), ])),
) )
); );
a.frobenius_map(1);
a.frobenius_map_in_place(1);
assert_eq!( assert_eq!(
a, a,
Fq2::new( Fq2::new(
@ -1686,7 +1686,7 @@ fn test_fq2_frobenius_map() {
])), ])),
) )
); );
a.frobenius_map(2);
a.frobenius_map_in_place(2);
assert_eq!( assert_eq!(
a, a,
Fq2::new( Fq2::new(

+ 3
- 3
cp6_782/src/curves/mod.rs

@ -129,19 +129,19 @@ impl CP6_782 {
// elt_q3 = elt^(q^3) // elt_q3 = elt^(q^3)
let mut elt_q3 = elt.clone(); let mut elt_q3 = elt.clone();
elt_q3.frobenius_map(3);
elt_q3.frobenius_map_in_place(3);
// elt_q3_over_elt = elt^(q^3-1) // elt_q3_over_elt = elt^(q^3-1)
let elt_q3_over_elt = elt_q3 * elt_inv; let elt_q3_over_elt = elt_q3 * elt_inv;
// alpha = elt^((q^3-1) * q) // alpha = elt^((q^3-1) * q)
let mut alpha = elt_q3_over_elt.clone(); let mut alpha = elt_q3_over_elt.clone();
alpha.frobenius_map(1);
alpha.frobenius_map_in_place(1);
// beta = elt^((q^3-1)*(q+1) // beta = elt^((q^3-1)*(q+1)
alpha * &elt_q3_over_elt alpha * &elt_q3_over_elt
} }
fn final_exponentiation_last(elt: &Fq6, elt_inv: &Fq6) -> Fq6 { fn final_exponentiation_last(elt: &Fq6, elt_inv: &Fq6) -> Fq6 {
let mut elt_q = elt.clone(); let mut elt_q = elt.clone();
elt_q.frobenius_map(1);
elt_q.frobenius_map_in_place(1);
let w1_part = elt_q.cyclotomic_exp(&FINAL_EXPONENT_LAST_CHUNK_W1); let w1_part = elt_q.cyclotomic_exp(&FINAL_EXPONENT_LAST_CHUNK_W1);
let w0_part = if FINAL_EXPONENT_LAST_CHUNK_W0_IS_NEG { let w0_part = if FINAL_EXPONENT_LAST_CHUNK_W0_IS_NEG {

+ 1
- 1
curve-constraint-tests/src/lib.rs

@ -211,7 +211,7 @@ pub mod fields {
let mut a = F::rand(&mut rng); let mut a = F::rand(&mut rng);
let mut a_gadget = AF::new_variable(ark_relations::ns!(cs, "a"), || Ok(a), mode)?; let mut a_gadget = AF::new_variable(ark_relations::ns!(cs, "a"), || Ok(a), mode)?;
a_gadget.frobenius_map_in_place(i)?; a_gadget.frobenius_map_in_place(i)?;
a.frobenius_map(i);
a.frobenius_map_in_place(i);
assert_eq!(a_gadget.value()?, a); assert_eq!(a_gadget.value()?, a);
} }

Loading…
Cancel
Save