Formally Verified Arguments of Knowledge in Lean

5 Supporting Theories

5.1 Polynomials

This section contains facts about polynomials that are used in the rest of the library, and also definitions for computable representations of polynomials.

Definition 261 Multilinear Extension
✓
#

For a commutative ring \(R\) and a function \(v:\{ 0,1\} ^{\sigma }\to R\), the multilinear extension of \(v\) is \(\widetilde{v}:=\sum _{x\in \{ 0,1\} ^{\sigma }}\mathsf{eq}(x,X)\cdot v(x)\), where \(\mathsf{eq}(x,X)=\prod _{i}\bigl((1-x_i)(1-X_i)+x_iX_i\bigr)\).

Theorem 262 Multilinear Extension is Unique
✓

Let \(R\) be a commutative ring and \(v:\{ 0,1\} ^n\to R\). If \(p\in R[X_1,\ldots ,X_n]\) has degree at most one in each variable and \(p(x)=v(x)\) for every \(x\in \{ 0,1\} ^n\), then \(p=\widetilde{v}\).

We note that the Schwartz-Zippel Lemma is already in Mathlib.

Theorem 263 Schwartz-Zippel Lemma
✓
#

Let \(R\) be an integral domain, let \(p\in R[X_1,\ldots ,X_n]\) be nonzero, and let \(S_1,\ldots ,S_n\subseteq R\) be finite sets. Then

\[ \frac{\bigl|\{ x\in S_1\times \cdots \times S_n : p(x)=0\} \bigr|}{\prod _{i}|S_i|} \le \sum _{i=1}^{n}\frac{\deg _{X_i}p}{|S_i|}. \]

Computable univariate and multilinear polynomials come from the CompPoly library. They are represented by arrays of coefficients, or, for multilinear polynomials, dually by their evaluations on the Boolean hypercube.

Definition 264 Computable Univariate Polynomials
✓
#

A computable univariate polynomial is an array of coefficients in canonical form: the last stored coefficient is nonzero whenever the array is nonempty.

Definition 265 Computable Multilinear Polynomials
✓

A computable multilinear polynomial in \(n\) variables is a vector of length \(2^n\), holding either its monomial coefficients or its evaluations on \(\{ 0,1\} ^n\), indexed little-endian.

5.2 Coding Theory

This section contains definitions and theorems about coding theory as they are used in the rest of the library.

Definition 266 Code Distance
✓
#

The distance of a code \(\mathcal{C}\subseteq \Sigma ^{\mathcal{L}}\) is the least Hamming distance between two distinct codewords; it is \(0\) if \(\mathcal{C}\) has fewer than two elements.

Definition 267 Distance from a Code
✓
#

The distance \(\Delta (u,\mathcal{C})\) of a word \(u\) from a code \(\mathcal{C}\) is the least Hamming distance between \(u\) and a codeword, valued in \(\mathbb {N}\cup \{ \infty \} \) (it is \(\infty \) when \(\mathcal{C}\) is empty).

Definition 268 Generator Matrix
✓

A matrix \(G\) generates the linear code spanned by its rows (equivalently, the image of \(v\mapsto vG\)); the column variant takes the image of \(v\mapsto Gv\).

Definition 269 Parity Check Matrix
✓
#

A matrix \(H\) defines the linear code \(\{ c : Hc = 0\} \), the kernel of \(c\mapsto Hc\).

Definition 270 Code
#

A code of length \(\mathcal{L}\) over an alphabet \(\Sigma \) is a set \(\mathcal{C}\subseteq \Sigma ^{\mathcal{L}}\) of words. The formalization uses \(\mathsf{Set}\, (\mathcal{L}\to \Sigma )\) directly and has no separate declaration for it.

Definition 271 Linear Code
✓
#

A linear code of length \(\mathcal{L}\) over \(\mathbb {F}\) is an \(\mathbb {F}\)-submodule of \(\mathbb {F}^{\mathcal{L}}\).

Definition 272 Interleaved Code
✓
#

