Skip to content

Commit

Permalink
fix: correct invalid brillig codegen for EmbeddedCurvePoint.add (#4382
Browse files Browse the repository at this point in the history
)

# Description

## Problem\*

Resolves  #4260

## Summary\*

The error is explained in the comment I've added to the stdlib. This is
a quick fix and we can clean it up once we're making serialisation
changes in `aztec-packages` again.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Feb 17, 2024
1 parent 46f2204 commit 5051ec4
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 5051ec4

Please sign in to comment.