diff --git a/noir_stdlib/src/grumpkin_scalar.nr b/noir_stdlib/src/grumpkin_scalar.nr new file mode 100644 index 00000000000..3a74e974322 --- /dev/null +++ b/noir_stdlib/src/grumpkin_scalar.nr @@ -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] +} diff --git a/noir_stdlib/src/grumpkin_scalar_mul.nr b/noir_stdlib/src/grumpkin_scalar_mul.nr new file mode 100644 index 00000000000..b7774f0086d --- /dev/null +++ b/noir_stdlib/src/grumpkin_scalar_mul.nr @@ -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) +} diff --git a/noir_stdlib/src/lib.nr b/noir_stdlib/src/lib.nr index f033334c140..224c3a03f21 100644 --- a/noir_stdlib/src/lib.nr +++ b/noir_stdlib/src/lib.nr @@ -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;