The \(\kappa \)-fold interleaving of a code \(\mathcal{C}\) is the set of \(\mathcal{L}\times \kappa \) matrices each of whose columns lies in \(\mathcal{C}\).

Definition 273 Reed-Solomon Code
✓
#

For an injective map \(\mathcal{L}\hookrightarrow \mathbb {F}\) and \(d\in \mathbb {N}\), \(\mathrm{RS}[\mathbb {F},\mathcal{L},d]\) is the image of the polynomials of degree less than \(d\) under evaluation on \(\mathcal{L}\).

Definition 274 Smooth Reed-Solomon Code
✓
#

A smooth Reed–Solomon code is a Reed–Solomon code whose evaluation domain is a smooth coset FFT domain: a coset of a multiplicative subgroup of \(\mathbb {F}^\times \) of order \(2^n\).

Definition 275 Constrained Code
✓
#

For a smooth domain \(\mathcal{L}\) of size \(2^n\), \(m\in \mathbb {N}\), a weight polynomial \(\hat{w}\in \mathbb {F}[Z,X_1,\ldots ,X_m]\) and \(\sigma \in \mathbb {F}\), the constrained code \(\mathrm{CRS}[\mathbb {F},\mathcal{L},m,\hat{w},\sigma ]\) consists of the codewords \(f\in \mathrm{RS}[\mathbb {F},\mathcal{L},2^m]\) whose multilinear polynomial \(\hat{f}\) satisfies \(\sum _{b\in \{ 0,1\} ^m}\hat{w}(\hat{f}(b),b)=\sigma \).

Definition 276 Multi-constrained Code
✓
#

The multi-constrained code for weights \(\hat{w}_0,\ldots ,\hat{w}_{t-1}\) and targets \(\sigma _0,\ldots ,\sigma _{t-1}\) consists of the codewords of \(\mathrm{RS}[\mathbb {F},\mathcal{L},2^m]\) that satisfy every one of the \(t\) weight constraints.

Definition 277 Proximity Measure
✓
#

For words \(u,v\), a code \(\mathcal{C}\) and \(d\in \mathbb {N}\), the proximity measure is the number of \(r\in \mathbb {F}\) with \(\Delta (r u+(1-r)v,\mathcal{C})\le d\).

Definition 278 Proximity Gap
✓
#

A code \(\mathcal{C}\) has a proximity gap at distance \(d\) with bound \(b\) if, for all words \(u,v\) whose proximity measure exceeds \(b\), the pair \((u,v)\) is within distance \(d\) of the 2-fold interleaved code of \(\mathcal{C}\).

Definition 279 List Decodability
✓
#

A code \(\mathcal{C}\) is \((r,\ell )\)-list decodable if every word has at most \(\lfloor \ell \rfloor \) codewords within relative Hamming distance \(r\).

Definition 280 List of Close Codewords
✓
#

For a word \(y\) and \(r\in \mathbb {R}\), \(\Lambda (\mathcal{C},y,r)\) is the set of codewords within relative Hamming distance \(r\) of \(y\).

5.2.1 Theorems

Theorem 281 List decoding of Reed–Solomon codes up to the Johnson bound
✓

Let \(\mathcal{L}\) be a nonempty finite domain embedded in a field \(\mathbb {F}\), let \(d{\gt}0\), and let \(\rho =\min \{ d,|\mathcal{L}|\} /|\mathcal{L}|\) be the rate of \(\mathrm{RS}[\mathbb {F},\mathcal{L},d]\). For every real \(\eta {\gt}0\), the code \(\mathrm{RS}[\mathbb {F},\mathcal{L},d]\) is \(\bigl(1-\sqrt{\rho }-\eta ,\ 1/(2\eta \sqrt{\rho })\bigr)\)-list decodable. The field need not be finite, and the bound does not depend on \(|\mathbb {F}|\).

Proof ▶

Two distinct codewords agree in fewer than \(d\) positions, so their agreement is at most \(\min \{ d,|\mathcal{L}|\} =\rho |\mathcal{L}|\). A counting bound for any code whose pairwise agreements are this small gives at most \(1/(2\eta \sqrt{\rho })\) codewords within relative distance \(1-\sqrt{\rho }-\eta \) of any word. This is Theorem 4.3 of  [ 3 ] .

