Skip to content

Commit

Permalink
fix bit_mul for tecurve as well
Browse files Browse the repository at this point in the history
  • Loading branch information
guipublic committed Jun 19, 2024
1 parent 4ddba7f commit dafc5fd
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions noir_stdlib/src/ec/tecurve.nr
Original file line number Diff line number Diff line change
Expand Up @@ -342,28 +342,24 @@ mod curvegroup {
// If k is the natural number represented by `bits`, then this computes p + ... + p k times.
fn bit_mul<N>(self, bits: [u1; N], p: Point) -> Point {
let mut out = Point::zero();

let mut base = p;
for i in 0..N {
out = self.add(
self.add(out, out),
if(bits[N - i - 1] == 0) {Point::zero()} else {p});
if bits[i] == 1 {
out = self.add(out, base);
}
base = self.add(base, base);
}

out
}

// Scalar multiplication (p + ... + p n times)
pub fn mul(self, n: Field, p: Point) -> Point {
let N_BITS = crate::field::modulus_num_bits();
assert(N_BITS <= 254);
let bits = n.to_le_bits(N_BITS as u32);
let bits_array :[u1; 254] = bits.as_array();

// TODO: temporary workaround until issue 1354 is solved
let mut n_as_bits: [u1; 254] = [0; 254];
let tmp = n.to_le_bits(N_BITS as u32);
for i in 0..254 {
n_as_bits[i] = tmp[i];
}

self.bit_mul(n_as_bits, p)
self.bit_mul(bits_array, p)
}

// Multi-scalar multiplication (n[0]*p[0] + ... + n[N]*p[N], where * denotes scalar multiplication)
Expand Down

0 comments on commit dafc5fd

Please sign in to comment.