Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion test_programs/execution_success/multi_scalar_mul/Prover.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
scalars = ["0", "0", "0", "0", "0"]
scalars = [
"0x20644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001",
"0x27241797651f4adc1f04da8e1aeb",
"0x00",
"0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000",
"0x1b",
]

[[points]]
is_infinite = "0"
Expand Down
30 changes: 19 additions & 11 deletions test_programs/execution_success/multi_scalar_mul/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@ unconstrained fn main(
points: [EmbeddedCurvePoint; 5],
scalars: [Field; 5],
) -> pub EmbeddedCurvePoint {
double_then_add_msm(points, scalars)
}

unconstrained fn double_then_add_msm<let N: u32>(
points: [EmbeddedCurvePoint; N],
scalars: [Field; N],
) -> EmbeddedCurvePoint {
// EmbeddedCurveScalar are two 128-bit numbers
let mut acc = EmbeddedCurvePoint::point_at_infinity();
for i in 0..1 {
for i in 0..N {
// These should probably be EmbeddedCurveScalars
// let full_scalar: Field = scalars[i].hi * 2.pow_32(128) + scalars[i].lo;
let full_scalar = scalars[i];
// If the scalar is zero we won't add anything to acc
if full_scalar == 0 {
continue;
}
let full_scalar_bits: [u1; 254] = full_scalar.to_be_bits();
let mut index_of_msb = 0;
// Iterates in BE
Expand All @@ -24,22 +35,19 @@ unconstrained fn main(
}
}

let mut temp = points[i];
let mut res = EmbeddedCurvePoint::point_at_infinity();
// When iterative backwards we want to go to bits.len() - 2
for j in 0..(254 - index_of_msb) {
let k = 253 - j;

let temp = points[i];
let mut res = points[i];
// traversing from second MSB to LSB
for j in (index_of_msb + 1)..(254) {
// Double
res = embedded_curve_add_unsafe(res, res);
// Add
if full_scalar_bits[k] == 1 {
if full_scalar_bits[j] == 1 {
res = embedded_curve_add_unsafe(res, temp);
}
// Double
temp = embedded_curve_add_unsafe(temp, temp);
}

acc = embedded_curve_add_unsafe(acc, res);
}
acc
}