The proximity-gap and mutual correlated agreement results for Reed–Solomon codes are stated where the protocols use them: Theorem 205 for random linear combinations, and Lemma 227 and Theorems 229, 230 and 231 for mutual correlated agreement in the unique-decoding, Johnson and capacity regimes.

5.3 The VCVio Library

This library provides a formal framework for reasoning about computations that make oracle queries. Many cryptographic primitives and interactive protocols use oracles to model (or simulate) external functionality such as random responses, coin flips, or more structured queries. The VCVio library "lifts" these ideas into a setting where both the abstract specification and concrete simulation of oracles may be studied, and their probabilistic behavior analyzed.

The main ingredients of the library are as follows:

Definition 282 Specification of Oracles
✓
#

An oracle specification on an index type \(\iota \) is a map \(\mathsf{spec} : \iota \to \mathsf{Type}\). Each \(t : \iota \) is a possible query, and \(\mathsf{spec}\ t\) is the type of answers to that query. The query type is therefore the index type itself (spec.Domain is \(\iota \)), and the answer type depends on the query (spec.Range t is \(\mathsf{spec}\ t\)). An oracle specification is the same data as a polynomial functor with positions \(\iota \) and directions \(\mathsf{spec}\ t\). The specification only describes interfaces, not how the oracles behave.

Definition 283 Standard Oracle Specifications
✓
#
  • \(A \to _{\mathsf{o}} B\): oracles that take inputs in \(A\) and answer every query in \(B\).

  • emptySpec, written \([]_{\mathsf{o}}\): no oracles.

  • coinSpec \(= \mathsf{Unit} \to _{\mathsf{o}} \mathsf{Bool}\): a coin-flipping oracle.

  • unifSpec: indexed by \(n \in \mathbb {N}\), the query \(n\) is answered in \(\mathsf{Fin}\ (n+1) = \{ 0, \ldots , n\} \); with uniform answers it samples uniformly from this set.

Specifications combine by disjoint sum \(\mathsf{spec}_1 + \mathsf{spec}_2\).

We often require extra properties of query and answer types, such as decidable equality or finiteness. These are stated as ordinary instance hypotheses on the index type and on spec.Range t (quantified over \(t\)), rather than as bundled classes on the specification.

Definition 284 Oracle Computation
✓
#

An oracle computation OracleComp spec \(\alpha \) is a program that makes queries to the oracles of spec and returns a value of type \(\alpha \). It is the free monad of the polynomial functor of spec, so every computation either

  • returns a value without making any queries (pure), or

  • makes one query \(t\) and continues with a function of the answer in spec.Range t (queryBind).

There is no failure constructor. Computations that may fail are written in OptionT (OracleComp spec). Computations whose only oracle is unifSpec are called probabilistic computations, ProbComp.

Definition 285 Handling Oracle Queries
✓
#

To run oracle computations, we need a way to handle (or implement) the oracle queries. A query implementation QueryImpl spec m maps every query \(t\) to a computation in a monad \(m\) returning an answer in spec.Range t. Depending on the monad, this allows various interpretations of the queries.

Definition 286 Probabilistic Semantics of Oracle Computations
✓
#

A computation denotes a subprobability measure on its outputs, evalDist mx. The missing mass represents failure or nontermination; the output distribution does not add an Option outcome. For oracle computations, the semantics is fixed by choosing a probability measure on the answers to each query. The usual choice is the uniform measure, as for ProbComp. Probabilities of outputs and events are defined from this measure.

Definition 287 Simulating Oracle Queries with Other Oracles
✓
#

