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-cryptography

Ethereum cryptography interfaces

The Ethereum cryptography interfaces connect Ethereum protocol data to Constantine's cryptographic operations. They cover consensus signatures and key derivation, transaction-style ECDSA, blob commitments and data sampling, Verkle proofs, and EVM precompile behavior. The interfaces use fixed protocol encodings and return status values so that callers can pass trusted or untrusted Ethereum bytes through a clear boundary.

Interface map

The interfaces serve different Ethereum roles. BLS and EIP-2333 support consensus keys, KZG and PeerDAS support blob data availability, Verkle IPA supports authenticated state proofs, and the EVM layer exposes protocol-defined byte interfaces.

AreaProtocol roleMain result
BLS signaturesSign and check Ethereum consensus messagesPublic keys, signatures, aggregate checks, and batch checks
EIP-2333 keysTurn seed material into BLS keys and child keysMaster and indexed child secret keys
ECDSASign or check secp256k1 messagesSignatures and recovered public keys
KZG commitmentsBind blob data to a short commitmentCommitments, evaluations, and proofs
PeerDASSample and recover extended blob dataCells and cell proofs
Verkle IPAProve vector relations for Verkle stateIPA proofs, multiproofs, and field mappings
EVM precompilesMatch Ethereum virtual-machine cryptographic callsFixed-size byte outputs and status codes

The protocol-specific modules are available as serial APIs. BLS and KZG also have parallel variants for work that benefits from a threadpool. The parallel variants keep the serial protocol contract and change the execution path rather than the meaning of the data.

References: constantine/ethereum_bls_signatures.nim• L83-109 constantine/ethereum_ecdsa_signatures.nim• L20-34 constantine/ethereum_eip4844_kzg.nim• L59-97 constantine/eth_eip7594_peerdas.nim• L29-69 constantine/ethereum_verkle_ipa.nim• L68-89 constantine/ethereum_evm_precompiles.nim• L36-58

Consensus key interfaces

BLS signatures

The Ethereum BLS interface provides the signature scheme used by the consensus layer. It represents a secret key as a BLS12-381 scalar, a public key on G1, and a signature on G2. It supports key derivation, compressed encoding, single-message checks, aggregate checks, batch checks, and a reusable batch accumulator. See Ethereum BLS signatures and key derivation for the end-to-end signing and key workflow.

The interface uses Ethereum's proof-of-possession BLS scheme and its fixed SHA-256 hash-to-curve domain. Callers must treat successful deserialization or explicit validation as the point at which public keys and signatures become safe inputs for verification. The unchecked deserializers skip subgroup checks and are therefore only suitable when another trusted boundary already provides that check.

For aggregate verification, the input relation matters. Fast aggregate verification checks many public keys against one message, while aggregate verification checks separate public-key and message pairs. Batch verification adds a caller-supplied source of randomness so that the combined check does not become attacker-controlled; the API reports empty input, length mismatch, infinity points, and verification failure as distinct outcomes.

References: constantine/ethereum_bls_signatures.nim• L15-40 constantine/ethereum_bls_signatures.nim• L133-208 constantine/ethereum_bls_signatures.nim• L213-263 constantine/ethereum_bls_signatures.nim• L269-325 constantine/ethereum_bls_signatures.nim• L328-513 constantine/ethereum_bls_signatures_parallel.nim• L16-28 constantine/ethereum_bls_signatures_parallel.nim• L35-88

EIP-2333 keys

The EIP-2333 interface derives BLS12-381 secret keys from input keying material and derives child keys from a parent key plus a 32-bit index. Master derivation accepts seed material of at least 32 bytes. Child derivation uses the EIP-2333 Lamport and HKDF steps to produce a new secret scalar.

This interface supplies secret-key material to the BLS interface; it does not create public keys or signatures. The caller owns the seed lifetime and should clear seed material after derivation. A failed master derivation means the input is too short, while the normal result is a valid non-zero scalar.

References: constantine/ethereum_eip2333_bls12381_key_derivation.nim• L18-36 constantine/ethereum_eip2333_bls12381_key_derivation.nim• L80-176 tests/t_ethereum_eip2333_bls12381_key_derivation.nim• L28-70 tests/t_ethereum_eip2333_bls12381_key_derivation.nim• L116-124

ECDSA

The Ethereum ECDSA interface covers secp256k1 signing and verification with Keccak-256 message hashing. It also derives a public key from a secret key and recovers a public key from a signature when the recovery parity is known. The signature has the two scalar parts used by Ethereum's ECDSA rules.

The recovery operations support both a message form and a pre-hashed scalar form. This lets the EVM recovery interface pass the digest without hashing it again. Nonce selection can be random or RFC 6979 deterministic, so callers must choose the mode that matches their protocol and operational needs.

References: constantine/ethereum_ecdsa_signatures.nim• L20-34 constantine/ethereum_ecdsa_signatures.nim• L47-62 constantine/ethereum_ecdsa_signatures.nim• L64-98

Blob commitment interfaces

KZG commitments

