Scalar multiplication
The following functions perform operations over the embedded curve whose coordinates are defined by the configured noir field. For the BN254 scalar field, this is BabyJubJub or Grumpkin.
Suffixes _low and _high denote low and high limbs of a scalar.
embedded_curve_ops::multi_scalar_mul
Performs multi scalar multiplication over the embedded curve. The function accepts arbitrary amount of point-scalar pairs on the input, it multiplies the individual pairs over the curve and returns a sum of the resulting points.
Points are represented as EmbeddedCurvePoint structs with x and y coordinates and an is_infinite flag, scalars as EmbeddedCurveScalar structs with lo and hi limbs.
pub fn multi_scalar_mul<let N: u32>(
points: [EmbeddedCurvePoint; N],
scalars: [EmbeddedCurveScalar; N],
) -> EmbeddedCurvePoint
Source code: noir_stdlib/src/embedded_curve_ops.nr#L142-L147
example
use std::embedded_curve_ops::{EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul};
fn main(point_x: Field, point_y: Field, scalar_low: Field, scalar_high: Field) {
let point = EmbeddedCurvePoint { x: point_x, y: point_y, is_infinite: false };
let scalar = EmbeddedCurveScalar { lo: scalar_low, hi: scalar_high };
let result = multi_scalar_mul([point], [scalar]);
println(result);
}
embedded_curve_ops::fixed_base_scalar_mul
Performs fixed base scalar multiplication over the embedded curve (multiplies input scalar with a generator point). The function accepts a single scalar on the input represented as 2 fields.
pub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint
Source code: noir_stdlib/src/embedded_curve_ops.nr#L159-L161
example
use std::embedded_curve_ops::{EmbeddedCurveScalar, fixed_base_scalar_mul};
fn main(scalar_low: Field, scalar_high: Field) {
let scalar = EmbeddedCurveScalar { lo: scalar_low, hi: scalar_high };
let point = fixed_base_scalar_mul(scalar);
println(point);
}
embedded_curve_ops::embedded_curve_add
Adds two points on the embedded curve.
This function takes two EmbeddedCurvePoint structures as parameters, representing points on the curve, and returns a new EmbeddedCurvePoint structure that represents their sum.
Parameters:
point1(EmbeddedCurvePoint): The first point to add.point2(EmbeddedCurvePoint): The second point to add.
Returns:
EmbeddedCurvePoint: The resulting point after the addition ofpoint1andpoint2.
pub fn embedded_curve_add(
point1: EmbeddedCurvePoint,
point2: EmbeddedCurvePoint,
) -> EmbeddedCurvePoint {
Source code: noir_stdlib/src/embedded_curve_ops.nr#L172-L177
example
use std::embedded_curve_ops::{EmbeddedCurvePoint, embedded_curve_add};
fn main() {
let point1 = EmbeddedCurvePoint { x: 1, y: 2, is_infinite: false };
let point2 = EmbeddedCurvePoint { x: 3, y: 4, is_infinite: false };
let result = embedded_curve_add(point1, point2);
println(f"Resulting Point: ({result.x}, {result.y})");
}
This is a black box function. Read this section to learn more about black box functions in Noir.