Given a query implementation of spec in a monad \(m\), simulateQ runs an oracle computation by substituting the implementation for each query. Taking \(m\) to be a computation with access to other oracles, possibly with state (for example a state monad over OracleComp spec'), simulates one specification by another.

Definition 288 Logging & Caching Oracle Queries
✓

Using the simulation framework, we can add logging and caching behaviors to oracle queries:

  • Logging records all queries made during a computation

  • Caching remembers query responses and reuses them for repeated queries

Logging forwards every query and records it. Caching forwards only cache misses and answers repeated queries from the cache.

Definition 289 Random Oracle
✓
#

A random oracle is implemented as a caching oracle that uses lazy sampling:

  • On first query: generates a uniform random response and caches it

  • On repeated queries: returns the cached response

5.4 The Subfield \(R_q^H \cong \mathbb {F}_{q^k}\) (Hachi Lemma 5)

This section covers Hachi  [ 26 ] §3, Lemma 5: the fixed subring \(R_q^H\) is a field and is isomorphic to \(\mathbb {F}_{q^k}\). The packing map \(\psi \) and the trace formula of Theorem 2 (the rest of §3) are formalized as well.

Throughout, \(d = 2^\alpha \), \(R_q = \mathbb {Z}_q[X]/(X^{d}+1)\) with \(q\) an odd prime, \(k = 2^\kappa \) a divisor of \(d/2\) (i.e. \(2k \mid d\)), and \(H = \langle \sigma _{-1}, \sigma _{4k+1}\rangle \). For the field statement we additionally assume \(q \equiv 5 \pmod8\).

5.4.1 The fixed subring and the packing map

Definition 290 Fixed subring
✓

\(R_q^H := \{ x \in R_q : \sigma _{-1}(x) = x \wedge \sigma _{4k+1}(x) = x\} \), defined as the meet of two eqLocus’s, hence a Subring.

Theorem 291 Cardinality, Eq. 7
✓

Over \(R = \mathbb {Z}_q\) with \(q\) prime and \(2k \mid d\), \(\; |R_q^H| = q^{k}\).

Theorem 292 Packing bijection, Theorem 2
✓

The map \(\psi : (R_q^H)^{d/k} \to R_q\) is a bijection.

The rest of the section establishes the field structure.

5.4.2 Main result

Theorem 293 Lemma 5: field isomorphism
✓

Let \(q\) be prime with \(q \equiv 5 \pmod8\) and \(2 \cdot 2^\kappa \mid 2^\alpha \). Then there is a ring isomorphism

\[ R_q^{H} \; \cong \; \mathbb {F}_{q^{2^\kappa }} \quad \bigl(\texttt{GaloisField } q\ (2^\kappa )\bigr). \]
Proof ▶

By Theorem 297 \(R_q^H\) is a finite field, and by Theorem 291 it has cardinality \(q^{2^\kappa }\). Any finite field of cardinality \(q^{2^\kappa }\) is isomorphic to \(\texttt{GaloisField } q\ (2^\kappa )\) (Lemma 294).

The point of this decomposition is that the cardinality is already known (Theorem 291), so once field-ness is established we get the isomorphism without any finite-field Galois-descent analysis of the \(\sigma _{4k+1}\)-action.

5.4.3 Reduction to “\(R_q^H\) is a field”

The whole difficulty concentrates in field-ness; everything else is generic algebra reused from Mathlib.

Lemma 294 Finite field by cardinality
#

Two finite fields of equal cardinality are isomorphic; in particular a finite field of cardinality \(q^{n}\) is isomorphic to \(\texttt{GaloisField } q\ n\). (Mathlib; GaloisField/FiniteField API.)

Lemma 295 Subring of a domain is a domain

If \(S \le T\) is a subring of an integral domain \(T\), then \(S\) is an integral domain (it inherits NoZeroDivisors; Mathlib).

Lemma 296 Finite domain is a field
#

A finite nontrivial commutative integral domain is a field. (Mathlib; Finite.isField_of_domain / Fintype.fieldOfDomain.)

For \(q\) prime, \(q \equiv 5 \pmod8\), \(2k \mid d\), the ring \(R_q^H\) is a field.

Proof ▶

\(R_q^H \subseteq R_q^{\sigma _{-1}}\) (Lemma 299), and \(R_q^{\sigma _{-1}}\) is a field (Theorem 307). A subring of a field is an integral domain (Lemma 295); \(R_q^H\) is finite (fixedSubring.fintype) and nontrivial, hence a field (Lemma 296).

Definition 298 Conjugation-fixed subring \(R_q^{\sigma _{-1}}\)
✓

\(R_q^{\sigma _{-1}} := \{ x \in R_q : \sigma _{-1}(x) = x\} = \texttt{eqLocus}\ \sigma _{-1}\ \mathrm{id}\).

Lemma 299 \(R_q^H \le R_q^{\sigma _{-1}}\)
✓

\(R_q^H \subseteq R_q^{\sigma _{-1}}\), immediate from the definition of \(R_q^H\) as a meet whose first factor is \(R_q^{\sigma _{-1}}\).

5.4.4 The crux: \(R_q^{\sigma _{-1}}\) is a field

This is the only genuinely new mathematics. The route is the two-factor decomposition of \(R_q\) that is special to \(q \equiv 5 \pmod8\).

Lemma 300 Order of \(q\) modulo the conductor
✓

For \(q \equiv 5 \pmod8\) and \(\alpha \ge 1\), the multiplicative order of \(q\) in \((\mathbb {Z}/2^{\alpha +1})^\times \) is \(2^{\alpha -1}\).

Proof ▶

\((\mathbb {Z}/2^{\alpha +1})^\times \cong \langle -1\rangle \times \langle 5\rangle \) with \(|\langle 5\rangle | = 2^{\alpha -1}\). Writing \(q \equiv (-1)^a 5^b\), the congruence \(q \equiv 5 \pmod8\) forces \(a = 0\) and \(b\) odd; since \(b\) is odd it is a unit mod \(2^{\alpha -1}\), so \(q\) generates \(\langle 5\rangle \) and \(\operatorname {ord}(q) = 2^{\alpha -1}\). The \(2\)-adic computation is the same lifting-the-exponent toolkit already used in Galois/Order.lean (two_pow_dvd_four_pow_sub_one_iff).

Lemma 301 Two irreducible factors
✓

Over \(\mathbb {F}_q\) with \(q \equiv 5 \pmod8\), the polynomial \(X^{2^\alpha }+1 = \Phi _{2^{\alpha +1}}(X)\) factors as a product of exactly two distinct monic irreducible polynomials, each of degree \(2^{\alpha -1} = d/2\).

Proof ▶

\(X^{2^\alpha }+1\) is the \(2^{\alpha +1}\)-th cyclotomic polynomial. Since \(q \nmid 2^{\alpha +1}\) it is separable over \(\mathbb {F}_q\), and over a finite field every irreducible factor of \(\Phi _n\) has degree \(\operatorname {ord}_n(q)\); the number of factors is \(\varphi (n)/\operatorname {ord}_n(q)\). With \(n = 2^{\alpha +1}\), \(\varphi (n) = 2^\alpha \) and \(\operatorname {ord}_n(q) = 2^{\alpha -1}\) (Lemma 300), giving exactly \(2\) factors of degree \(2^{\alpha -1}\). Formalized directly from Mathlib’s Polynomial.normalizedFactors_cyclotomic_card (factor count \(= \varphi (n)/\operatorname {ord}\)) together with Nat.totient_prime_pow_succ.

Lemma 302 Factor existence
✓

For \(q \equiv 5 \pmod8\), \(X^{2^\alpha }+1 = p_1 \cdot p_2\) over \(\mathbb {F}_q\) with \(p_1, p_2\) coprime and irreducible. (Extracted from the two normalized factors; coprimality of the distinct monic irreducibles via Irreducible.coprime_iff_not_dvd.)

5.4.5 The swap: \(\sigma _{-1}\) and polynomial reversal

The proof rests on one fact: \(\sigma _{-1}\) interchanges the two factors. Rather than build the explicit CRT product \(K \times K\), we work directly in \(S := \mathbb {F}_q[X]/(X^{2^\alpha }+1)\) via a reverse identity and a divisibility argument.

Lemma 303 The reverse identity
✓

In \(S\), with \(\mathrm{mk}\) the quotient map and \(\sigma _{-1} = \texttt{galoisAutₛ}\) of exponent \(2^{\alpha +1}-1\),

\[ \mathrm{mk}(p^{\mathrm{rev}}) \; =\; \sigma _{-1}(\mathrm{mk}\, p)\cdot (\mathrm{mk}\, X)^{\deg p}. \]

Since \(\mathrm{mk}\, X\) is a unit, \(\sigma _{-1}\) carries the ideal \((\mathrm{mk}\, p)\) onto \((\mathrm{mk}\, p^{\mathrm{rev}})\). Proved from Mathlib’s Polynomial.eval₂_reverse_mul_pow at the point \((\mathrm{mk}\, X)^{-1} = (\mathrm{mk}\, X)^{c}\).

Lemma 304 No self-reciprocal factor
✓

For \(q \equiv 5 \pmod8\), reversal swaps the two factors: if \(X^{2^\alpha }+1 = p_1 p_2\) with \(p_1, p_2\) irreducible, then \(p_1^{\mathrm{rev}}\) is associated to \(p_2\). This is the step carrying the \(-1 \notin \langle q\rangle \) root-orbit content. The root set of \(p_1\) is a single Frobenius orbit \(=\) a coset of \(\langle q\rangle \); were \(p_1^{\mathrm{rev}} \sim p_1\) it would be closed under \(\zeta \mapsto \zeta ^{-1}\), i.e. \(-1 \in \langle q\rangle \), contradicting Lemma 305; as reversal permutes the two factors of the self-reciprocal \(X^{2^\alpha }+1\), it sends \(p_1\) to \(p_2\).

Lemma 305 \(-1 \notin \langle q\rangle \)
✓

For \(q \equiv 5 \pmod8\) and \(\alpha \ge 1\), no power of \(q\) equals \(-1\) in \(\mathbb {Z}/2^{\alpha +1}\) (every power is \(\equiv 1 \pmod4\), while \(-1 \equiv 3\)).

5.4.6 Assembling the field and the isomorphism

In \(S = \mathbb {F}_q[X]/(X^{2^\alpha }+1)\) every nonzero \(\sigma _{-1}\)-fixed element is a unit.

Proof ▶

Write the element as \(\mathrm{mk}\, g\). If it is not a unit then \(g\) is not coprime to \(X^{2^\alpha }+1 = p_1 p_2\), so (WLOG) \(p_1 \mid g\). The reverse identity (Lemma 303) together with \(p_1^{\mathrm{rev}} \sim p_2\) (Lemma 304) gives \(\mathrm{mk}\, p_2 \mid \sigma _{-1}(\mathrm{mk}\, p_1) \mid \sigma _{-1}(\mathrm{mk}\, g) = \mathrm{mk}\, g\), hence \(p_2 \mid g\). With \(p_1 \mid g\) and \(p_1, p_2\) coprime, \(X^{2^\alpha }+1 \mid g\), so \(\mathrm{mk}\, g = 0\), a contradiction.

Theorem 307 \(R_q^{\sigma _{-1}}\) is a field
✓

For \(q\) prime with \(q \equiv 5 \pmod8\) and \(\alpha \ge 1\), \(R_q^{\sigma _{-1}}\) is a field.

Proof ▶

Transport along \(R_q \cong S\) (Rq.equivQuotient), under which \(\sigma _{-1}\) becomes \(\texttt{galoisAutₛ}\) (galoisAut_toQuotient). A nonzero \(\sigma _{-1}\)-fixed element of \(R_q^{\sigma _{-1}}\) maps to a nonzero fixed element of \(S\), a unit by Theorem 306; its inverse is again \(\sigma _{-1}\)-fixed (apply \(\sigma _{-1}\) to \(a a^{-1} = 1\) and cancel the unit), so it lies in \(R_q^{\sigma _{-1}}\).

The proof works directly in \(S\) via the reverse identity and a divisibility argument, rather than constructing the explicit CRT product \(R_q \cong K\times K\).