diff --git a/src/msm.rs b/src/msm.rs index 340a8d2a..ef6f1b16 100644 --- a/src/msm.rs +++ b/src/msm.rs @@ -53,70 +53,8 @@ fn get_booth_index(window_index: usize, window_size: usize, el: &[u8]) -> i32 { } } -// Batch addition without edge case handling: -// Will panic if a point is the identity or if two points share the x coordinate. -fn batch_add_nonexceptional( - size: usize, - buckets: &mut [BucketAffine], - points: &[SchedulePoint], - bases: &[Affine], -) { - let mut t = vec![C::Base::ZERO; size]; - let mut z = vec![C::Base::ZERO; size]; - let mut acc = C::Base::ONE; - - for ( - ( - SchedulePoint { - base_idx, - buck_idx, - sign, - }, - t, - ), - z, - ) in points.iter().zip(t.iter_mut()).zip(z.iter_mut()) - { - *z = buckets[*buck_idx].x() - bases[*base_idx].x; - if *sign { - *t = acc * (buckets[*buck_idx].y() - bases[*base_idx].y); - } else { - *t = acc * (buckets[*buck_idx].y() + bases[*base_idx].y); - } - acc *= *z; - } - - acc = acc - .invert() - .expect("Attempted to invert 0 at batch_add_nmonexceptional"); - - for ( - ( - SchedulePoint { - base_idx, - buck_idx, - sign, - }, - t, - ), - z, - ) in points.iter().zip(t.iter()).zip(z.iter()).rev() - { - let lambda = acc * t; - acc *= z; - - let x = lambda.square() - (buckets[*buck_idx].x() + bases[*base_idx].x); - if *sign { - buckets[*buck_idx].set_y(&((lambda * (bases[*base_idx].x - x)) - bases[*base_idx].y)); - } else { - buckets[*buck_idx].set_y(&((lambda * (bases[*base_idx].x - x)) + bases[*base_idx].y)); - } - buckets[*buck_idx].set_x(&x); - } -} - -/// Batch addition with edge case handling. -fn batch_add_exceptional( +/// Batch addition. +fn batch_add( size: usize, buckets: &mut [BucketAffine], points: &[SchedulePoint], @@ -371,7 +309,7 @@ impl Schedule { fn execute(&mut self, bases: &[Affine]) { if self.ptr != 0 { - batch_add_exceptional(self.ptr, &mut self.buckets, &self.set, bases); + batch_add(self.ptr, &mut self.buckets, &self.set, bases); self.ptr = 0; self.set .iter_mut()