Proof-system primitives
Constantine’s proof-system primitives turn field data into forms that proof protocols can use. They provide polynomial representations and transforms, structured matrix operations, multilinear extensions over Boolean inputs, constraint-system input, and transcript-driven inner-product proofs. Higher-level commitment and protocol pages build on these parts; see Proof systems and polynomials and Commitments and trusted setups.
Proof-system data flow
The library separates algebraic data from the proof relation that consumes it. A polynomial can move between coefficient and evaluation views, a matrix operation can reduce a large structured product, and a transcript can turn an interactive challenge sequence into a proof that a verifier can replay.
The main relationships are:
flowchart LR
I[Field values or constraints] --> R[Polynomial representation]
R --> F[FFT or interpolation]
R --> M[Structured matrix operation]
I --> B[Boolean-cube evaluations]
B --> E[Multilinear extension]
R --> P[Proof relation]
E --> P
P --> T[Transcript challenges]
T --> V[Verifier result]
These primitives are reusable rather than a complete proof-system framework. The core library supplies the algebraic transformations and proof checks. Protocol layers choose the commitment setup, input format, challenge rules, and security model.
Polynomial representations
The polynomial layer represents the same field polynomial in the form best suited to the next operation. Coefficient form stores the monomial coefficients, while evaluation form stores values on a known domain. This choice connects ordinary algebra such as division and derivatives with fast transforms and commitment schemes (constantine/math/polynomials/polynomials.nim#L22-L84).
Coefficient form
constantine/math/polynomials/polynomials.nim defines PolynomialCoef as a fixed-size coefficient view. It supports direct evaluation, simultaneous evaluation with the formal derivative, derivative construction, addition, subtraction, and polynomial division (constantine/math/polynomials/polynomials.nim#L22-L30, constantine/math/polynomials/polynomials.nim#L89-L203).
This form is useful when a protocol needs the polynomial equation itself. A vanishing polynomial describes a set of roots, and its derivative at a root supplies the weights needed by interpolation over a generic domain (constantine/math/polynomials/polynomials.nim#L446-L500).
References: constantine/…/polynomials.nim• L22-30 constantine/…/polynomials.nim• L89-203 constantine/…/polynomials.nim• L446-500
Evaluation form
PolynomialEval stores polynomial values in Lagrange form. The domain may be roots of unity or a generic set of points. Domain metadata records the points and the derivative weights of the vanishing polynomial so that a verifier or prover can evaluate the polynomial away from the stored points (constantine/math/polynomials/polynomials.nim#L36-L84, constantine/math/polynomials/polynomials.nim#L384-L440, constantine/math/polynomials/polynomials.nim#L502-L612).
Evaluation form is the bridge to proof commitments and inner products. A polynomial value at a new point is the inner product of its domain values with the Lagrange basis values at that point. The linear-domain setup specializes this work for points [0, ..., N-1] (constantine/math/polynomials/polynomials.nim#L551-L645).
References: constantine/…/polynomials.nim• L36-84 constantine/…/polynomials.nim• L384-440 constantine/…/polynomials.nim• L502-645
FFT and coset transforms
The FFT layer changes the ordering and representation of polynomial data over roots of unity. A field FFT descriptor defines the supported transform order and roots of unity. The public transforms cover natural and bit-reversed layouts, forward and inverse directions, and in-place use where supported (constantine/math/polynomials/fft_fields.nim#L34-L58, constantine/math/polynomials/fft_fields.nim#L187-L221, constantine/math/polynomials/fft_fields.nim#L532-L589).
A coset transform shifts the evaluation points away from the original roots of unity. This lets polynomial division avoid points where a denominator would be zero, then returns the result to coefficient form after the inverse transform (constantine/math/polynomials/fft_fields.nim#L629-L687). The parallel polynomial API keeps the same evaluation meaning while distributing the off-domain sum across a thread pool (constantine/math/polynomials/polynomials_parallel.nim#L24-L97).
References: constantine/…/fft_fields.nim• L34-58 constantine/…/fft_fields.nim• L187-221 constantine/…/fft_fields.nim• L532-589 constantine/…/fft_fields.nim• L629-687 constantine/…/polynomials_parallel.nim• L24-97
Structured matrix operations
The matrix primitives support data movement and structured products that appear in proof generation. They are general over element types, but the Toeplitz path also connects field transforms with elliptic-curve multi-scalar multiplication for amortized proof work.
Matrix transposition
constantine/math/matrix/transpose.nim provides a tiled transpose for a pre-allocated rectangular matrix. It changes row-major layout into column-major layout without changing the field values, which helps consumers align data with the next stage of a proof or transform (constantine/math/matrix/transpose.nim#L36-L79).
References: constantine/…/transpose.nim• L36-79
Toeplitz multiplication
Toeplitz multiplication applies a structured matrix to a vector without materializing every matrix entry. constantine/math/matrix/toeplitz.nim embeds the matrix in a circulant form, uses field and elliptic-curve FFTs, combines frequency-domain values, and returns the product after inverse transformation (constantine/math/matrix/toeplitz.nim#L23-L38, constantine/math/matrix/toeplitz.nim#L370-L439).
The accumulator form is designed for repeated layers of the same structured product. It collects transformed coefficient sets, combines them with a bank of curve points, and performs the final curve transform. This is the reusable algebraic core used by fast amortized KZG proof generation, while setup-specific point data belongs to the commitment layer (constantine/math/matrix/toeplitz.nim#L187-L235, constantine/math/matrix/toeplitz.nim#L268-L362).
References: constantine/…/toeplitz.nim• L23-38 constantine/…/toeplitz.nim• L92-143 constantine/…/toeplitz.nim• L187-235 constantine/…/toeplitz.nim• L268-362 constantine/…/toeplitz.nim• L370-439
Multilinear extensions
A multilinear extension is the unique polynomial that agrees with a function on every point of a Boolean cube and is linear in each variable. The library stores the function’s field values and evaluates this extension at field coordinates, which gives interactive proof systems a way to query a discrete table at a general point (constantine/boolean_hypercube/multilinear_extensions.nim#L17-L42).
Boolean-cube evaluation
MultilinearExtension expects 2^s base evaluations for s variables. Its public evaluator supports both big-endian and little-endian interpretations of the Boolean index. The reference evaluator provides a simple correctness model, while the normal evaluator reuses intermediate values to reach linear work in the number of base evaluations (constantine/boolean_hypercube/multilinear_extensions.nim#L52-L63, constantine/boolean_hypercube/multilinear_extensions.nim#L289-L323).
The endian choice is part of the data contract. It determines which base evaluation corresponds to each bit string and therefore changes the resulting extension when the same table is read in the other order.
References: constantine/…/multilinear_extensions.nim• L17-42 constantine/…/multilinear_extensions.nim• L52-63 constantine/…/multilinear_extensions.nim• L67-173 constantine/…/multilinear_extensions.nim• L178-284 constantine/…/multilinear_extensions.nim• L289-323
Interactive proof primitives
The proof layer turns an evaluation claim into a relation that a verifier can check from public data. The repository includes an inner-product argument for evaluation-form polynomials and a transcript abstraction that supplies repeatable Fiat–Shamir challenges. It does not define a general sum-check or complete proving language around these primitives.
Inner-product arguments
The Verkle-style IPA proves that a committed evaluation vector has a claimed value at an opening point. The prover and verifier use a polynomial evaluation vector, a fixed evaluation domain, curve generators, the commitment, and the claimed point and value. Each round sends two curve points and reduces the working vectors by half, so the proof has logarithmic round count (constantine/commitments/eth_verkle_ipa.nim#L124-L153, constantine/commitments/eth_verkle_ipa.nim#L182-L267).
The verifier rebuilds the same challenges and checks one final multi-scalar relation. The commitment and generator material are supplied by the commitment setup; the IPA layer focuses on the proof relation and its evaluation claim (constantine/commitments/eth_verkle_ipa.nim#L326-L438).
References: constantine/…/eth_verkle_ipa.nim• L124-153 constantine/…/eth_verkle_ipa.nim• L182-267 constantine/…/eth_verkle_ipa.nim• L326-438
Fiat–Shamir transcripts
EthVerkleTranscript replaces live verifier messages with a shared hash state. Both sides absorb the same labeled public values and proof points, then squeeze field challenges in the same order. Domain separators keep protocol stages and labels distinct (constantine/commitments/eth_verkle_transcripts.nim#L18-L24, constantine/commitments/eth_verkle_transcripts.nim#L54-L109).
The transcript is part of the proof protocol, not only a utility for hashing. A change to a label, absorbed value, encoding, or order changes every later challenge and makes otherwise valid proofs incompatible. The IPA uses this sequence for its initial scaling challenge and each recursive round (constantine/commitments/eth_verkle_ipa.nim#L184-L232, constantine/commitments/eth_verkle_ipa.nim#L378-L399).
References: constantine/…/eth_verkle_transcripts.nim• L24-49 constantine/…/eth_verkle_transcripts.nim• L54-109 constantine/…/eth_verkle_ipa.nim• L184-232 constantine/…/eth_verkle_ipa.nim• L378-399
Constraint-system input
The R1CS parser is an input primitive for proof systems that start from a Circom Rank-1 Constraint System. It reads the field description, wire counts, sparse linear combinations, constraints, and wire-to-label data from the binary format. It preserves the constraint relation A .* B = C as structured data for a later proving layer (constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L27-L48, constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L77-L119).
This parser does not perform the proof. It also leaves custom-gate section parsing unfinished, so consumers must not treat a successfully opened file as proof-ready without checking which sections the input uses (constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L194-L196, constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L224-L256).
References: constantine/…/r1cs_circom_parser.nim• L27-48 constantine/…/r1cs_circom_parser.nim• L77-119 constantine/…/r1cs_circom_parser.nim• L127-185 constantine/…/r1cs_circom_parser.nim• L194-196 constantine/…/r1cs_circom_parser.nim• L224-256
Change checklist
When these files or sections are changed, remember to consider these:
- Keep coefficient order, evaluation order, bit-reversal order, and endian choice consistent across polynomial transforms, interpolation, commitments, and proof inputs.
- Keep FFT descriptor capacity and field roots of unity aligned with every transform and coset size that a caller can request.
- Keep generic-domain points distinct and keep their vanishing-polynomial derivative weights matched to the same domain.
- Keep Toeplitz circulant layout, layer count, and curve-point layout aligned with the setup-specific fast proof path.
- Keep multilinear base-table indexing aligned with the selected endian mode. A table with the right length can still represent the wrong function.
- Treat transcript labels, absorbed values, encodings, and order as a cross-implementation protocol contract.
- Keep R1CS section support aligned with the accepted circuit files. Custom-gate sections need a separate supported path before they can enter proving.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| FFT input and output lengths differ, the length is not a power of two, or the length exceeds field 2-adicity | The transform returns an error status and no valid polynomial view is produced | Check FFTStatus and the descriptor order before using the result (constantine/math/polynomials/fft_common.nim#L33-L48) |
| Coefficient, evaluation, or bit-reversed data is passed to an API with a different ordering contract | Interpolation or proof values are wrong even though the field elements are valid | Keep the representation and PolyOrdering contract with the data (constantine/math/polynomials/polynomials.nim#L32-L69) |
| A generic evaluation domain has duplicate points or stale derivative weights | Off-domain evaluation and Lagrange basis values are invalid | Build domain metadata from one fixed set of distinct points (constantine/math/polynomials/polynomials.nim#L232-L242, constantine/math/polynomials/polynomials.nim#L630-L648) |
| Toeplitz accumulation is incomplete or its output, spectrum bank, or layer sizes do not match | The operation returns Toeplitz_MismatchedSizes or cannot produce the requested proof data | Complete each layer before finish and validate the declared dimensions (constantine/math/matrix/toeplitz.nim#L268-L329) |
A multilinear table does not contain 2^num_vars values or coordinates use the wrong endian convention | Construction or evaluation fails in debug mode, or the extension represents another table | Validate table size and carry the endian choice with the query (constantine/boolean_hypercube/multilinear_extensions.nim#L52-L63, constantine/boolean_hypercube/multilinear_extensions.nim#L289-L323) |
| Prover and verifier use different transcript inputs or challenge order | The verifier derives different challenges and rejects the proof | Use the same domain separators, labels, encodings, and absorb sequence (constantine/commitments/eth_verkle_transcripts.nim#L60-L109, constantine/commitments/eth_verkle_ipa.nim#L378-L399) |
| An R1CS file uses unsupported custom-gate sections or malformed section sizes | Parsing fails or the result cannot represent the complete circuit | Check supported section kinds and the parser’s success assertions before proving (constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L194-L196, constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim#L224-L256) |
Key files
| File | Why to read it |
|---|---|
constantine/math/polynomials/polynomials.nim | Defines coefficient and evaluation forms, domains, interpolation, vanishing polynomials, and core polynomial operations. |
constantine/math/polynomials/fft_fields.nim | Defines field FFT descriptors, transform ordering, inverse transforms, and coset transforms. |
constantine/math/polynomials/polynomials_parallel.nim | Shows how polynomial evaluation keeps the serial contract while using parallel execution. |
constantine/math/matrix/toeplitz.nim | Connects structured matrix products with FFTs and curve multi-scalar multiplication for amortized proof work. |
constantine/math/matrix/transpose.nim | Defines the reusable matrix layout conversion used by data-oriented consumers. |
constantine/boolean_hypercube/multilinear_extensions.nim | Defines Boolean-cube tables and big-endian or little-endian multilinear extension evaluation. |
constantine/commitments/eth_verkle_ipa.nim | Defines the evaluation-opening inner-product proof and its verifier relation. |
constantine/commitments/eth_verkle_transcripts.nim | Defines the labeled absorb and challenge contract used by the IPA. |
constantine/proof_systems/constraint_systems/r1cs_circom_parser.nim | Defines the R1CS circuit input boundary and supported binary sections. |
tests/interactive_proofs/t_multilinear_extensions.nim | Demonstrates and cross-checks multilinear extension evaluation in both endian modes. |
tests/math_matrix/t_toeplitz.nim | Compares structured Toeplitz multiplication with a direct reference and checks failure statuses. |