Named curves and group operations
Constantine represents an elliptic-curve group through a named algebra profile and a small set of shared point types. The profile selects the field, equation, group order, and pairing data. Shared operations then provide point arithmetic, scalar multiplication, and multi-scalar multiplication, while curve-specific code supplies the constants and rules that cannot be shared.
Named curve model
Curve profiles
The named curve catalog is the link between mathematical curve names and the generic arithmetic layer. A profile defines the base-field modulus and, when available, the scalar-field order. It also records the equation form and the coefficients needed to check points and perform group operations.
Pairing profiles add an embedding degree and a sextic twist type. A twist is an equivalent curve over a smaller field that represents a second pairing group. These properties connect point arithmetic to the elliptic-curve and pairing overview, the pairing engine, and the extension-field towers.
References: constantine/…/parser_fields.nim• L31-35 constantine/…/parser_fields.nim• L55-90 constantine/…/parser_fields.nim• L92-120 constantine/…/parser_curves.nim• L40-121
Curve families
The catalog marks pairing-friendly curves with a family. Curves without one still use the same point and scalar operation layer, but they do not receive pairing-family metadata.
| Family or class | Named profiles | Main group use |
|---|---|---|
| Barreto–Naehrig | BN254_Nogami, BN254_Snarks | Pairing groups with G1 and G2 points |
| Barreto–Lynn–Scott | BLS12_377, BLS12_381 | Pairing groups with G1 and G2 points |
| Brezing–Weng | BW6_761 | Pairing groups with curve-specific embedding and twist data |
| Short Weierstrass | Pallas, Vesta, Secp256k1 | Prime-field groups for general elliptic-curve work |
| Twisted Edwards | BabyJubjub, Jubjub, Bandersnatch, Banderwagon, Edwards25519 | Groups with an Edwards addition law |
| Parameter and field profiles | P224, P256, BabyBear, KoalaBear, Goldilocks | Field or parameter selection; group support depends on the profile |
The configuration also has small test profiles that are enabled by a test build option. They exercise field and curve machinery without expanding the production catalog.
References: constantine/…/config_fields_and_curves.nim• L45-89 constantine/…/config_fields_and_curves.nim• L91-133 constantine/…/config_fields_and_curves.nim• L135-229 constantine/…/config_fields_and_curves.nim• L231-311
Curve metadata
The profile exposes metadata through named properties rather than through a separate runtime object. Code can ask for the base field or scalar field, the curve family, the equation coefficients, and pairing properties from the selected algebra.
This model keeps large constants tied to the curve name and lets generic code select the right values at compile time. It also makes the same point type usable over a prime field or an extension field when a pairing group needs it.
References: constantine/…/properties_curves.nim• L26-48 constantine/…/properties_curves.nim• L50-74 constantine/…/properties_curves.nim• L76-115 constantine/…/algebras.nim• L1-10
Group abstractions
Short Weierstrass groups
Short Weierstrass groups use the equation y² = x³ + ax + b. The shared short Weierstrass type binds a field F to a subgroup tag. The subgroup tag distinguishes G1 from G2 for pairing curves and prevents points from different groups from being mixed by generic code.
The public short Weierstrass abstraction accepts affine, projective, and Jacobian point forms. A generator can be loaded into any supported form through the named generator path when that curve has a registered generator.
References: constantine/…/ec_shortweierstrass_affine.nim• L27-45 constantine/…/ec_shortweierstrass.nim• L28-52 constantine/…/zoo_generators.nim• L20-26
Twisted Edwards groups
Twisted Edwards groups use the equation ax² + y² = 1 + dx²y². Their shared abstraction supports affine and projective points. Unlike the short Weierstrass model, the identity point is a regular point on the curve rather than a point at infinity.
The Edwards model covers both ordinary Edwards profiles and named constructions such as Bandersnatch and Banderwagon. Banderwagon keeps the Bandersnatch curve equation but represents a quotient subgroup, so its subgroup check is a curve-specific rule rather than a change to the group law.
References: constantine/…/ec_twistededwards_affine.nim• L23-35 constantine/…/ec_twistededwards_affine.nim• L45-58 constantine/…/ec_twistededwards.nim• L25-35 constantine/…/banderwagon_subgroups.nim• L22-28
Pairing subgroups
Pairing curves expose named prime-order groups. G1 normally uses the base field. G2 normally uses an extension field and the curve twist. The point equation and field type therefore change together when code moves from one pairing group to the other.
Subgroup membership is separate from the curve equation. A point can satisfy the curve equation and still be outside the intended prime-order subgroup. The shared cofactor operation maps a curve point into the target subgroup, then the curve-specific subgroup module supplies the fast or reference rule.
References: constantine/…/ec_shortweierstrass_affine.nim• L28-38 constantine/…/zoo_subgroups.nim• L34-40 constantine/…/bls12_381_subgroups.nim• L85-92 constantine/…/bls12_381_subgroups.nim• L103-160
Coordinate systems
Affine coordinates
Affine coordinates store the visible (x, y) pair. They make point I/O, curve checks, generators, and final results simple, but point addition normally needs field inversion. They are therefore most useful at API boundaries or when one point is reused in mixed operations.
Affine constructors can recover a point from one coordinate when the other coordinate has a square root. The constructor is intended for test data; robust message-to-point conversion belongs to the hash-to-curve flow.
References: constantine/…/ec_shortweierstrass_affine.nim• L32-38 constantine/…/ec_shortweierstrass_affine.nim• L95-128 constantine/…/ec_twistededwards_affine.nim• L68-104
Projective coordinates
Projective coordinates replace repeated inversions with field multiplication. In the short Weierstrass model they use X = xZ and Y = yZ. In the Edwards model they use x = X/Z and y = Y/Z.
Projective points are not unique. The identity is represented by a zero-coordinate pattern that is specific to the curve model. Conversion back to affine form is normally delayed until a boundary or a batch conversion can amortize the required inversion.
References: constantine/…/ec_shortweierstrass_projective.nim• L28-38 constantine/…/ec_shortweierstrass_projective.nim• L46-62 constantine/…/ec_twistededwards_projective.nim• L24-34 constantine/…/ec_twistededwards_projective.nim• L42-56
Jacobian coordinates
Jacobian coordinates are a short Weierstrass representation with X = xZ² and Y = yZ³. They reduce the cost of repeated point additions and doublings without changing the represented group.
Extended Jacobian coordinates keep Z² and Z³ alongside X and Y. This form is a specialized working representation for short Weierstrass operations where those powers are used often. It converts to and from the other point forms at the same group boundary as ordinary Jacobian points.
References: constantine/…/ec_shortweierstrass_jacobian.nim• L28-38 constantine/…/ec_shortweierstrass_jacobian_extended.nim• L30-45 constantine/…/ec_shortweierstrass_jacobian_extended.nim• L47-60
Coordinate conversion
The curve layer provides conversions between affine and projective-like forms, plus batch conversion for many points. Batch conversion shares inversion work across a group of points, which makes it useful after a large accumulation or before a serialization step.
The conversion path must preserve the identity point. Each coordinate model has a different identity encoding, so generic callers should use the supplied conversion and identity operations instead of copying coordinates by hand.
References: constantine/…/ec_shortweierstrass.nim• L35-41 constantine/…/ec_shortweierstrass_batch_ops.nim• L29-96 constantine/…/ec_twistededwards_batch_ops.nim• L25-89
Group operations
Point operations
Point arithmetic provides the group law through addition, subtraction or negation, and doubling. The constant-time paths use complete or exception-free laws where the point relation is not exposed through a special case. This matters for inputs that are equal, opposite, or the identity.
The operation form follows the coordinate choice. Projective short Weierstrass addition and projective Edwards addition support mixed inputs when one point is already affine. Jacobian forms provide the corresponding short Weierstrass working path.
References: constantine/…/ec_shortweierstrass_projective.nim• L160-180 constantine/…/ec_shortweierstrass_jacobian.nim• L171-192 constantine/…/ec_twistededwards_projective.nim• L196-227 constantine/…/ec_twistededwards_projective.nim• L276-307
Scalar multiplication
Scalar multiplication computes [k]P. It is the main operation for public-key derivation, signatures, subgroup clearing, and many protocol checks. The default secret-safe path keeps the work pattern independent of scalar bits and uses a fixed public curve-order width.
The library also exposes variable-time multiplication for public scalars. That path is faster in some workloads but must not process secret values. Curve-specific endomorphisms can split a scalar or replace a long multiplication with a smaller set of group operations.
References: constantine/…/ec_scalar_mul.nim• L34-43 constantine/…/ec_scalar_mul.nim• L143-169 constantine/…/ec_scalar_mul_vartime.nim• L41-49 constantine/…/zoo_endomorphisms.nim• L79-122
Multi-scalar multiplication
Multi-scalar multiplication computes a linear combination such as [a₀]P₀ + [a₁]P₁ + .... It is a core workload for proof systems and polynomial commitments because it combines many independent points into one result.
The operation works with the same group types as ordinary scalar multiplication. Its bucket-based work is organized for batches of points, and curve-specific endomorphism support can reduce the scalar work when the selected curve provides it.
References: constantine/…/ec_multi_scalar_mul.nim• L27-38 constantine/…/ec_multi_scalar_mul.nim• L40-90 constantine/…/ec_shortweierstrass.nim• L18-31 constantine/…/ec_twistededwards.nim• L15-27
Curve-specific behavior
Generators and constants
Named constants supply the data that gives a generic group its concrete meaning. Generator modules register the base point for selected curves and subgroups. The dispatch layer then selects the generator by algebra name and subgroup name.
Not every parameter profile has a registered generator module. Engineers should treat generator availability as a property of the selected profile rather than assume that every named field entry is a ready-to-use group.
References: constantine/…/zoo_generators.nim• L9-26 constantine/…/bls12_381_generators.nim• L20-25 constantine/…/bn254_snarks_generators.nim• L23-37 constantine/…/secp256k1_generators.nim• L20-23
Cofactors and subgroup checks
Curve-specific subgroup modules define how a point enters or proves membership in the intended group. A prime-order group can use a no-op cofactor clear and a constant success result after the caller has checked that the point is on the curve. Pairing groups and cofactor-bearing Edwards groups need a real map or check.
The shared clearCofactor entry point chooses the fast rule for the main pairing curves and the reference rule for other configured curves. The distinction keeps the public API common while allowing each curve to use its own group structure.
References: constantine/…/zoo_subgroups.nim• L34-40 constantine/…/secp256k1_subgroups.nim• L22-36 constantine/…/pallas_subgroups.nim• L22-40 constantine/…/bandersnatch_subgroups.nim• L21-34
Endomorphism acceleration
An endomorphism is a curve map that stays within the group and can reduce scalar multiplication work. The named endomorphism layer selects the map for the curve and point form, including special maps for Bandersnatch and Banderwagon and pairing-related maps for several pairing curves.
The acceleration is available only for a configured set of profiles. Generic scalar and multi-scalar code can use the capability without embedding each curve's constants in the core operation.
References: constantine/…/zoo_endomorphisms.nim• L53-104 constantine/…/zoo_endomorphisms.nim• L110-128 constantine/…/bandersnatch_endomorphisms.nim• L13-28
Pairing twists
For pairing curves, the curve-specific data includes the non-residue and twist direction used to represent the second group. The twist changes the curve coefficient seen by the extension-field point, so G2 cannot be treated as a second copy of the base-field G1 type.
The pairing code consumes these named properties when it moves points into the Miller loop and when it builds the target field. Details of that flow belong in Pairing engine; this page only defines the group-side contract.
References: constantine/…/config_fields_and_curves.nim• L97-133 constantine/…/config_fields_and_curves.nim• L246-311 constantine/…/ec_shortweierstrass_affine.nim• L73-93 constantine/…/properties_curves.nim• L76-107
Change checklist
When these files or sections are changed, remember to consider these:
- A new curve profile must keep its base modulus, scalar order, equation form, and subgroup constants aligned. Pairing profiles must also keep embedding-degree and twist data aligned with the extension-field and pairing pages.
- A new generator must be registered in the generator dispatch and must use the subgroup tag expected by the point type.
- A change to a point representation must preserve identity handling and every affine or projective conversion path, including batch conversion.
- A new cofactor or subgroup rule must be connected to the shared subgroup dispatch. A curve check alone does not prove prime-order subgroup membership.
- Endomorphism support must agree with the scalar-splitting data and with the point forms accepted by the generic multiplication paths.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A point is checked only with the curve equation on a curve with a non-trivial cofactor | A small-subgroup point can enter a protocol group | Clear the cofactor and check subgroup membership before group use |
| A secret scalar uses the variable-time multiplication path | Scalar bits can affect timing or control flow | Use the constant-time scalar multiplication path for secret values |
G1 and G2 are treated as the same field-level group | Pairing inputs use the wrong curve or field representation | Keep the subgroup tag, field type, and twist profile together |
| Projective coordinates are copied without their identity rules | The identity can become an invalid point or compare incorrectly | Use the model's setNeutral, conversion, and equality operations |
| A profile has parameters but no generator or subgroup module | Generic group code cannot create or validate the expected group | Check the named constants and curve-specific dispatch before using the profile |
Key files
| File | Why to read it |
|---|---|
constantine/named/config_fields_and_curves.nim | Source of the named curve profiles and their mathematical parameters |
constantine/named/properties_curves.nim | Public view of curve family, equation, field, and pairing properties |
constantine/math/ec_shortweierstrass.nim | Shared short Weierstrass group surface and point-form selection |
constantine/math/ec_twistededwards.nim | Shared Twisted Edwards group surface and point-form selection |
constantine/math/elliptic/ec_shortweierstrass_affine.nim | Affine point meaning, curve checks, and identity behavior |
constantine/math/elliptic/ec_shortweierstrass_projective.nim | Projective short Weierstrass operations and complete addition path |
constantine/math/elliptic/ec_shortweierstrass_jacobian.nim | Jacobian short Weierstrass representation and group operations |
constantine/math/elliptic/ec_twistededwards_projective.nim | Projective Edwards operations and mixed addition |
constantine/math/elliptic/ec_scalar_mul.nim | Secret-safe scalar multiplication contract |
constantine/math/elliptic/ec_multi_scalar_mul.nim | Batch linear combinations of curve points |
constantine/named/zoo_subgroups.nim | Common cofactor-clearing entry point and curve dispatch |
constantine/named/zoo_endomorphisms.nim | Endomorphism capability and curve-specific acceleration dispatch |
constantine/named/zoo_generators.nim | Named generator lookup for configured curves and subgroups |