diff --git a/plonky2/src/gadgets/curve.rs b/plonky2/src/gadgets/curve.rs index 0a0650e9..66d2d1b1 100644 --- a/plonky2/src/gadgets/curve.rs +++ b/plonky2/src/gadgets/curve.rs @@ -95,6 +95,16 @@ impl, const D: usize> CircuitBuilder { AffinePointTarget { x: x3, y: y3 } } + pub fn curve_repeated_double(&mut self, p: &AffinePointTarget, n: usize) -> AffinePointTarget { + let mut result = p.clone(); + + for _ in 0..n { + result = self.curve_double(&result); + } + + result + } + // Add two points, which are assumed to be non-equal. pub fn curve_add( &mut self, diff --git a/plonky2/src/gadgets/curve_windowed_mul.rs b/plonky2/src/gadgets/curve_windowed_mul.rs index 57d8c558..002b6ec4 100644 --- a/plonky2/src/gadgets/curve_windowed_mul.rs +++ b/plonky2/src/gadgets/curve_windowed_mul.rs @@ -82,7 +82,7 @@ impl, const D: usize> CircuitBuilder { let windows = self.split_nonnative_to_4_bit_limbs(n); let m = C::ScalarField::BITS / WINDOW_SIZE; for i in (0..m).rev() { - result = self.curve_double(&result); + result = self.curve_repeated_double(&result, WINDOW_SIZE); let window = windows[i]; let to_add = self.random_access_curve_points(window, precomputation.clone()); @@ -147,7 +147,7 @@ mod tests { } #[test] - fn test_curve_mul_windowed() -> Result<()> { + fn test_curve_windowed_mul() -> Result<()> { const D: usize = 2; type C = PoseidonGoldilocksConfig; type F = >::F;