The Ethereum KZG interface binds each blob to a short BLS12-381 G1 commitment. A blob is interpreted as a fixed-size polynomial over the BLS12-381 scalar field. The interface can create a commitment, prove an evaluation, check an evaluation proof, create a proof that a blob matches a commitment, and verify one or many blob proofs.

KZG operations use an EthereumKZGContext loaded from the Ethereum trusted setup. The context connects the commitment and proof APIs to the setup data and the evaluation domain. Inputs and outputs use Ethereum's fixed byte sizes: field elements are 32 bytes, commitments are 48 bytes, proofs are 48 bytes, and a blob contains 4096 field elements.

The normal flow separates binding from checking:

  1. Convert blob bytes into field values.
  2. Create the commitment for the blob.
  3. Create a proof for an opening point or for the blob commitment relation.
  4. Verify the proof with the commitment and the claimed value.

The batch verifier combines many checks with independent random weights. It accepts caller-provided secure random bytes and has a Fiat-Shamir fallback when those bytes produce no usable field challenge. Status values distinguish malformed field or curve encodings from a valid encoding whose proof does not verify.

References: constantine/ethereum_eip4844_kzg.nim• L29-97 constantine/ethereum_eip4844_kzg.nim• L297-407 constantine/ethereum_eip4844_kzg.nim• L409-485 constantine/ethereum_eip4844_kzg.nim• L487-560 constantine/…/ethereum_kzg_srs.nim• L107-155 constantine/…/ethereum_kzg_srs.nim• L165-205

PeerDAS

PeerDAS, the peer data availability sampling scheme from EIP-7594, extends a blob so that a node can request and check cells instead of downloading the full blob. Each cell holds 64 field elements, and the extended blob has twice the field-element capacity of the original blob. A KZG proof links each cell to the blob commitment.

The PeerDAS interface provides four connected operations:

OperationPurpose
Cell computationProduce the cells of the extended blob
Cell and proof computationProduce all cells and their KZG proofs
Batch cell verificationCheck sampled cells against commitments
Cell recoveryRebuild the extended data and proofs from enough cells

The data flow starts with a blob and its KZG context. It produces 128 extended-blob cells and matching 48-byte proof encodings. A sampler can verify selected cells by their indices. Recovery can then rebuild the full extended set when the available cells meet the protocol's recovery condition. See KZG and PeerDAS for the detailed blob-to-cell workflow.

References: constantine/eth_eip7594_peerdas.nim• L29-69 constantine/eth_eip7594_peerdas.nim• L74-103 constantine/eth_eip7594_peerdas.nim• L161-205 constantine/eth_eip7594_peerdas.nim• L274-344 constantine/eth_eip7594_peerdas.nim• L516-593 constantine/eth_eip7594_peerdas.nim• L625-725

This diagram shows how a blob moves through commitment, sampling, verification, and recovery.

flowchart LR
    B[Blob] --> C[KZG commitment]
    B --> X[Extended blob]
    X --> S[Cells and cell proofs]
    C --> V[Batch cell verification]
    S --> V
    V --> R[Available cells]
    R --> Q[Recovered cells and proofs]

Verkle proof interfaces

Verkle IPA

The Verkle IPA interface exposes the cryptographic pieces used by an Ethereum Verkle tree. An inner product argument, or IPA, proves a relation between committed vectors without revealing the full vector. The interface works with the Banderwagon curve and maps curve points into field elements for the Verkle transcript and evaluation rules.

The public boundary covers deterministic generator-point creation, proof and multiproof byte encoding, proof decoding, and point-to-field mapping. A single proof has a fixed 544-byte encoding, while a multiproof has a fixed 576-byte encoding. The wrapper re-exports the lower-level IPA operations and SHA-256 transcript support; it is not a complete Verkle tree state API.

The main relationship is between a curve proof and the scalar values used to evaluate it. Mapping a point first takes the protocol-defined base-field value and then loads that value into the scalar field. The batch mapping form applies the same relation to several points and reports whether all conversions succeeded.

References: constantine/ethereum_verkle_ipa.nim• L23-64 constantine/ethereum_verkle_ipa.nim• L68-89 constantine/ethereum_verkle_ipa.nim• L136-210 constantine/ethereum_verkle_ipa.nim• L218-292 tests/t_ethereum_verkle_ipa_primitives.nim• L33-115

EVM interfaces

EVM precompiles

The EVM precompile interface models Ethereum's byte-oriented cryptographic calls. Each operation receives an input byte array and a caller-owned output buffer. It checks the protocol-required sizes and encodings before returning a result or a CttEVMStatus value.

The supported groups are:

GroupCapabilities
Hash and arithmeticSHA-256, RIPEMD-160, and modular exponentiation
BN254G1 addition, G1 multiplication, and pairing checks
BLS12-381G1/G2 addition, multiplication, multi-scalar multiplication, pairing checks, and field-to-curve mapping
Ethereum recoveryKZG point evaluation and secp256k1 ECRECOVER

The curve calls validate field ranges and curve membership. Operations that need subgroup safety perform subgroup checks where the EVM specification requires them. The caller must pass the exact output size and must handle invalid input, malformed signatures, point failures, and verification failures as different protocol outcomes.

