Skip to content

Commit

Permalink
feat(stdlib): grumpkin scalar multiplication API (#2586)
Browse files Browse the repository at this point in the history
Co-authored-by: kevaundray <[email protected]>
  • Loading branch information
benesjan and kevaundray authored Sep 7, 2023
1 parent 2d0a5e4 commit dc34bc4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions noir_stdlib/src/grumpkin_scalar.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
struct GrumpkinScalar {
low: Field,
high: Field,
}

impl GrumpkinScalar {
fn new(low: Field, high: Field) -> Self {
// TODO: check that the low and high value fit within the grumpkin modulus
GrumpkinScalar { low, high }
}
}

global GRUMPKIN_SCALAR_SERIALISED_LEN: Field = 2;

fn deserialise_grumpkin_scalar(fields: [Field; GRUMPKIN_SCALAR_SERIALISED_LEN]) -> GrumpkinScalar {
GrumpkinScalar { low: fields[0], high: fields[1] }
}

fn serialise_grumpkin_scalar(scalar: GrumpkinScalar) -> [Field; GRUMPKIN_SCALAR_SERIALISED_LEN] {
[scalar.low, scalar.high]
}
7 changes: 7 additions & 0 deletions noir_stdlib/src/grumpkin_scalar_mul.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::grumpkin_scalar::GrumpkinScalar;
use crate::scalar_mul::fixed_base_embedded_curve;

fn grumpkin_fixed_base(scalar: GrumpkinScalar) -> [Field; 2] {
// TODO: this should use both the low and high limbs to do the scalar multiplication
fixed_base_embedded_curve(scalar.low)
}
2 changes: 2 additions & 0 deletions noir_stdlib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod schnorr;
mod ecdsa_secp256k1;
mod ecdsa_secp256r1;
mod eddsa;
mod grumpkin_scalar;
mod grumpkin_scalar_mul;
mod scalar_mul;
mod sha256;
mod sha512;
Expand Down

0 comments on commit dc34bc4

Please sign in to comment.