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 187 Multilinear Extension
#
Theorem 188 Multilinear Extension is Unique
#

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

Theorem 189 Schwartz-Zippel Lemma
#

We also define the type of computable univariate & multilinear polynomials using arrays to represent their coefficients (or dually, their evaluations at given points).

Definition 190 Computable Univariate Polynomials
#
Definition 191 Computable Multilinear Polynomials
#

5.2 Coding Theory

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

Definition 192 Code Distance
#
Definition 193 Distance from a Code
#
Definition 194 Generator Matrix
Definition 195 Parity Check Matrix
#
Definition 196 Code
#
Definition 197 Linear Code
#
Definition 198 Interleaved Code
#
Definition 199 Reed-Solomon Code
#
Definition 200 Smooth Reed-Solomon Code
#
Definition 201 Constrained Code
#
Definition 202 Multi-constrained Code
#
Definition 203 Proximity Measure
#
Definition 204 Proximity Gap
#
Definition 205 List Decodability
#
Definition 206 List of Close Codewords
#

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 207 Specification of Oracles
#

An oracle specification describes a collection of available oracles, each with its own input and output types. Formally, it’s given by an indexed family where each oracle is specified by:

  • A domain type (what inputs it accepts)

  • A range type (what outputs it can produce)

The indexing allows for potentially infinite collections of oracles, and the specification itself is agnostic to how the oracles actually behave - it just describes their interfaces.

Some examples of oracle specifications (and their intended behavior) are as follows:

  • emptySpec: Represents an empty set of oracles

  • singletonSpec: Represents a single oracle available on a singleton index

  • coinSpec: A coin flipping oracle that produces a random Boolean value

  • unifSpec: A family of oracles that for every natural number \(n \in \mathbb {N}\) chooses uniformly from the set \(\{ 0, \ldots , n\} \).

We often require extra properties on the domains and ranges of oracles. For example, we may require that the domains and ranges come equipped with decidable equality or finiteness properties .

Definition 208 Oracle Computation
#

An oracle computation represents a program that can make oracle queries. It can:

  • Return a pure value without making any queries (via pure)

  • Make an oracle query and continue with the response (via queryBind)

  • Signal failure (via failure)

The formal implementation uses a free monad on the inductive type of oracle queries wrapped in an option monad transformer (i.e. OptionT(FreeMonad(OracleQuery spec))).

Definition 209 Handling Oracle Queries
#

To actually run oracle computations, we need a way to handle (or implement) the oracle queries. An oracle implementation consists a mapping from oracle queries to values in another monad. Depending on the monad, this may allow for various interpretations of the oracle queries.

Definition 210 Probabilistic Semantics of Oracle Computations
#

We can view oracle computations as probabilistic programs by considering what happens when oracles respond uniformly at random. This gives rise to a probability distribution over possible outputs (including the possibility of failure). The semantics maps each oracle query to a uniform distribution over its possible responses.

Once we have mapped an oracle computation to a probability distribution, we can define various associated probabilities, such as the probability of failure, or the probability of the output satisfying a given predicate (assuming it does not fail).

Definition 211 Simulating Oracle Queries with Other Oracles
#

We can simulate complex oracles using simpler ones by providing a translation mechanism. A simulation oracle specifies how to implement queries in one specification using computations in another specification, possibly maintaining additional state information during the simulation.

Definition 212 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

These are implemented as special cases of simulation oracles.

Definition 213 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 is a blueprint for the one missing piece of Hachi  [ 13 ] §3, Lemma 5: that 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 already formalized; what remains is to upgrade \(R_q^H\) from “a Subring of cardinality \(q^k\)” to “a field \(\cong \mathbb {F}_{q^k}\)”.

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 What already exists

Definition 214 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 215 Cardinality, Eq. 7

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

Theorem 216 Packing bijection, Theorem 2

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

These two are proven with no sorry. The blueprint below adds the field structure on top.

5.4.2 Target

Theorem 217 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 221 \(R_q^H\) is a finite field, and by Theorem 215 it has cardinality \(q^{2^\kappa }\). Any finite field of cardinality \(q^{2^\kappa }\) is isomorphic to \(\texttt{GaloisField } q\ (2^\kappa )\) (Lemma 218).

The point of this decomposition is that the cardinality is already known (Theorem 215), 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 218 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 219 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 220 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 223), and \(R_q^{\sigma _{-1}}\) is a field (Theorem 231). A subring of a field is an integral domain (Lemma 219); \(R_q^H\) is finite (fixedSubring.fintype) and nontrivial, hence a field (Lemma 220).

Definition 222 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 223 \(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 224 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 225 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 224), 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 226 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 (Phase 4): \(\sigma _{-1}\) and polynomial reversal

The proof is gated by 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 227 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 228 No self-reciprocal factor

For \(q \equiv 5 \pmod8\), reversal swaps the two factors: if \(X^{2^\alpha }+1 = p_1 p_2\) then \(p_1^{\mathrm{rev}}\) is associated to \(p_2\). (Left as sorry; carries the entire \(-1 \notin \langle q\rangle \) 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 229; as reversal permutes the two factors of the self-reciprocal \(X^{2^\alpha }+1\), it sends \(p_1\) to \(p_2\).

Lemma 229 \(-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 Phase 5: 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 227) together with \(p_1^{\mathrm{rev}} \sim p_2\) (Lemma 228) 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\) — contradiction.

Theorem 231 \(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 230; 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}}\).

5.4.7 Status and dependency summary

Everything below is formalized and compiles, with the single exception of 228, which is left as sorry and carries the entire \(-1 \notin \langle q\rangle \) content of the swap.

  • Reused, done: 214, 215, 216, the fintype instance, the LTE order toolkit in Galois/Order.lean, and IsCyclotomic (which already gives \(X^{2^\alpha }+1 = \Phi _{2^{\alpha +1}}\) and, via Rq.equivQuotient, lands in the Mathlib quotient \(S\)).

  • Phase 0 — glue: 222, 223; the assembly 221 (subring-of-field domain \(\Rightarrow \) finite domain \(\Rightarrow \) field) and 217 (FiniteField.ringEquivOfCardEq).

  • Phase 1 — number theory: 224 (via ZMod.orderOf_one_add_four_mul), 229.

  • Phase 2 — factorization: 225 (count via normalizedFactors_cyclotomic_card), 226.

  • Phase 4 — the swap: 227 (the reverse identity, via eval₂_reverse_mul_pow) and \(\boxed {\ref{lem:no_selfReciprocal}\ (\texttt{sorry})}\).

  • Phase 5 — payoff: 230, 231.

Files. Subfield/Factorization.lean (Phases 1–2, importing Galois/Order.lean) and Subfield/Field.lean (Phases 4–5 and the Phase 0/glue assembly); the \(\sigma _{-1}\)-fixed subring helper 222 sits in Galois/FixedSubring.lean. The implementation 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\) (which is therefore not needed). The sole remaining sorry is 228.