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
17 changes: 11 additions & 6 deletions noir_stdlib/src/embedded_curve_ops.nr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ impl EmbeddedCurvePoint {
pub fn point_at_infinity() -> EmbeddedCurvePoint {
EmbeddedCurvePoint { x: 0, y: 0, is_infinite: true }
}

/// Returns the curve's generator point.
pub fn generator() -> EmbeddedCurvePoint {
// Generator point for the grumpkin curve (y^2 = x^3 - 17)
EmbeddedCurvePoint {
x: 1,
y: 17631683881184975370165255887551781615748388533673675138860, // sqrt(-16)
is_infinite: false,
}
}
}

impl Add for EmbeddedCurvePoint {
Expand Down Expand Up @@ -121,12 +131,7 @@ pub(crate) fn multi_scalar_mul_array_return<let N: u32>(
pub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint
// docs:end:fixed_base_scalar_mul
{
let g1 = EmbeddedCurvePoint {
x: 1,
y: 17631683881184975370165255887551781615748388533673675138860,
is_infinite: false,
};
multi_scalar_mul([g1], [scalar])
multi_scalar_mul([EmbeddedCurvePoint::generator()], [scalar])
}

/// This function only assumes that the points are on the curve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use std::embedded_curve_ops::EmbeddedCurvePoint;

fn main() {
let zero = EmbeddedCurvePoint::point_at_infinity();
let g1 = EmbeddedCurvePoint {
x: 1,
y: 17631683881184975370165255887551781615748388533673675138860,
is_infinite: false,
};
let g1 = EmbeddedCurvePoint::generator();

assert(g1 + zero == g1);
assert(g1 - g1 == zero);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ fn main() {
let pub_x = 0x0000000000000000000000000000000000000000000000000000000000000001;
let pub_y = 0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c;

let g1_y = 17631683881184975370165255887551781615748388533673675138860;
let g1 = std::embedded_curve_ops::EmbeddedCurvePoint { x: 1, y: g1_y, is_infinite: false };
let g1 = std::embedded_curve_ops::EmbeddedCurvePoint::generator();
let scalar = std::embedded_curve_ops::EmbeddedCurveScalar { lo: 1, hi: 0 };
// Test that multi_scalar_mul correctly derives the public key
let res = std::embedded_curve_ops::multi_scalar_mul([g1], [scalar]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::ops::Add;

fn main(priv_key: Field, pub_x: pub Field, pub_y: pub Field) {
let g1_y = 17631683881184975370165255887551781615748388533673675138860;
let g1 = std::embedded_curve_ops::EmbeddedCurvePoint { x: 1, y: g1_y, is_infinite: false };
let g1 = std::embedded_curve_ops::EmbeddedCurvePoint::generator();
let scalar = std::embedded_curve_ops::EmbeddedCurveScalar { lo: priv_key, hi: 0 };
// Test that multi_scalar_mul correctly derives the public key
let res = std::embedded_curve_ops::multi_scalar_mul([g1], [scalar]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ fn test_embedded_curve_ops() {
let (sum, mul) = comptime {
let s1 = EmbeddedCurveScalar { lo: 1, hi: 0 };
let s2 = EmbeddedCurveScalar { lo: 2, hi: 0 };
let g1 = EmbeddedCurvePoint {
x: 1,
y: 17631683881184975370165255887551781615748388533673675138860,
is_infinite: false,
};
let g1 = EmbeddedCurvePoint::generator();
let g2 = multi_scalar_mul([g1], [s2]);
let sum = g1 + g2;
let mul = multi_scalar_mul([g1, g2], [s1, s1]);
Expand Down
15 changes: 2 additions & 13 deletions test_programs/noir_test_success/embedded_curve_ops/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use std::embedded_curve_ops::{EmbeddedCurvePoint, EmbeddedCurveScalar, multi_sca

fn test_infinite_point() {
let zero = EmbeddedCurvePoint::point_at_infinity();
let g1 = EmbeddedCurvePoint {
x: 1,
y: 17631683881184975370165255887551781615748388533673675138860,
is_infinite: false,
};
let g1 = EmbeddedCurvePoint::generator();
let g2 = g1 + g1;

let s1 = EmbeddedCurveScalar { lo: 1, hi: 0 };
Expand All @@ -18,14 +14,7 @@ fn test_infinite_point() {
assert(g1 - g1 == zero);
assert(g1 - zero == g1);
assert(zero + zero == zero);
assert(
multi_scalar_mul([g1], [s1])
== EmbeddedCurvePoint {
x: 1,
y: 17631683881184975370165255887551781615748388533673675138860,
is_infinite: false,
},
);
assert(multi_scalar_mul([g1], [s1]) == g1);
assert(multi_scalar_mul([g1, g1], [s1, s1]) == g2);
assert(
multi_scalar_mul(
Expand Down
Loading