Skip to content

Commit

Permalink
msm: fix border case
Browse files Browse the repository at this point in the history
  • Loading branch information
jsign committed Sep 26, 2023
1 parent 790ba73 commit df7309e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/msm/msm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ pub fn PrecompMSM(
for (0..scalars.len) |s_i| {
var k: u16 = 0;
while (k < Fr.BitSize) : (k += t) {
const bit = scalars[s_i] >> (@as(u8, @intCast(k + t - t_i - 1))) & 1;
curr_window_scalar |= @as(usize, @intCast(bit << (b - curr_window_b_idx - 1)));
if (k + t - t_i - 1 < Fr.BitSize) {
const bit = scalars[s_i] >> (@as(u8, @intCast(k + t - t_i - 1))) & 1;
curr_window_scalar |= @as(usize, @intCast(bit << (b - curr_window_b_idx - 1)));
}
curr_window_b_idx += 1;

if (curr_window_b_idx == b) {
Expand All @@ -107,6 +109,9 @@ pub fn PrecompMSM(
}
}
}
if (curr_window_scalar > 0) {
accum = bandersnatch.ExtendedPoint.mixedAdd(accum, self.table[curr_window_idx * window_size .. (curr_window_idx + 1) * window_size][curr_window_scalar]);
}
}

return Element{ .point = accum };
Expand Down

0 comments on commit df7309e

Please sign in to comment.