# Four papers on lattices: a Lean 4 formalization This folder holds four papers on lattice problems and lattice-based cryptography, and a Lean 4 formalization of their results. The results were discovered by an internal research Claude model. The formalization was written by AI models. Research artifact. Not maintained and not accepting contributions. ## The papers | Paper | Title | Start at | Main statements | Further statements | |---|---|---|---|---| | 1 | [Galactic quasi-polynomial quantum algorithms for integral and module lattices](papers/01-quasi-polynomial-quantum-algorithms.pdf) | [`P01.lean`](PaperDefs/P01.lean) | 81 | 104 | | 2 | [Approximate search SVP reduces to SIS and SIVP and, quantumly, to LWE and GapSVP](papers/02-search-svp-to-sis-and-lwe.pdf) | [`P02.lean`](PaperDefs/P02.lean) | 24 | 35 | | 3 | [A converse of the dual attack, and a quantum equivalence of SIVP and LWE at small noise rates](papers/03-converse-of-the-dual-attack.pdf) | [`P03.lean`](PaperDefs/P03.lean) | 19 | 35 | | 4 | [Public-key encryption from GapSVP within Õ(n), classically: an adaptive reduction to decision LWE in dimension kn with exponential modulus](papers/04-pke-from-gapsvp-classical.pdf) | [`P04.lean`](PaperDefs/P04.lean) | 8 | 16 | ## What is formalized The main theorems are stated in [`PaperDefs/`](PaperDefs/), under their printed numbers. They assume no conjecture and no published theorem: the cited results that the proofs use are formalized as well, with their proofs. Algorithms are programs of a quantum word RAM, defined in about 1,000 lines in [`CryptoDefs/`](CryptoDefs/), and time is the number of its steps. | What | Stated in | Checked by | |---|---|---| | The main theorems: 132 statements | `PaperDefs/` | Comparator | | Intermediate theorems, remarks and detailed forms: 190 statements | `PaperDetails/` | Comparator | | The machine defines the standard P, BPP, PSPACE and BQP; simulations, oracles, resources: 63 theorems | `Challenge/Machine.lean` | Comparator | | The papers' lemmas, and that explicit programs execute the printed algorithms | `proof/QLStatement/`, `proof/QL/` | `lake build` | A good place to start is [`PaperDefs/P01/Cases.lean`](PaperDefs/P01/Cases.lean), which states eight results on paper 1 in a few lines each. For example, one quantum program solves search Module-LWE in quasi-polynomial time, for every fixed rank, all large degrees, moduli above a polynomial bound and almost all square matrices: ```lean def ModuleLWETheorem : Prop := ∃ program : QuantumProgram, ∃ c : ℕ, ∀ rank ≥ (1 : ℕ), ∀ᶠ n : ℕ in largePowersOfTwo, ∀ noise ≥ 1, ∀ q ∈ Set.Icc (11 * rank * noise ^ 2 * n) (2 ^ n), ForAllButFraction (2 ^ (-(n : ℝ) / (240 * rank))) fun A : Fin rank → Fin rank → Fin n → Fin q => program.SolvesEveryInstance (moduleLWE A noise) (told := [n, rank, rank]) (time := 2 ^ (c * rank ^ 8 * n.log2 ^ 2)) ``` The results are asymptotic, and the algorithms are not practical for the parameter sets of ML-KEM and ML-DSA. ## Not formalized, or formalized weaker than printed Running times count steps of the machine, so some bounds differ from the printed ones by logarithmic factors. That a program executes a printed algorithm means that it records the printed values and makes the printed calls and random choices, in order. Where a paper cites a subroutine without giving it, the programs use one of ours. Two remarks, one heuristic and one with open questions, are not formalized, and Remark 7.17 of paper 4 is conditional on an open question, as in the paper. [`docs/departures.md`](docs/departures.md) lists the differences between the Lean statements and the text. ## How to check it With [elan](https://github.com/leanprover/elan) installed, in this folder: ```sh lake exe cache get lake build lake env lean scripts/PrintAxioms.lean ``` The build takes a little over an hour on 12 cores, with 12 GB of memory and 21 GB of disk. Only `Challenge/` contains `sorry`. The last command prints the axioms behind each compared theorem: `propext`, `Classical.choice` and `Quot.sound`. The fuller check is [Comparator](https://github.com/leanprover/comparator) (`bash ../.github/scripts/comparator-check.sh`, on Linux). It verifies that `Solution/` proves exactly the statements of `Challenge/`, from these three axioms, and replays the proofs in Lean's kernel and in the independent kernel `nanoda`. Its three configurations take about 60, 40 and 5 minutes and up to 14 GB of memory. **What a reader has to trust:** the statements and the definitions that they use (`CryptoDefs/`, `PaperDefs/`, `PaperDetails/`, `ConsistencyDefs/`, Mathlib), `Challenge/`, the configuration files, and the checkers; for the last row of the table above, also the statements in `proof/`. That the statements say what the papers say is for the reader to judge; AI readers have compared them with the text. **Security.** Building downloads the Lean toolchain, Mathlib and Mathlib's compiled files, and compiling Lean code runs its tactics and macros with the rights of your user. ## How the files are laid out | Path | What it holds | |---|---| | `papers/` | the four papers | | `CryptoDefs/` | the machine, resources and problems | | `ConsistencyDefs/` | Turing machines, circuits and classes, against which `Challenge/Machine.lean` holds the machine | | `PaperDefs/` | the main theorems | | `PaperDetails/` | the further statements | | `Challenge/`, `comparator-*.json` | one theorem for each statement, with `sorry` in place of its proof; which theorems Comparator compares | | `Solution/` | one file for each file of `Challenge/`, which imports the proofs and adds nothing | | `proof/Crypto/` | the library on the machine: a language, its compiler, circuits | | `proof/CryptoConsistency/` | the proofs of the theorems on the machine; end theorems in `Theorems/` | | `proof/QLStatement/` | the full statements, with the printed algorithms | | `proof/QL/` | the proofs: mathematics (`Tactic/` to `Lattice/`), computation (`Tree/` to `Quantum/`), `Algo/`, `Crypto/`, `Cited/`, one folder for each paper; `Papers/` has nearly all compared theorems, `Named/` the theorems on named programs | | `proof/CryptoMeta/`, `proof/QLMeta/` | tactics and programs on terms that import Lean alone; Lake compiles them to native code (untrusted) | | `docs/departures.md` | where the Lean statements differ from the papers | | `docs/INDEX.md` | the papers item by item | | `scripts/PrintAxioms.lean` | prints the axioms behind the compared theorems | `QL.P04.Corollary_1_4a` is Corollary 1.4 (a) of paper 4, and `QL.P04.corollary_1_4a` says that it holds. [`docs/INDEX.md`](docs/INDEX.md) leads from a printed number to the Lean declarations. [`proof/QLStatement/README.md`](proof/QLStatement/README.md) explains the statements on explicit programs, the marks in doc comments and the keys of cited works. In the documents, a path that begins with `QL/`, `QLStatement/`, `Crypto/` or `CryptoConsistency/` is a file of `proof/`. ## License Apache 2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE).