Introducing a new way to review your PRs.

Read the announcement

mratsim / constantine

Constantine: modular, high-performance, zero-dependency cryptography stack for verifiable computation, proof systems and blockchain protocols.

View on GitHub

19 documents · Updated Nov 13, 2026

docs / ethereum-bls-signatures-and-key-derivation

Ethereum BLS signatures and key derivation

Constantine provides the Ethereum BLS12-381 signature scheme and the EIP-2333 key-derivation flow. The APIs turn byte seeds into valid secret keys, derive public keys on G1, sign messages into signatures on G2, and verify or combine those objects for Ethereum consumers.

System role

The Ethereum-facing layer fixes the cryptographic choices that an Ethereum consumer must share with other implementations. It uses BLS12-381 with public keys in G1 and signatures in G2. It also fixes SHA-256 hash-to-curve behavior and the Ethereum proof-of-possession domain separation tag.

The main public entry point is constantine/ethereum_bls_signatures.nim. It presents protocol types and status codes while the generic signature layer performs the curve and pairing work. The C header exposes the same core lifecycle to native callers. The parent page, Ethereum cryptography interfaces, places this API beside the KZG commitments and PeerDAS interfaces. The lower-level group model is described in Named curves and group operations.

BLS object model

Each BLS object has one role in the signing flow. A secret key is a scalar in the BLS12-381 scalar field. A public key is the generator multiplied by that scalar in G1. A signature is the hash of a message mapped to G2 and multiplied by the same scalar.

ObjectMathematical locationCompressed sizeMain use
Secret keyBLS12-381 scalar field32 bytesInput to public-key derivation and signing
Public keyG1 over the base field48 bytesIdentifies the signer during verification
SignatureG2 over the quadratic extension field96 bytesProves possession of the secret key for a message

The Ethereum suite uses BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_ as its domain separation tag. This tag keeps these signatures separate from signatures made by another BLS suite. The Ethereum protocol uses proof of possession at the deposit boundary, so this layer does not expose separate proof-of-possession prove and verify calls.

EIP-2333 key derivation

Master key derivation

The master-key API accepts input keying material and returns a scalar suitable for BLS12-381. derive_master_secretKey requires at least 32 bytes of input. It uses the EIP-2333 BLS key-generation construction with HKDF-SHA256 and reduces the derived 48-byte result modulo the BLS12-381 scalar order.

The key-generation salt starts from BLS-SIG-KEYGEN-SALT-. If reduction produces zero, the flow hashes the salt again and retries. This makes zero an invalid output while preserving the EIP-2333 result for normal inputs. Callers should clear the input material after use because it can contain the root secret.

References: constantine/ethereum_eip2333_bls12381_key_derivation.nim• L18-78 constantine/ethereum_eip2333_bls12381_key_derivation.nim• L167-177

Child key derivation

The child-key API maps a parent secret key and a 32-bit child index to a new secret key. It first builds a compressed Lamport public key from the parent key and the index. It then runs the same EIP-2333 scalar-generation step on that 32-byte result.

This design gives consumers a deterministic hierarchy without placing public-key operations in the derivation path. The index is encoded in big-endian form, so the index encoding is part of the compatibility contract between wallets and validators.

References: constantine/ethereum_eip2333_bls12381_key_derivation.nim• L80-165

Derivation validation

The derivation functions report whether the input can produce a result. Master derivation rejects input shorter than 32 bytes. Secret-key consumers must still treat a scalar as valid only when it is non-zero and below the BLS12-381 scalar order.

The EIP-2333 tests compare master and child results with known vectors. They cover different seeds and child indices, including the largest 32-bit index, which checks both the byte-level contract and the scalar result.

References: constantine/ethereum_eip2333_bls12381_key_derivation.nim• L152-177 tests/t_ethereum_eip2333_bls12381_key_derivation.nim• L28-124

Signature lifecycle

The signature lifecycle connects key derivation, curve multiplication, hash-to-curve, serialization, and pairing checks. The following diagram shows the path from a secret key and message to a signature or a verification result.

flowchart LR
    IKM[Input key material] --> MK[Master secret key]
    MK --> CK[Child secret key]
    CK --> PK[Public key on G1]
    CK --> HM[Hash message to G2]
    HM --> SIG[Signature on G2]
    PK --> CHECK[Pairing check]
    SIG --> CHECK
    MSG[Message] --> HM
    CHECK --> RESULT[Verification status]

Public-key derivation

derive_pubkey multiplies the G1 generator by a validated secret scalar and converts the result to the public affine form. The operation is the bridge between EIP-2333 secret keys and the public key that Ethereum consumers store or publish.

