PageSourceSearch

https://noir-lang.org/docs/assets/js/61397e6b.b43871f6.js

js noir-lang.org collected 2026-10-03 22:50:56 UTC 9,054 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkdocs=globalThis.webpackChunkdocs||[]).push([[1144],{25471(e,r,d){d.r(r),d.d(r,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>a,metadata:()=>i,toc:()=>o});const i=JSON.parse('{"id":"libraries/standard_library/cryptographic_primitives/embedded_curve_ops","title":"Scalar multiplication","description":"See how you can perform scalar multiplication in Noir","source":"@site/versioned_docs/version-v1.0.0-rc.0/libraries/standard_library/cryptographic_primitives/embedded_curve_ops.mdx","sourceDirName":"libraries/standard_library/cryptographic_primitives","slug":"/libraries/standard_library/cryptographic_primitives/embedded_curve_ops","permalink":"/docs/v1.0.0-rc.0/libraries/standard_library/cryptographic_primitives/embedded_curve_ops","draft":false,"unlisted":false,"editUrl":"https://github.com/noir-lang/noir/edit/master/docs/versioned_docs/version-v1.0.0-rc.0/libraries/standard_library/cryptographic_primitives/embedded_curve_ops.mdx","tags":[],"version":"v1.0.0-rc.0","frontMatter":{"title":"Scalar multiplication","description":"See how you can perform scalar multiplication in Noir","keywords":["cryptographic primitives","Noir project","scalar multiplication"]},"sidebar":"sidebar","previous":{"title":"Ciphers","permalink":"/docs/v1.0.0-rc.0/libraries/standard_library/cryptographic_primitives/ciphers"},"next":{"title":"Hash methods","permalink":"/docs/v1.0.0-rc.0/libraries/standard_library/cryptographic_primitives/hashes"}}');var n=d(74848),s=d(28453),t=d(8037);const a={title:"Scalar multiplication",description:"See how you can perform scalar multiplication in Noir",keywords:["cryptographic primitives","Noir project","scalar multiplication"]},l=void 0,c={},o=[{value:"embedded_curve_ops::multi_scalar_mul",id:"embedded_curve_opsmulti_scalar_mul",level:2},{value:"embedded_curve_ops::fixed_base_scalar_mul",id:"embedded_curve_opsfixed_base_scalar_mul",level:2},{value:"embedded_curve_ops::embedded_curve_add",id:"embedded_curve_opsembedded_curve_add",level:2},{value:"Parameters:",id:"parameters",level:3},{value:"Returns:",id:"returns",level:3}];function u(e){const r={admonition:"admonition",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.p,{children:"The following functions perform operations over the embedded curve whose coordinates are defined by the configured noir field.\nFor the BN254 scalar field, this is BabyJubJub or Grumpkin."}),"\n",(0,n.jsx)(r.admonition,{type:"note",children:(0,n.jsxs)(r.p,{children:["Suffixes ",(0,n.jsx)(r.code,{children:"_low"})," and ",(0,n.jsx)(r.code,{children:"_high"})," denote low and high limbs of a scalar."]})}),"\n",(0,n.jsx)(r.h2,{id:"embedded_curve_opsmulti_scalar_mul",children:"embedded_curve_ops::multi_scalar_mul"}),"\n",(0,n.jsx)(r.p,{children:"Performs multi scalar multiplication over the embedded curve.\nThe function accepts arbitrary amount of point-scalar pairs on the input, it multiplies the individual pairs over\nthe curve and returns a sum of the resulting points."}),"\n",(0,n.jsxs)(r.p,{children:["Points are represented as ",(0,n.jsx)(r.code,{children:"EmbeddedCurvePoint"})," structs with ",(0,n.jsx)(r.code,{children:"x"})," and ",(0,n.jsx)(r.code,{children:"y"})," coordinates, scalars as ",(0,n.jsx)(r.code,{children:"EmbeddedCurveScalar"})," structs with ",(0,n.jsx)(r.code,{children:"lo"})," and ",(0,n.jsx)(r.code,{children:"hi"})," limbs."]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-rust",metastring:'title="multi_scalar_mul" showLineNumbers ',children:"pub fn multi_scalar_mul<let N: u32>(\n    points: [EmbeddedCurvePoint; N],\n    scalars: [EmbeddedCurveScalar; N],\n) -> EmbeddedCurvePoint\n"})}),"\n",(0,n.jsxs)(r.blockquote,{children:["\n",(0,n.jsx)("sup",{children:(0,n.jsx)("sub",{children:(0,n.jsx)("a",{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/embedded_curve_ops.nr#L131-L136",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/embedded_curve_ops.nr#L131-L136"})})}),"\n"]}),"\n",(0,n.jsx)(r.p,{children:"example"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-rust",children:"use std::embedded_curve_ops::{EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul};\n\nfn main(point_x: Field, point_y: Field, scalar_low: Field, scalar_high: Field) {\
1n    let point = EmbeddedCurvePoint { x: point_x, y: point_y };\n    let scalar = EmbeddedCurveScalar { lo: scalar_low, hi: scalar_high };\n    let result = multi_scalar_mul([point], [scalar]);\n    println(result);\n}\n"})}),"\n",(0,n.jsx)(r.h2,{id:"embedded_curve_opsfixed_base_scalar_mul",children:"embedded_curve_ops::fixed_base_scalar_mul"}),"\n",(0,n.jsx)(r.p,{children:"Performs fixed base scalar multiplication over the embedded curve (multiplies input scalar with a generator point).\nThe function accepts a single scalar on the input represented as 2 fields."}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-rust",metastring:'title="fixed_base_scalar_mul" showLineNumbers ',children:"pub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint\n"})}),"\n",(0,n.jsxs)(r.blockquote,{children:["\n",(0,n.jsx)("sup",{children:(0,n.jsx)("sub",{children:(0,n.jsx)("a",{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/embedded_curve_ops.nr#L141-L143",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/embedded_curve_ops.nr#L141-L143"})})}),"\n"]}),"\n",(0,n.jsx)(r.p,{children:"example"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-rust",children:"use std::embedded_curve_ops::{EmbeddedCurveScalar, fixed_base_scalar_mul};\n\nfn main(scalar_low: Field, scalar_high: Field) {\n    let scalar = EmbeddedCurveScalar { lo: scalar_low, hi: scalar_high };\n    let point = fixed_base_scalar_mul(scalar);\n    println(point);\n}\n"})}),"\n",(0,n.jsx)(r.h2,{id:"embedded_curve_opsembedded_curve_add",children:"embedded_curve_ops::embedded_curve_add"}),"\n",(0,n.jsxs)(r.p,{children:["Adds two points on the embedded curve.\nThis function takes two ",(0,n.jsx)(r.code,{children:"EmbeddedCurvePoint"})," structures as parameters, representing points on the curve, and returns a new ",(0,n.jsx)(r.code,{children:"EmbeddedCurvePoint"})," structure that represents their sum."]}),"\n",(0,n.jsx)(r.h3,{id:"parameters",children:"Parameters:"}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsxs)(r.li,{children:[(0,n.jsx)(r.code,{children:"point1"})," (",(0,n.jsx)(r.code,{children:"EmbeddedCurvePoint"}),"): The first point to add."]}),"\n",(0,n.jsxs)(r.li,{children:[(0,n.jsx)(r.code,{children:"point2"})," (",(0,n.jsx)(r.code,{children:"EmbeddedCurvePoint"}),"): The second point to add."]}),"\n"]}),"\n",(0,n.jsx)(r.h3,{id:"returns",children:"Returns:"}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsxs)(r.li,{children:[(0,n.jsx)(r.code,{children:"EmbeddedCurvePoint"}),": The resulting point after the addition of ",(0,n.jsx)(r.code,{children:"point1"})," and ",(0,n.jsx)(r.code,{children:"point2"}),"."]}),"\n"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-rust",metastring:'title="embedded_curve_add" showLineNumbers ',children:"pub fn embedded_curve_add(\n    point1: EmbeddedCurvePoint,\n    point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n"})}),"\n",(0,n.jsxs)(r.blockquote,{children:["\n",(0,n.jsx)("sup",{children:(0,n.jsx)("sub",{children:(0,n.jsx)("a",{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/embedded_curve_ops.nr#L161-L166",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/embedded_curve_ops.nr#L161-L166"})})}),"\n"]}),"\n",(0,n.jsx)(r.p,{children:"example"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-rust",children:'use std::embedded_curve_ops::{EmbeddedCurvePoint, embedded_curve_add};\n\nfn main() {\n    let point1 = EmbeddedCurvePoint { x: 1, y: 2 };\n    let point2 = EmbeddedCurvePoint { x: 3, y: 4 };\n    let result = embedded_curve_add(point1, point2);\n    println(f"Resulting Point: ({result.x}, {result.y})");\n}\n'})}),"\n",(0,n.jsx)(t.A,{to:"../black_box_fns"})]})}function p(e={}){const{wrapper:r}={...(0,s.R)(),...e.components};return r?(0,n.jsx)(r,{...e,children:(0,n.jsx)(u,{...e})}):u(e)}},8037(e,r,d){d.d(r,{A:()=>s});var i=d(28774),n=d(74848);function s({to:e}){return(0,n.jsx)("div",{children:(0,n.jsxs)("p",{children:["This is a black box function. Read ",(0,n.jsx)(i.A,{to:e,children:"this section"})," to learn more about black box functions in Noir."]})})}},28453(e,r,d){d.d(r,{R:()=>t,x:()=>a});var i=d(96540);const n={},s=i.createContext(n);function t(e){const r=i.useContext(s);return i.useMemo(function(){return"function"==typeof e?e(r):{...r,...e}},[r,e])}function a(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:t(e.components),i.createElement(s.Provider,{value:r},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.