Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stdlib): grumpkin scalar multiplication API #2586

Merged
merged 4 commits into from
Sep 7, 2023
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
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)
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
}
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