The API expects the secret key to be validated before derivation. A zero or out-of-range scalar does not represent a valid BLS signer and must not be used as a public-key source.

References: constantine/ethereum_bls_signatures.nim• L130-147 constantine/ethereum_bls_signatures.nim• L210-217 constantine/…/ecc_sig_ops.nim• L11-22

Message signing

sign hashes the message to a point in G2 with SHA-256 and the Ethereum domain separation tag. It then multiplies that point by the secret scalar and writes the resulting signature.

The public key remains in G1 while the signature remains in G2. This placement is important for both the compressed byte sizes and the pairing equation used by verification.

References: constantine/ethereum_bls_signatures.nim• L15-27 constantine/ethereum_bls_signatures.nim• L219-235 constantine/…/bls_signatures.nim• L40-77

Signature verification

verify hashes the message with the same suite and checks a pairing relation between the public key, the message point, the signature, and the negated G1 generator. A valid signature makes the product of the pairings equal the identity element.

Verification assumes that the public key and signature have already passed the required curve and subgroup checks. The protocol wrapper adds an explicit rejection for the neutral point, also called the point at infinity, before it runs the pairing check.

References: constantine/…/bls_signatures.nim• L79-102 constantine/ethereum_bls_signatures.nim• L236-263 constantine/…/pairings_generic.nim• L27-34

Aggregate and batch verification

The API supports three different multi-signature questions. They differ in how messages and signatures are related, so a consumer must select the path that matches its protocol data.

APIQuestion answeredExtra protection
fast_aggregate_verifyDoes one aggregate signature match many public keys for one message?Public keys and the aggregate signature must be valid and non-neutral
aggregate_verifyDoes one aggregate signature match many public-key and message pairs?Same-message keys need safe aggregation plus augmentation or proof of possession
batch_verifyAre all public-key, message, and signature triplets valid?Cryptographically secure random bytes are required for blinding

aggregate_pubkeys_unstable_api and aggregate_signatures_unstable_api combine group elements. They are low-level composition steps: they assume that each input has already been checked and return the neutral point for an empty input. The verification wrappers reject empty aggregates and neutral inputs with explicit status values.

Batch verification flow

Batch verification combines pairing work for many triplets instead of checking each triplet as a separate operation. It uses a fresh, attacker-independent random input to weight the checks. This prevents invalid inputs from cancelling through the bilinear group operation and appearing valid as one aggregate.

The parallel API gives a thread-pool based version of the same batch question. It keeps the serial API available and returns the same status categories while distributing the work across the supplied thread pool.

sequenceDiagram
    participant C as Consumer
    participant V as BLS verifier
    participant P as Pairing accumulator
    C->>V: Public keys, messages, signatures, secure random bytes
    V->>V: Check lengths and reject neutral points
    loop Each triplet
        V->>P: Add blinded pairing relation
    end
    P-->>V: Product of pairing terms
    V-->>C: Success or verification failure

References: constantine/…/bls_signatures.nim• L122-242 constantine/…/bls_signatures.nim• L244-528 constantine/ethereum_bls_signatures_parallel.nim• L35-88

Serialization and validation

Serialization is the boundary between in-memory curve objects and Ethereum protocol bytes. The codec uses the Zcash BLS12-381 format adopted by the IETF BLS signature work. Field values use big-endian encoding. G1 coordinates use the base field, while G2 coordinates use the extension field.

Encoded valueCompressed formUncompressed formValidation concern
G1 public key48 bytes96 bytesEncoding flags, field range, curve membership, subgroup membership
G2 signature96 bytes192 bytesEncoding flags, both field coordinates, curve membership, subgroup membership
Scalar secret key32 bytesNot usedNon-zero and below the scalar order

The first three bits of a compressed point carry metadata. They identify compressed form, the neutral point, and the selected square-root sign. For the neutral point, the remaining bytes must be zero. Deserialization reconstructs the missing y-coordinate from x and then selects the root described by the sign bit.

Validation paths

The checked deserializers reject malformed encodings, coordinates outside the base-field range, points not on the curve, and points outside the expected subgroup. The *_unchecked variants stop before the expensive subgroup check. They are suitable only when a trusted store or a separate validation step provides that guarantee.

Scalar deserialization also validates the scalar range. Invalid scalars and invalid curve points produce status codes and clear the scalar result where required. These statuses let C and Nim callers distinguish bad encoding, a neutral point, a bad subgroup, and a bad scalar.

References: constantine/…/codecs_bls12_381.nim• L15-37 constantine/…/codecs_bls12_381.nim• L56-113 constantine/…/codecs_bls12_381.nim• L116-196 constantine/…/codecs_bls12_381.nim• L199-288

