Browse Source

alloc zero points consistently (#126)

Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
avoid_assigned_value
Chris Sosnin 1 year ago
committed by GitHub
parent
commit
f58b7b797b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions
  1. +1
    -0
      Cargo.toml
  2. +7
    -4
      src/groups/curves/short_weierstrass/mod.rs

+ 1
- 0
Cargo.toml

@ -78,6 +78,7 @@ ark-ec = { git = "https://github.com/arkworks-rs/algebra/" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/" }
ark-test-curves = { git = "https://github.com/arkworks-rs/algebra/" }
ark-bn254 = { git = "https://github.com/arkworks-rs/curves/" }
ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves/" }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves/" }
ark-mnt4-298 = { git = "https://github.com/arkworks-rs/curves/" }

+ 7
- 4
src/groups/curves/short_weierstrass/mod.rs

@ -170,8 +170,9 @@ where
} else {
let cs = self.cs();
let infinity = self.is_zero()?;
let zero_x = F::zero();
let zero_y = F::one();
let zero_affine = SWAffine::<P>::zero();
let zero_x = F::new_constant(cs.clone(), &zero_affine.x)?;
let zero_y = F::new_constant(cs.clone(), &zero_affine.y)?;
// Allocate a variable whose value is either `self.z.inverse()` if the inverse
// exists, and is zero otherwise.
let z_inv = F::new_witness(ark_relations::ns!(cs, "z_inverse"), || {
@ -210,6 +211,8 @@ where
Ok(ge) => {
let ge = ge.into_affine();
if ge.is_zero() {
// These values are convenient since the point satisfies
// curve equation.
(
Ok(P::BaseField::zero()),
Ok(P::BaseField::one()),
@ -334,10 +337,10 @@ where
for bit in affine_bits.iter().skip(1) {
if bit.is_constant() {
if *bit == &Boolean::TRUE {
accumulator = accumulator.add_unchecked(&multiple_of_power_of_two)?;
accumulator = accumulator.add_unchecked(multiple_of_power_of_two)?;
}
} else {
let temp = accumulator.add_unchecked(&multiple_of_power_of_two)?;
let temp = accumulator.add_unchecked(multiple_of_power_of_two)?;
accumulator = bit.select(&temp, &accumulator)?;
}
multiple_of_power_of_two.double_in_place()?;

Loading…
Cancel
Save