Skip to main content
Version: dev

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.

note

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, ...].

multi_scalar_mul
pub fn multi_scalar_mul<let N: u32>(
points: [EmbeddedCurvePoint; N],
scalars: [EmbeddedCurveScalar; N]
) -> EmbeddedCurvePoint
Source code: noir_stdlib/src/embedded_curve_ops.nr#L91-L96

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.

fixed_base_scalar_mul
pub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint
Source code: noir_stdlib/src/embedded_curve_ops.nr#L108-L110

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 of point1 and point2.
embedded_curve_add
fn embedded_curve_add(
point1: EmbeddedCurvePoint,
point2: EmbeddedCurvePoint
) -> EmbeddedCurvePoint
Source code: noir_stdlib/src/embedded_curve_ops.nr#L118-L123

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);
}
info

This is a black box function. Read this section to learn more about black box functions in Noir.