Skip to content

Commit

Permalink
fix: correct invalid brillig codegen for EmbeddedCurvePoint.add
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Feb 15, 2024
1 parent aeb3241 commit e70ba52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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);
}

0 comments on commit e70ba52

Please sign in to comment.