Skip to content

Commit eca8377

Browse files
committed
perf: update CachedMulTable MSM to use projective add/double (INT-6096)
1 parent b8e5c3a commit eca8377

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

extensions/ecc/guest/src/weierstrass.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,15 @@ where
149149
let table = bases
150150
.iter()
151151
.map(|base| {
152-
if base.is_identity() {
152+
if Group::is_identity(base) {
153153
vec![<C::Point as Group>::IDENTITY; window_size - 2]
154154
} else {
155155
let mut multiples = Vec::with_capacity(window_size - 2);
156156
for _ in 0..window_size - 2 {
157-
// Because the order of `base` is prime, we are guaranteed that
158-
// j * base != identity,
159-
// j * base != +- base for j > 1,
160-
// j * base + base != identity
161157
let multiple = multiples
162158
.last()
163-
.map(|last| unsafe {
164-
WeierstrassPoint::add_ne_nonidentity::<false>(last, base)
165-
})
166-
.unwrap_or_else(|| unsafe { base.double_nonidentity::<false>() });
159+
.map(|last: &C::Point| last.add_impl::<false>(base))
160+
.unwrap_or_else(|| base.double_impl::<false>());
167161
multiples.push(multiple);
168162
}
169163
multiples
@@ -223,17 +217,15 @@ where
223217

224218
if outer != 0 {
225219
for _ in 0..self.window_bits {
226-
// Note: this handles identity
227220
// setup has been called above
228-
res.double_assign_impl::<false>();
221+
res = res.double_impl::<false>();
229222
}
230223
}
231224
for (base_idx, scalar) in scalars.iter().enumerate() {
232225
let scalar = (scalar.as_le_bytes()[limb_idx] >> bit_idx) & mask;
233226
let summand = self.get_multiple(base_idx, scalar as usize);
234-
// handles identity
235227
// setup has been called above
236-
res.add_assign_impl::<false>(summand);
228+
res = res.add_impl::<false>(summand);
237229
}
238230
}
239231
res

0 commit comments

Comments
 (0)