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 represented as x and y coordinates [x1, y1, x2, y2, ...], scalars as low and high limbs [low1, high1, low2, high2, ...].
pub fn multi_scalar_mul<N>(
points: [Field; N], // points represented as x and y coordinates [x1, y1, x2, y2, ...]
scalars: [Field; N] // scalars represented as low and high limbs [low1, high1, low2, high2, ...]
) -> [Field; 2]
Source code: noir_stdlib/src/embedded_curve_ops.nr#L43-L48
example
fn main(point_x: Field, point_y: Field, scalar_low: Field, scalar_high: Field) {
let point = std::embedded_curve_ops::multi_scalar_mul([point_x, point_y], [scalar_low, scalar_high]);
println(point);
}
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_low: Field,
scalar_high: Field
) -> [Field; 2]
Source code: noir_stdlib/src/embedded_curve_ops.nr#L51-L56
example
fn main(scalar_low: Field, scalar_high: Field) {
let point = std::embedded_curve_ops::fixed_base_scalar_mul(scalar_low, scalar_high);
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 ofpoint1
andpoint2
.
fn embedded_curve_add(
point1: EmbeddedCurvePoint,
point2: EmbeddedCurvePoint
) -> EmbeddedCurvePoint
Source code: noir_stdlib/src/embedded_curve_ops.nr#L65-L70
example
fn main() {
let point1 = EmbeddedCurvePoint { x: 1, y: 2 };
let point2 = EmbeddedCurvePoint { x: 3, y: 4 };
let result = std::embedded_curve_ops::embedded_curve_add(point1, point2);
println!("Resulting Point: ({}, {})", result.x, result.y);
}
This is a black box function. Read this section to learn more about black box functions in Noir.