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

fix: correct invalid brillig codegen for EmbeddedCurvePoint.add #4382

Merged
merged 1 commit into from
Feb 17, 2024
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
11 changes: 10 additions & 1 deletion noir_stdlib/src/scalar_mul.nr
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,14 @@ pub fn fixed_base_embedded_curve(
// docs:end:fixed_base_embedded_curve
{}

// This is a hack as returning an `EmbeddedCurvePoint` from a foreign function in brillig returns a [BrilligVariable::SingleAddr; 2] rather than BrilligVariable::BrilligArray
// as is defined in the brillig bytecode format. This is a workaround which allows us to fix this without modifying the serialization format.
fn embedded_curve_add(point1: EmbeddedCurvePoint, point2: EmbeddedCurvePoint) -> EmbeddedCurvePoint {
let point_array = embedded_curve_add_array_return(point1, point2);
let x = point_array[0];
let y = point_array[1];
EmbeddedCurvePoint { x, y }
}

#[foreign(embedded_curve_add)]
fn embedded_curve_add(_point1: EmbeddedCurvePoint, _point2: EmbeddedCurvePoint) -> EmbeddedCurvePoint {}
fn embedded_curve_add_array_return(_point1: EmbeddedCurvePoint, _point2: EmbeddedCurvePoint) -> [Field; 2] {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ unconstrained fn main(
let res = std::scalar_mul::fixed_base_embedded_curve(priv_key, 0);
assert(res[0] == pub_x);
assert(res[1] == pub_y);

let pub_point= std::scalar_mul::EmbeddedCurvePoint { x: pub_x, y: pub_y };
let g1_y = 17631683881184975370165255887551781615748388533673675138860;
let g1= std::scalar_mul::EmbeddedCurvePoint { x: 1, y: g1_y };

let res = pub_point.double();
let double = g1.add(g1);

assert(double.x == res.x);
}
Loading