Elliptic curves and pairings
Constantine provides the algebraic building blocks used by cryptographic protocols: elliptic-curve groups, scalar multiplication, multi-scalar multiplication, and pairings. These building blocks share field and subgroup rules across several curve families, while named curves supply the parameters that give each group its meaning. Read Named curves and groups for the curve catalog and Pairing engine for the execution path of a pairing.
Algebraic foundations
Finite-field domains
An elliptic curve is defined over a finite field. A point group uses the base field for ordinary points and may use an extension field for a second pairing group. The scalar field, written as Fr in the API, supplies the numbers used to multiply points. The named curve binds these fields to curve coefficients, group orders, cofactors, and pairing parameters.
References: constantine/…/config_fields_and_curves.nim• L22-45 constantine/…/ec_shortweierstrass_affine.nim• L32-45
Curve forms
The API supports two main curve forms. Short Weierstrass curves use the equation y² = x³ + ax + b, while twisted Edwards curves use ax² + y² = 1 + dx²y². Both forms expose the same group ideas, but their neutral elements and point operations follow their own curve equations.
References: constantine/…/ec_shortweierstrass.nim• L9-33 constantine/…/ec_twistededwards.nim• L9-29 constantine/…/ec_twistededwards_projective.nim• L24-56
Point groups
A point group is the set of valid curve points together with a neutral element and the group operations. Pairing-friendly curves commonly expose G1 over the base field and G2 over an extension field; other curves expose one ordinary group. Cofactor clearing and subgroup checks matter because a valid point on the full curve is not always a valid point in the cryptographic subgroup.
References: constantine/lowlevel_elliptic_curves.nim• L49-60 constantine/lowlevel_elliptic_curves.nim• L131-133 constantine/…/config_fields_and_curves.nim• L97-133
Point representations
Coordinate systems
The same mathematical point can use affine or projective coordinates. Affine points store (x, y) and are simple to inspect. Projective and Jacobian points add a third coordinate so that point operations can avoid repeated field inversions. Conversion to affine form is therefore a boundary between convenient input or output and efficient sequences of group operations.
Short Weierstrass curves use affine, projective, or Jacobian forms. Twisted Edwards curves use affine or projective forms. The neutral point also has a curve-specific representation, so code must use the group operations and checks provided for the point type.
References: constantine/…/README.md• L7-15 constantine/…/ec_shortweierstrass_projective.nim• L28-38 constantine/…/ec_shortweierstrass_jacobian.nim• L28-38 constantine/…/ec_twistededwards_projective.nim• L24-34
Group laws
Point addition, subtraction, doubling, negation, equality, and neutral-element checks form the base operation set for every higher-level curve task. The constant-time group laws handle equal points, opposite points, and neutral points without exposing which case occurred. This keeps mathematical edge cases inside the group layer instead of forcing each caller to handle them.
The low-level API also exposes variable-time operations. These operations can use visible case checks and are intended only when the inputs are public.
References: constantine/lowlevel_elliptic_curves.nim• L69-97 constantine/…/ec_shortweierstrass_projective.nim• L160-181 constantine/…/ec_twistededwards_projective.nim• L196-227
Scalar multiplication
Single-point multiplication
Scalar multiplication computes [k]P, which means adding a point P to itself according to the scalar k. It is the main bridge from scalar values to curve points. It supports key generation, signatures, and proof systems.
The constant-time path uses a fixed public shape for its work and may use an endomorphism when the named curve permits it. That acceleration assumes the point is in the right subgroup and the scalar is in the expected range.
References: constantine/…/ec_scalar_mul.nim• L34-43 constantine/…/ec_scalar_mul.nim• L143-169 constantine/…/ec_scalar_mul.nim• L438-469
Scalar-multiplication modes
Constantine separates protected scalar multiplication from variable-time multiplication. The protected path is intended for secret scalars. The variable-time path selects faster methods based on the scalar and curve, so it is intended only when the scalar and point data are public. Endomorphism acceleration also assumes a cleared cofactor and a scalar within the curve order.
References: constantine/…/ec_scalar_mul_vartime.nim• L475-528 constantine/…/ec_scalar_mul.nim• L267-284 constantine/lowlevel_elliptic_curves.nim• L95-98
Multi-scalar multiplication
Linear combinations
Multi-scalar multiplication computes a linear combination of points:
R = [a₀]P₀ + [a₁]P₁ + ... + [aₙ₋₁]Pₙ₋₁
It turns many independent scalar multiplications into one coordinated group operation. This makes it a core primitive for proof systems and polynomial-commitment work, where the point count can be very large.
References: constantine/…/ec_multi_scalar_mul.nim• L21-38 constantine/…/ec_multi_scalar_mul.nim• L525-568
Bucket accumulation
The MSM process groups scalar windows into buckets, reduces each window to a weighted point sum, and joins the window results with repeated doublings. The caller supplies matching coefficient and point sequences. The public API uses variable-time scheduling and may use curve endomorphisms when the curve supports them.
References: constantine/…/ec_multi_scalar_mul.nim• L204-255 constantine/…/ec_multi_scalar_mul.nim• L256-297 constantine/…/ec_multi_scalar_mul.nim• L456-490
Pairing foundations
Pairing groups
A pairing maps one point from G1 and one point from G2 to an element of a target group GT. Its bilinear behavior lets a relation between point sums become a relation in GT, which is the basis for pairing-based proof and signature checks. The curve catalog identifies the field extension, embedding degree, twist, and family needed to define these groups.
References: constantine/…/pairings_bn.nim• L97-107 constantine/…/pairings_bls12.nim• L85-95 constantine/…/config_fields_and_curves.nim• L246-287
Pairing pipeline
Pairing evaluation has three conceptual stages: build the Miller function from curve line values, apply the easy part of the final exponentiation, and apply a curve-specific hard part. The generic entry point selects the BN or BLS12 family and returns a GT value. A pairing check then tests whether the resulting target-group value is one.
The following diagram shows how validated group points move through pairing evaluation and become a target-group result or a boolean check.
flowchart LR
P[G1 point] --> M[Miller loop]
Q[G2 point] --> M
M --> E[Final exponentiation]
E --> GT[GT element]
GT --> C[Pairing check]
C --> B[true or false]
References: constantine/…/pairings_generic.nim• L19-25 constantine/…/pairings_generic.nim• L27-47 constantine/…/pairings_generic.nim• L105-123
Pairing families
The configured pairing families are not interchangeable. BN and BLS12 use G1, G2, and GT structures with family-specific parameters and execution rules. BW6-761 is present in the curve and pairing definitions, but its current reference entry reports that the Miller loop is not working. Do not treat its presence in the catalog as a ready pairing implementation.
References: constantine/…/pairings_bn.nim• L164-193 constantine/…/pairings_bls12.nim• L155-178 constantine/…/pairings_bw6_761.nim• L146-161
Multi-pairings
A multi-pairing computes the product of several pairings before the final target-group result is produced. This lets verification work over a batch of point pairs and avoids treating each pairing as a separate final result. The input pairs must remain aligned because each G1 point is paired with the G2 point at the same position.
References: constantine/…/pairings_bn.nim• L178-205 constantine/…/pairings_bls12.nim• L166-190 constantine/…/multi_pairings.md• L67-99
API boundaries
Low-level curve interface
The low-level curve interface exposes common point types and operations for Short Weierstrass and twisted Edwards groups. It also exposes subgroup helpers, hash-to-curve entry points, scalar multiplication, and MSM. These APIs are useful for building or testing primitives, but the repository marks them as unstable and directs protocol users to stable higher-level interfaces.
References: constantine/lowlevel_elliptic_curves.nim• L26-31 constantine/lowlevel_elliptic_curves.nim• L49-60 constantine/lowlevel_elliptic_curves.nim• L131-139
Low-level pairing interface
The low-level pairing interface exposes line evaluation, Miller accumulators, final exponentiation, target-group exponentiation, and generic pairing calls. These pieces describe the pairing lifecycle, while named constants choose the rules for each supported family. Use Pairing engine when the task concerns pairing execution rather than the shared mathematical model.
References: constantine/lowlevel_pairing_curves.nim• L44-79 constantine/…/zoo_pairings.nim• L9-24
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the named curve's base field, scalar field, subgroup order, cofactor, and curve form aligned with its point types.
- When a curve changes coordinate or group form, check affine conversion, neutral-element handling, scalar multiplication, MSM, and any
G1orG2pairing inputs together. - When a pairing family changes, update its Miller parameters, final exponent rules, target-group type, and generic family dispatch as one contract.
- Keep multi-pairing input order and equal-length
G1andG2sequences consistent across the low-level API and protocol callers. - Do not route secret scalars to variable-time scalar multiplication or MSM APIs.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A point is on the full curve but not in the required subgroup | A protocol can accept an invalid group element or produce an invalid pairing relation | Clear the cofactor and use subgroup checks before protocol use |
| A secret scalar reaches a variable-time multiplication or MSM path | Timing or power observations can reveal scalar information | Use the constant-time scalar-multiplication path and keep variable-time APIs for public data |
G1 and G2 inputs are paired at different positions | The product checks a different relation from the caller's intent | Preserve pair order and validate that both input sequences have equal length |
| BW6-761 is selected for a generic pairing call | The generic pairing path cannot provide a working result for that family | Confirm family dispatch and current implementation status before selecting BW6-761 |
| Twisted Edwards parameters do not meet the complete-formula assumptions | Neutral-element or addition behavior can fail for edge inputs | Check the named curve's parameter conditions before relying on complete group laws |
Key files
| File | Why to read it |
|---|---|
constantine/named/config_fields_and_curves.nim | Defines the field, curve form, subgroup, cofactor, and pairing parameters that give each named curve its meaning. |
constantine/lowlevel_elliptic_curves.nim | Shows the shared curve API and the boundary between point operations, scalar multiplication, MSM, subgroup helpers, and hash-to-curve. |
constantine/math/elliptic/ec_scalar_mul.nim | Explains the protected scalar-multiplication contract for secret values. |
constantine/math/elliptic/ec_scalar_mul_vartime.nim | Explains the separate public-data path and its algorithm selection. |
constantine/math/elliptic/ec_multi_scalar_mul.nim | Describes the MSM result and the bucket-based linear-combination model. |
constantine/lowlevel_pairing_curves.nim | Lists the shared pairing stages and target-group operations. |
constantine/math/pairings/pairings_generic.nim | Connects the generic pairing entry point to family-specific pairing implementations and pairing checks. |
constantine/math/pairings/pairings_bn.nim | Defines the BN pairing and its multi-pairing result. |
constantine/math/pairings/pairings_bls12.nim | Defines the BLS12 pairing and its multi-pairing result. |
constantine/math/pairings/pairings_bw6_761.nim | Records the current BW6-761 pairing status. |