Skip to content

Commit f58b7b7

Browse files
slumberPratyush
andauthored
alloc zero points consistently (#126)
Co-authored-by: Pratyush Mishra <[email protected]>
1 parent 529c8dc commit f58b7b7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ark-ec = { git = "https://github.com/arkworks-rs/algebra/" }
7878
ark-poly = { git = "https://github.com/arkworks-rs/algebra/" }
7979
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/" }
8080
ark-test-curves = { git = "https://github.com/arkworks-rs/algebra/" }
81+
ark-bn254 = { git = "https://github.com/arkworks-rs/curves/" }
8182
ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves/" }
8283
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves/" }
8384
ark-mnt4-298 = { git = "https://github.com/arkworks-rs/curves/" }

src/groups/curves/short_weierstrass/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ where
170170
} else {
171171
let cs = self.cs();
172172
let infinity = self.is_zero()?;
173-
let zero_x = F::zero();
174-
let zero_y = F::one();
173+
let zero_affine = SWAffine::<P>::zero();
174+
let zero_x = F::new_constant(cs.clone(), &zero_affine.x)?;
175+
let zero_y = F::new_constant(cs.clone(), &zero_affine.y)?;
175176
// Allocate a variable whose value is either `self.z.inverse()` if the inverse
176177
// exists, and is zero otherwise.
177178
let z_inv = F::new_witness(ark_relations::ns!(cs, "z_inverse"), || {
@@ -210,6 +211,8 @@ where
210211
Ok(ge) => {
211212
let ge = ge.into_affine();
212213
if ge.is_zero() {
214+
// These values are convenient since the point satisfies
215+
// curve equation.
213216
(
214217
Ok(P::BaseField::zero()),
215218
Ok(P::BaseField::one()),
@@ -334,10 +337,10 @@ where
334337
for bit in affine_bits.iter().skip(1) {
335338
if bit.is_constant() {
336339
if *bit == &Boolean::TRUE {
337-
accumulator = accumulator.add_unchecked(&multiple_of_power_of_two)?;
340+
accumulator = accumulator.add_unchecked(multiple_of_power_of_two)?;
338341
}
339342
} else {
340-
let temp = accumulator.add_unchecked(&multiple_of_power_of_two)?;
343+
let temp = accumulator.add_unchecked(multiple_of_power_of_two)?;
341344
accumulator = bit.select(&temp, &accumulator)?;
342345
}
343346
multiple_of_power_of_two.double_in_place()?;

0 commit comments

Comments
 (0)