Browse Source

Fix BLS12 G2PreparedGadget's AllocVar with a divisive twist (#77)

* fix

* tidy up Cargo; add changelog

* fix nostd

* removal of the test

* fmt
master
Weikeng Chen 3 years ago
committed by GitHub
parent
commit
a2a5ac491a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 11 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +26
    -11
      src/groups/curves/short_weierstrass/bls12/mod.rs

+ 2
- 0
CHANGELOG.md

@ -12,6 +12,8 @@
### Bug Fixes
- [\#77](https://github.com/arkworks-rs/r1cs-std/pull/77) Fix BLS12 `G2PreparedGadget`'s `AllocVar` when G2 uses a divisive twist.
## v0.3.1
### Features

+ 26
- 11
src/groups/curves/short_weierstrass/bls12/mod.rs

@ -10,7 +10,6 @@ use crate::{
groups::curves::short_weierstrass::*,
Vec,
};
use core::fmt::Debug;
/// Represents a projective point in G1.
@ -124,16 +123,32 @@ impl AllocVar, P::Fp> for G2PreparedVar

{

let cs = ns.cs();
let g2_prep = f().map(|b| {
let projective_coeffs = &b.borrow().ell_coeffs;
let mut z_s = projective_coeffs
.iter()
.map(|(_, _, z)| *z)
.collect::<Vec<_>>();
ark_ff::fields::batch_inversion(&mut z_s);
projective_coeffs
.iter()
.zip(z_s)
.map(|((x, y, _), z_inv)| (*x * &z_inv, *y * &z_inv))
.collect::<Vec<_>>()
match P::TWIST_TYPE {
TwistType::M => {
let mut z_s = projective_coeffs
.iter()
.map(|(_, _, z)| *z)
.collect::<Vec<_>>();
ark_ff::fields::batch_inversion(&mut z_s);
projective_coeffs
.iter()
.zip(z_s)
.map(|((x, y, _), z_inv)| (*x * &z_inv, *y * &z_inv))
.collect::<Vec<_>>()
}
TwistType::D => {
let mut z_s = projective_coeffs
.iter()
.map(|(z, _, _)| *z)
.collect::<Vec<_>>();
ark_ff::fields::batch_inversion(&mut z_s);
projective_coeffs
.iter()
.zip(z_s)
.map(|((_, x, y), z_inv)| (*x * &z_inv, *y * &z_inv))
.collect::<Vec<_>>()
}
}
});
let l = Vec::new_variable(

Loading…
Cancel
Save