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 / proof-systems-and-polynomials

Proof systems and polynomial infrastructure

Constantine provides the algebraic building blocks that turn data and computation claims into objects that can be checked with small proofs. Polynomials move between coefficient and evaluation views. FFT domains and matrix helpers make those moves practical. Commitment and interactive-proof layers then bind those values to curve points or to transcript-driven claims. See Commitments and trusted setups for setup and commitment contracts, and Proof-system primitives for the reusable polynomial, matrix, multilinear, and proof components.

System purpose

The proof-system area supports two related goals. It supplies general algebra for protocols that prove polynomial relations, and it supplies protocol-facing paths for Ethereum data availability, where nodes check sampled data without receiving every value. The same field, curve, pairing, FFT, and multi-scalar multiplication foundations serve both goals.

The main relationships are:

ConcernRole in the wider system
Polynomial representationDescribes data as coefficients or as values on a known domain.
Evaluation domainDefines the points used by interpolation, FFT, coset sampling, and quotient checks.
Matrix transformExpresses repeated linear work in forms that FFT and curve operations can process.
CommitmentBinds a polynomial or vector to a short curve value.
Proof systemTurns an opening or algebraic relation into a verifier check.
Data availability samplingExtends and samples committed data so a node can test availability and recover missing data.

Polynomial infrastructure

Polynomial representations