Consumer interfaces

The Nim API is the protocol layer used by Constantine code. The C API wraps its secret key, public key, signature, and accumulator types in fixed-layout structures with explicit status codes. This gives native and binding consumers a stable byte and ownership boundary without exposing the generic curve types.

C and parallel access

The serial C interface covers key validation, compressed serialization, signing, single verification, aggregate verification, and batch verification. The parallel header adds batch verification through a caller-owned thread pool. It preserves the same suite, input rules, statuses, and randomness requirement.

The accumulator interface separates batch setup, item updates, and final verification. C callers must obtain its storage through the provided allocator and release it through the matching free function. This keeps the opaque context size out of consumer code while preserving the same validation contract.

References: include/…/ethereum_bls_signatures.h• L77-165 include/…/ethereum_bls_signatures.h• L167-221 include/…/ethereum_bls_signatures.h• L245-359 include/…/ethereum_bls_signatures_parallel.h• L20-57

Curve operation boundary

The Ethereum layer depends on the BLS12-381 curve groups but does not redefine their general algebra. Public-key derivation uses scalar multiplication in G1. Signing uses hash-to-curve and scalar multiplication in G2. Verification uses the BLS12-381 pairing and its identity check.

This boundary matters when a consumer needs more than the protocol wrappers. The curve headers expose field, group, scalar multiplication, multi-scalar multiplication, and hash-to-curve operations for lower-level integrations. Use the Ethereum wrapper for Ethereum wire and suite rules; use the named-curve layer for general group work.

Change checklist

When these files or sections are changed, remember to consider these:

  • A change to the Ethereum domain separation tag or hash-to-curve suite affects signing, verification, aggregate verification, batch verification, and every interoperability vector.
  • A change to the G1/G2 role or compressed sizes affects the protocol types, C ABI buffers, codecs, and all consumers that store serialized keys or signatures.
  • A change to EIP-2333 salt handling, HKDF output length, index encoding, or retry behavior changes wallet-derived keys and must be checked against external EIP-2333 vectors.
  • A change to checked versus unchecked deserialization changes the security contract for callers that cache validation or load points from storage.
  • A change to batch blinding or accumulator merging must preserve the security requirement for attacker-independent randomness and the result agreement between serial and parallel APIs.

Important failure modes

TriggerConsequenceGuard
Input keying material is shorter than 32 bytesMaster derivation returns failure and no valid master key existsEnforce the EIP-2333 minimum before deriving
Scalar is zero or at least the BLS12-381 scalar orderSecret-key use is invalid and public-key derivation has no valid signerValidate every imported or supplied secret key
Compressed point has bad flags, an out-of-range coordinate, or no curve pointDeserialization rejects the public key or signatureUse the checked deserializer and handle its status
Point is on the curve but not in the required subgroupSmall-subgroup attacks can affect protocol checksDo not use an unchecked point until subgroup validation is complete
Public key, signature, or aggregate is the neutral pointVerification returns a point-at-infinity failureReject neutral values at the protocol boundary
Aggregate inputs are empty or have different lengthsVerification returns an aggregation or length failureCheck cardinality before calling the aggregate API
Batch verification uses missing or attacker-controlled random bytesForged invalid triplets can pass a combined checkSupply cryptographically secure bytes that the attacker cannot choose
Signer and verifier use different suite tagsValid signatures fail verification or can cross protocol domainsKeep the exact Ethereum domain separation tag on both sides

Key files

FileWhy to read it
constantine/ethereum_bls_signatures.nimDefines the Ethereum BLS types, suite choice, wrapper APIs, status handling, and C-facing lifecycle
constantine/ethereum_eip2333_bls12381_key_derivation.nimDefines master and child EIP-2333 derivation for BLS12-381
constantine/signatures/bls_signatures.nimExplains the shared signing, pairing verification, aggregation, and batch-verification model
constantine/serialization/codecs_bls12_381.nimDefines scalar and compressed G1/G2 encoding plus checked and unchecked validation paths
constantine/ethereum_bls_signatures_parallel.nimDefines the thread-pool batch-verification entry point
include/…/ethereum_bls_signatures.hShows the native ABI, fixed buffer sizes, status codes, and opaque accumulator contract
include/…/ethereum_bls_signatures_parallel.hShows the native parallel batch-verification contract
tests/t_ethereum_bls_signatures.nimConfirms interoperability behavior for codecs, signing, single verification, aggregate verification, and batch verification
tests/t_ethereum_eip2333_bls12381_key_derivation.nimConfirms master and child derivation against EIP-2333 vectors