ECRECOVER consumes a 128-byte record containing a Keccak-256 digest, recovery value, and the two ECDSA signature scalars. It recovers the public key and returns the last 20 bytes of its Keccak-256 digest as the Ethereum address. The KZG point-evaluation call checks both the commitment's versioned hash and the KZG proof before returning the blob field count and BLS12-381 modulus.

References: constantine/ethereum_evm_precompiles.nim• L45-145 constantine/ethereum_evm_precompiles.nim• L413-626 constantine/ethereum_evm_precompiles.nim• L628-752 constantine/ethereum_evm_precompiles.nim• L754-1134 constantine/ethereum_evm_precompiles.nim• L1136-1243 constantine/ethereum_evm_precompiles.nim• L1245-1297 constantine/ethereum_evm_precompiles.nim• L1300-1371

EVM validation boundary

The EVM boundary treats byte layout as part of the protocol contract. It uses big-endian values and fixed coordinate layouts for the supported EIPs. The boundary also handles the EVM rules for short input through padding or truncation in the calls where the specification permits it; callers should not assume that every operation has the same length behavior.

The precompile test suite compares the byte outputs and error behavior with Ethereum and Geth test vectors. This gives the EVM layer a protocol-level compatibility check rather than only checking the underlying curve operations.

References: constantine/ethereum_evm_precompiles.nim• L258-389 constantine/ethereum_evm_precompiles.nim• L413-438 tests/t_ethereum_evm_precompiles.nim• L18-104 tests/t_ethereum_evm_precompiles.nim• L106-170

Change checklist

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

  • Keep BLS compressed sizes, Ethereum's hash-to-curve domain, and subgroup validation rules aligned across serialization, single verification, aggregate verification, and batch verification.
  • Keep EIP-2333 master and child derivation changes aligned with the BLS secret-key representation and the published EIP test vectors.
  • Keep KZG context setup data aligned with blob sizes, evaluation domains, proof encodings, and both serial and parallel APIs.
  • Keep PeerDAS cell counts, cell indices, commitment grouping, and proof ordering aligned across compute, verify, and recover operations.
  • Keep EVM input layouts and output lengths aligned with the named EIP and with the precompile test-vector groups.
  • Keep the KZG point-evaluation versioned-hash check aligned with the commitment encoding and the KZG verifier.

Important failure modes

TriggerConsequenceGuard
BLS public key or signature enters verification without a subgroup checkA malformed point can affect the verification resultUse checked deserialization or explicit validation before verification
BLS aggregate or batch inputs have different lengths or contain infinity pointsThe aggregate check returns an input or verification status instead of a valid resultCheck lengths and reject zero or infinity elements at the caller boundary
KZG field element or curve encoding is out of rangeCommitment or proof processing returns a codec-specific KZG errorTreat status values as part of input validation and do not continue after failure
PeerDAS cell index is outside the extended blob or arrays do not matchCell verification or recovery rejects the inputValidate indices and keep commitments, cells, indices, and proofs aligned
EVM output buffer has the wrong sizeThe precompile returns an output-size error and does not provide a protocol resultAllocate the output from the named precompile contract
KZG trusted setup is missing or invalidCommitment, proof, or KZG precompile work cannot use the Ethereum contextLoad the setup and check TrustedSetupStatus before serving requests
ECDSA recovery value is malformedECRECOVER returns a malformed-signature statusValidate the 32-byte recovery field and accept only the protocol values

Key files

FileWhy to read it
constantine/ethereum_bls_signatures.nimPrimary Ethereum BLS types, encodings, signing, aggregation, and verification
constantine/ethereum_bls_signatures_parallel.nimParallel batch BLS verification boundary
constantine/ethereum_eip2333_bls12381_key_derivation.nimEIP-2333 master and child secret-key derivation
constantine/ethereum_ecdsa_signatures.nimsecp256k1 signing, verification, and public-key recovery
constantine/ethereum_eip4844_kzg.nimEthereum blob commitments and KZG proof workflows
constantine/ethereum_eip4844_kzg_parallel.nimParallel KZG operations with the same protocol contract
constantine/commitments_setups/ethereum_kzg_srs.nimEthereum KZG context, trusted setup, domains, and PeerDAS sizes
constantine/eth_eip7594_peerdas.nimPeerDAS cell generation, checking, and recovery
constantine/ethereum_verkle_ipa.nimVerkle IPA proof encoding and point-to-field interface
constantine/ethereum_evm_precompiles.nimEVM byte contracts for hashes, curves, KZG evaluation, and recovery
tests/t_ethereum_bls_signatures.nimEthereum BLS compatibility and aggregate-verification coverage
tests/t_ethereum_eip4844_deneb_kzg.nimDeneb KZG commitment and proof-vector coverage
tests/t_eth_eip7594_peerdas.nimPeerDAS cell, proof, verification, and recovery-vector coverage
tests/t_ethereum_evm_precompiles.nimEVM precompile output and error compatibility coverage