Polynomial data has two main views. PolynomialCoef stores coefficients in the monomial basis. PolynomialEval stores values in the Lagrange basis over a stated domain. The choice affects which operation is direct: coefficients suit polynomial division and domain changes, while evaluations suit point access, commitments with matching setup data, and FFT-based transforms (constantine/math/polynomials/polynomials.nim#L22-L84).

The domain is part of the meaning of evaluation-form data. Roots-of-unity domains support FFTs and cosets. Generic domains support barycentric interpolation. Linear domains add precomputed differences for repeated work over points such as 0, 1, ..., n-1 (constantine/math/polynomials/polynomials.nim#L54-L84, constantine/math/polynomials/polynomials.nim#L502-L649).

References: constantine/…/polynomials.nim• L22-84 constantine/…/polynomials.nim• L502-649

Quotient and vanishing polynomials

Polynomial operations connect data to proof claims. A vanishing polynomial is zero at a chosen set of points. A quotient polynomial captures the difference between a polynomial and its claimed value divided by the matching linear factor. This quotient is the central witness shape used by KZG openings and related algebraic checks (constantine/math/polynomials/polynomials.nim#L384-L549, constantine/commitments/protocol_quotient_check.nim#L23-L44).

The quotient path handles both cases that matter to protocol code: the challenge is outside the evaluation domain, or it matches a domain point. The second case needs a separate relation because direct division would produce an undefined 0/0 term (constantine/commitments/protocol_quotient_check.nim#L46-L114).

References: constantine/…/polynomials.nim• L384-549 constantine/…/protocol_quotient_check.nim• L23-114

FFT and coset transforms

FFT infrastructure changes between coefficient values and values on roots-of-unity domains. A field FFT descriptor owns the transform order and the roots that define that domain. Natural and bit-reversed order are separate data conventions, so a producer and consumer must agree on both the domain and the order (constantine/math/polynomials/fft_fields.nim#L34-L58, constantine/math/polynomials/fft_fields.nim#L87-L148).

A coset is a shifted roots-of-unity domain. Coset FFTs apply a field shift before the transform, and coset inverse FFTs remove it after the inverse transform. This lets protocols evaluate related polynomial views without using the original domain directly (constantine/math/polynomials/fft_fields.nim#L607-L742).

The following flow shows how a polynomial view becomes a sampled or committed protocol value.

flowchart LR
    D[Data or constraint values] --> E[Evaluation-form polynomial]
    E -->|IFFT| C[Coefficient-form polynomial]
    C -->|FFT or coset FFT| X[Domain or coset evaluations]
    C --> Q[Quotient or vanishing-polynomial relation]
    E --> M[Commitment or proof input]
    Q --> M
    M --> V[Verifier check]

References: constantine/…/fft_fields.nim• L34-58 constantine/…/fft_fields.nim• L152-180 constantine/…/fft_fields.nim• L607-742 constantine/…/polynomials.nim• L650-660

Matrix and linear-transform support

Matrix layout

Matrix helpers support the linear work that appears when polynomial values are reorganized or curve points are combined. Transposition changes row-major data into the layout expected by later passes. The blocked form exists to keep nearby values in cache while it performs that change (constantine/math/matrix/transpose.nim#L32-L79).

References: constantine/…/transpose.nim• L36-79

Toeplitz transforms

Toeplitz multiplication is the main protocol-specific matrix path. A Toeplitz matrix is embedded in a circulant vector, transformed with FFTs, combined pointwise, and transformed back. In the FK20 path, the resulting field values feed per-position multi-scalar multiplications over curve points. This connects polynomial structure to many KZG proofs without treating each proof as an unrelated calculation (constantine/math/matrix/toeplitz.nim#L23-L38, constantine/math/matrix/toeplitz.nim#L187-L240, constantine/math/matrix/toeplitz.nim#L286-L342).

Matrix size and layout are part of the contract. The Toeplitz accumulator expects all layers for one output position to stay together, and it finishes only after every layer has been accumulated. These rules preserve the correspondence between polynomial positions, SRS points, and proof outputs (constantine/math/matrix/toeplitz.nim#L209-L266, constantine/math/matrix/toeplitz.nim#L307-L329).

References: constantine/…/toeplitz.nim• L23-38 constantine/…/toeplitz.nim• L187-240 constantine/…/toeplitz.nim• L286-342

Commitment and proof model

Polynomial commitments

A commitment binds a polynomial or vector to a short public curve value. An opening proof then shows that a claimed value belongs to the committed object. KZG uses the quotient relation and a trusted setup. Pedersen uses public generators to form a vector commitment and can add a hiding term. The detailed setup and scheme contracts are covered in Commitments and trusted setups (constantine/commitments/kzg.nim#L102-L163, constantine/commitments/pedersen_commitments.nim#L22-L36).

References: constantine/…/kzg.nim• L102-163 constantine/…/pedersen_commitments.nim• L22-36

Opening and verification flow

The KZG proof model separates the prover's polynomial work from the verifier's small check. The prover commits to a polynomial, receives or derives an opening challenge, returns the evaluation and a quotient proof, and lets the verifier check the relation with a pairing and the setup point. The verifier does not need the full polynomial for a normal opening (constantine/commitments/kzg.nim#L120-L163, constantine/commitments/kzg.nim#L228-L280).

Batch verification preserves the same relation with random weights that the prover cannot select. This prevents linear commitments from canceling in a way that hides an invalid opening (constantine/commitments/kzg.nim#L282-L329, constantine/commitments/kzg_parallel.nim#L80-L120).

The relationship between the core inputs is:

sequenceDiagram
    participant P as Prover
    participant V as Verifier
    participant S as Setup
    P->>S: Use public setup points
    P->>P: Form polynomial commitment
    V->>P: Provide or derive challenge
    P->>P: Compute evaluation and quotient proof
    P->>V: Return commitment, evaluation, and proof
    V->>S: Read matching setup point
    V->>V: Check pairing relation

References: constantine/…/kzg.nim• L120-163 constantine/…/kzg.nim• L228-329 constantine/…/kzg_parallel.nim• L33-120

Interactive-proof foundations

Constraint statements

A constraint statement expresses a computation as algebraic relations over field values. The R1CS format represents each relation as the product of two sparse linear combinations minus a third linear combination. Constantine reads the standard format so tools that compile circuits can pass statements to later proof-system work (constantine/…/r1cs_circom_bin_format.md• L7-18, constantine/…/r1cs_circom_bin_format.md• L27-40).

The parser keeps the file's header, constraints, wire-to-label map, and optional custom-gate sections as separate logical sections. It validates file structure and ordering rules while leaving field-specific proof processing to higher layers (constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L27-L47, constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L108-L119).

References: constantine/…/r1cs_circom_bin_format.md• L7-18 constantine/…/r1cs_circom_bin_format.md• L27-40 constantine/…/r1cs_circom_parser.nim• L27-47

Multilinear extensions

A multilinear extension turns a function defined on Boolean inputs into the unique polynomial that is linear in each variable and agrees with the function on every Boolean point. This gives interactive-proof protocols a compact way to treat a table of values as one algebraic object (constantine/boolean_hypercube/multilinear_extensions.nim#L18-L40).

The public evaluator supports big-endian and little-endian interpretations of the Boolean index. A reference evaluator and an optimized evaluator provide the same mathematical result. The interactive-proof tests compare these views across small and larger finite-field examples (constantine/boolean_hypercube/multilinear_extensions.nim#L286-L323, tests/interactive_proofs/t_multilinear_extensions.nim#L36-L47, tests/interactive_proofs/t_multilinear_extensions.nim#L123-L161).

References: constantine/…/multilinear_extensions.nim• L18-40 constantine/…/multilinear_extensions.nim• L286-323 tests/…/t_multilinear_extensions.nim• L36-47

Transcript-driven challenges

An interactive proof normally obtains a challenge from the verifier between proof rounds. The transcript replaces that interaction with a shared hash state: both sides absorb the same public values and proof messages, then derive the same field challenge. Domain separators keep separate protocol stages from sharing one challenge context (constantine/commitments/eth_verkle_transcripts.nim#L18-L52, constantine/commitments/eth_verkle_transcripts.nim#L54-L109).

The Ethereum Verkle IPA path uses this transcript model for a vector commitment whose vector is polynomial evaluations. Recursive rounds halve the vectors and send left and right curve elements. The final proof is logarithmic in the vector length, while the verifier rebuilds the challenges and checks the final relation (constantine/commitments/eth_verkle_ipa.nim#L57-L120, constantine/commitments/eth_verkle_ipa.nim#L124-L153).

References: constantine/…/eth_verkle_transcripts.nim• L18-109 constantine/…/eth_verkle_ipa.nim• L57-120 constantine/…/eth_verkle_ipa.nim• L124-153

Data availability sampling

PeerDAS data model

PeerDAS, or Peer Data Availability Sampling, applies polynomial commitments to a larger availability view of an Ethereum blob. A blob becomes a polynomial. The polynomial is extended with redundancy. The extended values are grouped into cells. Each cell covers one coset of evaluations and has a KZG proof. A node can then request and check selected cells instead of the complete blob (constantine/eth_eip7594_peerdas.nim#L29-L68).

The generic PeerDAS layer works on validated polynomials, domains, and FFTs. The Ethereum-facing layer handles byte conversion and status codes. This split keeps the sampling math independent from the serialized form used at the protocol boundary (constantine/data_availability_sampling/eth_peerdas.nim#L17-L32).

References: constantine/eth_eip7594_peerdas.nim• L29-68 constantine/…/eth_peerdas.nim• L17-43

Cell proof lifecycle

The cell lifecycle connects the polynomial and commitment layers:

  1. Convert blob bytes into validated field values in evaluation form.
  2. Extend the polynomial over the larger domain and serialize the values as cells.
  3. Produce one coset proof for each cell.
  4. Sample cells and verify their proofs against the relevant commitment.
  5. Recover all cells when at least half of the extended cells are available.

The proof path uses FK20-style amortization to produce many cell proofs. The verification path derives a batch challenge from the commitments, cell positions, cell values, and proofs, then checks one aggregated relation. Commitment de-duplication allows repeated cells from the same blob to share the same decoded commitment (constantine/eth_eip7594_peerdas.nim#L274-L344, constantine/eth_eip7594_peerdas.nim#L479-L621).

References: constantine/eth_eip7594_peerdas.nim• L207-344 constantine/eth_eip7594_peerdas.nim• L479-621

Recovery path

Recovery treats missing cells as unknown evaluations of the extended polynomial. It builds a vanishing polynomial for the missing positions, combines it with the available evaluations, and uses FFT and coset transforms to recover the coefficient form. A final FFT rebuilds every extended cell, after which the system recomputes the corresponding proofs (constantine/data_availability_sampling/eth_peerdas.nim#L83-L124, constantine/data_availability_sampling/eth_peerdas.nim#L132-L225, constantine/eth_eip7594_peerdas.nim#L625-L725).

The recovery contract requires enough cells and a strictly ascending list of unique cell indices. These checks preserve the mapping between received cells and positions in the extended domain (constantine/eth_eip7594_peerdas.nim#L647-L675).

References: constantine/…/eth_peerdas.nim• L83-124 constantine/…/eth_peerdas.nim• L132-225 constantine/eth_eip7594_peerdas.nim• L625-725

Change checklist

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

  • Keep coefficient order, evaluation order, bit reversal, and coset shifts aligned across FFT, quotient, commitment, proof, and recovery paths.
  • Keep the polynomial degree, evaluation-domain size, cell size, and extended-domain size consistent. A mismatch can produce valid-looking field values at the wrong points.
  • Keep the SRS basis aligned with its consumer. Blob commitments use evaluation-form data, while FK20 cell proofs use coefficient-form data.
  • Keep the quotient relation and its special in-domain case aligned with challenge handling. A change to domain membership can alter both the claimed value and the proof witness.
  • Keep transcript labels and absorbed input order stable across prover and verifier. A mismatch derives different challenges without an obvious type error.
  • Keep the R1CS field metadata and sparse factor encoding aligned with the circuit tool that writes the file.
  • Keep PeerDAS cell indices, commitment references, coset evaluations, and proof arrays aligned before batch aggregation or recovery.

Important failure modes

TriggerConsequenceGuard
Polynomial data uses the wrong domain or orderingInterpolation, commitment, or proof values refer to different pointsCarry the domain and ordering with evaluation-form data and preserve bit-reversal conventions (constantine/math/polynomials/polynomials.nim#L32-L84)
Opening challenge is treated as outside the domain when it matches a domain pointQuotient computation reaches an undefined 0/0 termUse the in-domain quotient path (constantine/commitments/protocol_quotient_check.nim#L46-L114)
Batch weights come from the prover or are not independentLinear commitment terms can cancel and hide an invalid proofUse secure randomness or the prescribed transcript-derived challenge (constantine/commitments/kzg.nim#L282-L329, constantine/eth_eip7594_peerdas.nim#L479-L515)
Cell indices are out of range, duplicated, or not ascending for recoverySamples map to the wrong coset or recovery cannot build a valid domain viewCheck bounds and strict ordering before conversion (constantine/eth_eip7594_peerdas.nim#L542-L545, constantine/eth_eip7594_peerdas.nim#L647-L660)
Fewer than half of the extended cells are availableThe original polynomial cannot be uniquely recoveredReject recovery below the minimum cell count (constantine/eth_eip7594_peerdas.nim#L647-L649)
Transcript inputs or labels differ between prover and verifierFiat-Shamir challenges differ and a valid proof fails verificationPreserve domain separators and absorb the same labeled values (constantine/commitments/eth_verkle_transcripts.nim#L60-L109)
R1CS sections or sparse factors do not match the declared file metadataThe circuit statement is rejected or interpreted with the wrong wiresValidate section sizes, field size, and sorted factor indices (constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L127-L185)

Key files

FileWhy to read it
constantine/math/polynomials/polynomials.nimDefines coefficient and evaluation polynomial views, domains, interpolation, evaluation, and vanishing-polynomial operations.
constantine/math/polynomials/fft_fields.nimDefines field FFT and inverse FFT domains, order conventions, and coset transforms.
constantine/math/matrix/toeplitz.nimConnects structured matrix multiplication with FFTs and curve multi-scalar multiplication for amortized proof work.
constantine/commitments/protocol_quotient_check.nimShows how an evaluation claim becomes a quotient witness.
constantine/commitments/kzg.nimDefines the generic polynomial commitment, opening, pairing check, and batch-verification model.
constantine/commitments/eth_verkle_ipa.nimShows the transcript-driven inner-product proof built over polynomial evaluations.
constantine/commitments/eth_verkle_transcripts.nimDefines the shared absorb and challenge rules for non-interactive proof rounds.
constantine/proof_systems/constraint_systems/r1cs_circom_parser.nimDefines the boundary that reads circuit constraints from the standard R1CS file format.
constantine/boolean_hypercube/multilinear_extensions.nimDefines multilinear extensions for functions over Boolean inputs.
constantine/data_availability_sampling/eth_peerdas.nimDefines generic PeerDAS coset operations and polynomial recovery from available cells.
constantine/eth_eip7594_peerdas.nimExposes the serialized cell, proof, batch-verification, and recovery lifecycle for Ethereum.
constantine/commitments/kzg_multiproofs.nimDefines coset openings and the FK20 path used to produce many KZG proofs.