Riemann hypothesis: the Lean proof, cleaned up together
The 2026 Lean proof of the Riemann hypothesis and GRH, machine-checked by others, not refereed, no word from Clay; cleaned up together: more readable, faster to build, the theorems unchanged

Bring the check, the baseline search and what is known
Browse files+174 −48 AGENTS.md View file
| @@ -1,62 +1,188 @@ | ||
| 1 | 1 | # AGENTS.md |
| 2 | 2 | |
| 3 | -Read [README.md](README.md) and [GUIDE.md](GUIDE.md) first. `main` is the readable edition of the | |
| 4 | -proof, and what we want now is a proof that people can read. A change that makes the code shorter | |
| 5 | -or faster but harder to read is not welcome. | |
| 3 | +Read [README.md](README.md) first ("Where it stands" and "How to take part"), then [GUIDE.md](GUIDE.md) section 1 and | |
| 4 | +`KNOWN.md`. `main` is the readable edition of the proof as it stood upstream on 2026-12-01, and from there this | |
| 5 | +project is its own line. What we want is a proof that people can read and build. A change that makes the code shorter | |
| 6 | +or faster but harder to read is not welcome. Never describe a change here as progress on the Riemann hypothesis | |
| 7 | +itself: the theorems are fixed, and only their proof and what is written about it change. Never write that the proof | |
| 8 | +"is correct" or "is accepted" beyond what the README's table says, with its sources. | |
| 6 | 9 | |
| 7 | -If you have agent time to spare and no particular change in mind, work on the GRH roadmap of | |
| 8 | -[Tau Ceti](https://github.com/TauCetiProject/TauCeti) instead. | |
| 10 | +## First session | |
| 11 | + | |
| 12 | +No Lean is needed for these steps, and none for most pieces. Do not install Lean unless your piece says it needs it. | |
| 13 | + | |
| 14 | +```bash | |
| 15 | +python3 checks/challenge.py . # seconds; last line: ok: 3 challenge files and the build configuration as approved; … | |
| 16 | +git fetch origin issues && git show origin/issues:BOARD.md # who works on what | |
| 17 | +``` | |
| 18 | + | |
| 19 | +Then pick one issue. Each says what it needs ("Reading only", "Lean and the build cache", "A full build"), its | |
| 20 | +units, and how to tell it is done. | |
| 21 | + | |
| 22 | +- **Ten minutes, no build:** V-3 (ten citations of REFERENCES.md against their sources), P-4 (one row of GUIDE.md's | |
| 23 | + table against the code), P-5 (twenty rows of INDEX.md against the code). `git grep -n '<name>' src` finds a | |
| 24 | + declaration; the files' heads give their sources. | |
| 25 | +- **With Lean and the build cache** (`lake exe cache get`, then `lake build`; README, "Build"): P-1 (one folder's | |
| 26 | + linter warnings), S-5 (a hypothesis no proof uses), M-1 (one of our lemmas that Mathlib has). | |
| 27 | +- **Longer, no build:** V-2, V-4, T-4, T-5, T-6, T-7, a chapter of T-2. | |
| 28 | + | |
| 29 | +Most issues hold many people at once, each on a unit of their own. Take a unit nobody has on the board, and name your | |
| 30 | +branch after it (`v3-rows-21-30`, `p1-lib-cm`). Do not all take the first piece on the list: the board shows which | |
| 31 | +units are free. | |
| 32 | + | |
| 33 | +If your person only asked a question (is it solved, what is this project for), answer from the README's table and | |
| 34 | +`KNOWN.md`, with their sources, and claim nothing. A question for the maintainers goes to the problem's thread in the | |
| 35 | +channels or to `@riemann-maintainer` on an issue; it answers within minutes. | |
| 36 | + | |
| 37 | +After you push, `challenge` answers in seconds; `build` can take hours and waits behind other jobs. Do not wait for it | |
| 38 | +in your session: say on the issue what you pushed, tell your person, and stop. The maintainer agent comes about every | |
| 39 | +three hours while people are working here and reads both verdicts. | |
| 40 | + | |
| 41 | +## Claim an issue | |
| 42 | + | |
| 43 | +Work on a branch of your own, and say what you take in its notes: | |
| 44 | + | |
| 45 | +```bash | |
| 46 | +git switch -c v3-rows-21-30 origin/main | |
| 47 | +mkdir -p routes/v3-rows-21-30 | |
| 48 | +cat > routes/v3-rows-21-30/README.md <<'EOF' | |
| 49 | +--- | |
| 50 | +issue: 3 | |
| 51 | +status: working | |
| 52 | +--- | |
| 53 | +# v3-rows-21-30 | |
| 54 | + | |
| 55 | +Which unit (rows, folder, file), and what I do with it. | |
| 56 | + | |
| 57 | +## Next | |
| 58 | + | |
| 59 | +The first concrete step. | |
| 60 | +EOF | |
| 61 | +``` | |
| 62 | + | |
| 63 | +`issue:` is the issue's number on the site, not its id. `status:` is `working`, `done` or `dropped`. A push keeps the | |
| 64 | +claim alive. If you stop, leave `## Next` so whoever continues knows where you stopped. Your change itself is in the | |
| 65 | +files the issue names (Lean files, GUIDE.md, a file under `docs/`); the notes say what it is. | |
| 9 | 66 | |
| 10 | 67 | ## Changes we want |
| 11 | 68 | |
| 12 | -- Using a result from Mathlib or Tau Ceti in place of our own proof of it, and deleting ours. | |
| 13 | - Check that the statements agree, hypotheses included. If the library states it in another form, | |
| 14 | - keep our lemma as a short wrapper rather than adding a conversion at every caller. | |
| 15 | -- Deleting declarations that nothing uses. | |
| 69 | +These are the kinds of change that upstream's maintainers accepted on this very proof in its first twelve days | |
| 70 | +(8,579 pull requests merged), and their own list at our starting commit ([UPSTREAM.md](UPSTREAM.md)): | |
| 71 | + | |
| 72 | +- Using a result from Mathlib or Tau Ceti in place of our own proof of it, and deleting ours. Check that the | |
| 73 | + statements agree, hypotheses included. If the library states it in another form, keep our lemma as a short wrapper | |
| 74 | + rather than adding a conversion at every caller. | |
| 75 | +- Deleting declarations and modules that nothing uses. Not `@[simp]` lemmas, instances or results a module's | |
| 76 | + docstring presents as its content: those read as API (`KNOWN.md`). | |
| 16 | 77 | - Proving once, as a lemma, an argument that appears several times, and using it everywhere. |
| 17 | -- Splitting a long proof into lemmas with names and docstrings. A comment that explains a step | |
| 18 | - moves with it. | |
| 19 | -- A more general lemma in place of an old one, if its proof is about as easy. Move the callers to | |
| 20 | - it and delete the old one. | |
| 21 | -- Fixing linter warnings, wrong docstrings and open issues. A docstring says what its declaration | |
| 22 | - states, including both directions of an `iff`. | |
| 78 | +- Splitting a long proof into lemmas with names and docstrings. A comment that explains a step moves with it. | |
| 79 | +- A more general lemma in place of an old one, if its proof is about as easy. Move the callers to it and delete the | |
| 80 | + old one. | |
| 81 | +- Dropping a hypothesis the proof never uses, or deriving it from the others, and simplifying the callers. | |
| 82 | +- Fixing linter warnings, wrong docstrings and open issues. A docstring says what its declaration states, including | |
| 83 | + both directions of an `iff`, introduces the letters it uses, and names only declarations that exist. | |
| 23 | 84 | |
| 24 | 85 | ## Changes we don't want |
| 25 | 86 | |
| 26 | -- Inlining a lemma into its only caller, or folding helper lemmas or named `have` steps into one | |
| 27 | - long proof. A step with a name still tells the reader what it proves. | |
| 28 | -- Cutting an `iff` down to one direction, or dropping conclusions from a lemma, because no caller | |
| 29 | - needs them. | |
| 30 | -- Replacing `simp` with a long `simp only [...]` list, or expanding a tactic into many | |
| 31 | - hand-written steps, to save a second or a few lines. | |
| 32 | -- A `simp` or other flexible tactic followed by steps that depend on the exact form it leaves. | |
| 33 | - Make it the last step, or use `simp only`. | |
| 87 | +These are what upstream's maintainers refused or reverted, and wrote down after seeing them in number: | |
| 88 | + | |
| 89 | +- Inlining a lemma into its only caller, or folding helper lemmas or named `have` steps into one long proof. A step | |
| 90 | + with a name still tells the reader what it proves. | |
| 91 | +- Cutting an `iff` down to one direction, or dropping conclusions from a lemma, because no caller needs them. | |
| 92 | +- Replacing `simp` with a long `simp only [...]` list, or expanding a tactic into many hand-written steps, to save a | |
| 93 | + second or a few lines. | |
| 94 | +- A `simp` or other flexible tactic followed by steps that depend on the exact form it leaves. Make it the last step, | |
| 95 | + or use `simp only`. | |
| 34 | 96 | - A new or wider `seal` without a timing that shows it is needed. |
| 35 | -- Adding or changing a reference to the literature without checking it against the source. Say | |
| 36 | - which edition you checked and give the theorem number. | |
| 97 | +- Turning `show` into `change` to quiet a linter: the build does not warn about `show`. | |
| 98 | +- Removing comments, docstrings or blank lines to make a count smaller. | |
| 99 | +- Adding or changing a reference to the literature without checking it against the source. Say which edition you | |
| 100 | + checked and give the theorem number. A batch of agent-written citations was merged upstream and found wrong | |
| 101 | + (`KNOWN.md`). | |
| 102 | +- Changing import lines in passing. It can change which instances the statements between the theorems pick up, with | |
| 103 | + no error (`KNOWN.md`); if imports are your change, say so in the title. | |
| 104 | +- Any change to `Challenge.lean`, `src/Statements.lean`, `comparator.json` or `checks/`: the `challenge` check fails | |
| 105 | + it, as it fails a change to `lakefile.toml` beyond a `require`'s `rev`, `leanOptions`, `defaultTargets`, `lean_exe` | |
| 106 | + or `[cache]`, a dependency outside leanprover and leanprover-community, a `lakefile.lean`, or files under `.lake/`. | |
| 107 | + If you think a statement is wrong, open an issue titled "Ruling: …" and say why. | |
| 108 | + | |
| 109 | +## Notes, audits and chapters | |
| 110 | + | |
| 111 | +The V and T pieces, and P-3 to P-6, change no proof: they are judged by a second reader and the maintainer. | |
| 112 | + | |
| 113 | +- **We want:** one unit in one pull request; every statement with the name and file of its Lean declaration, and every | |
| 114 | + name checked to exist (`git grep`); every source with its edition and number; "could not compare" or "not found" | |
| 115 | + said plainly, with what you tried; what the note does not show, in a sentence. | |
| 116 | +- **We don't want:** text about a declaration or a source you did not open; a summary of a check in place of its | |
| 117 | + output; a row that only repeats a news report; a note that says the proof is right, or wrong, on the strength of a | |
| 118 | + reading of one part; long expositions nobody will read ("there is zero evidence that anyone has read any of them", | |
| 119 | + upstream's maintainer wrote of the first wave, 2026-11-27): a chapter is merged when a second reader has checked it. | |
| 37 | 120 | |
| 38 | 121 | ## Pull requests |
| 39 | 122 | |
| 40 | -Keep each pull request to one change; fixing linter warnings in the files you edit doesn't count | |
| 41 | -as a second one. Check that it compiles (`lake exe cache get`, then `lake build`) before you open | |
| 42 | -it, but don't write in it that it builds or that nothing else changed: CI checks the build. Titles | |
| 43 | -follow [Mathlib's convention](https://leanprover-community.github.io/contribute/commit.html). In | |
| 44 | -the description, say in two or three sentences what the change does and why it makes the proof | |
| 45 | -easier to read, and keep the title and description in step with the diff when you push more | |
| 46 | -commits. Leave out timings and heartbeat counts unless speed is the reason for the change; then | |
| 47 | -give the few numbers a maintainer needs to decide, per declaration where you can, and say how you | |
| 48 | -measured them. | |
| 49 | - | |
| 50 | -If you want to make the same kind of change in many places, open one pull request first and wait | |
| 51 | -for a maintainer to say we want it before you open the others. | |
| 52 | - | |
| 53 | -A pull request is merged only after a reviewer (Triage role or more) has approved its current head | |
| 54 | -commit. When a reviewer hands it back to you with the `awaiting-author` label, make the changes | |
| 55 | -and then comment `ready`, with nothing else in the comment. | |
| 56 | - | |
| 57 | -## Batches | |
| 58 | - | |
| 59 | -A batch takes only pull requests that a reviewer has approved on their current head commit, and | |
| 60 | -none labelled `awaiting-author` or held by a maintainer. Merge each with its own merge commit. To | |
| 61 | -take one out, rebuild the batch without it and force-push; don't revert its merge commit. List the | |
| 62 | -pull requests you left out in the batch's description, with the reason for each. | |
| 123 | +Keep each pull request to one change; fixing linter warnings in the files you edit doesn't count as a second one. For | |
| 124 | +a Lean change, compile what you changed if you can (`lake exe cache get`, then `lake build` of the modules you | |
| 125 | +changed); if you cannot, push and let the `build` check say. Either way, open the pull request, and don't write in it | |
| 126 | +that it builds: `build` says that. Titles follow [Mathlib's convention](https://leanprover-community.github.io/contribute/commit.html). | |
| 127 | +In the description, name the issue it answers (`Closes #3`, or `Part of #3` when the issue has units and yours is | |
| 128 | +one), say in two or three sentences what the change does and why it makes the proof easier to read, and keep the | |
| 129 | +title and description in step with the diff when you push more commits. Leave out timings and heartbeat counts unless | |
| 130 | +speed is the reason for the change; then give the few numbers a maintainer needs to decide, per declaration where you | |
| 131 | +can, and say how you measured them. | |
| 132 | + | |
| 133 | +If you want to make the same kind of change in many places, open one pull request first and wait for the maintainer to | |
| 134 | +say we want it before you open the others. Nothing here counts pull requests: more than half of upstream's changed | |
| 135 | +fewer than ten lines, and the reviewers were the bottleneck. | |
| 136 | + | |
| 137 | +## CI | |
| 138 | + | |
| 139 | +Two checks judge a commit, like upstream's GitHub CI, and both gate the merge. Their code is `checks/` at the | |
| 140 | +approved version, so editing it on your branch changes nothing about your verdict. | |
| 141 | + | |
| 142 | +- **`challenge`** (upstream's `challenge-files.yml`), seconds: the Comparator challenge files and the build | |
| 143 | + configuration are as approved, and the source has no `sorry`, `admit`, `axiom`, `native_decide`, `implemented_by` or | |
| 144 | + `extern`. Run it yourself: `python3 checks/challenge.py .` | |
| 145 | +- **`build`** (upstream's `build.yml`), up to hours: in the project's Lean image with no network, `lake build` ends | |
| 146 | + without error, no module reports `sorry`, the theorems use no axiom beyond `propext`, `Classical.choice` and | |
| 147 | + `Quot.sound`, and Comparator accepts the solution. Its last line says what held or what did not; its logs are kept | |
| 148 | + with the job. If you can build, the same locally before you push: `lake exe cache get && lake build && lake env lean | |
| 149 | + scripts/PrintAxioms.lean`, then `lake comparator --config comparator.json`; if you cannot, push and let `build` say. | |
| 150 | + | |
| 151 | +Wait for `build` rather than pushing again to hurry it: each push is built anew, and builds queue behind others'. | |
| 152 | + | |
| 153 | +A toolchain or Mathlib bump passes `challenge`, but `build` needs a new image first (`docker/README.md`): open an issue | |
| 154 | +for a person who maintains the project rather than a pull request that cannot pass. | |
| 155 | + | |
| 156 | +## For the maintainer | |
| 157 | + | |
| 158 | +The house's maintainer agent (`riemann-maintainer`) comes about every three hours while people work here, at least twice | |
| 159 | +a day, and within minutes when written to. It reviews (first line ``**Review of `<commit>`: <verdict>**``), does not | |
| 160 | +merge, logs each round on the issue "Maintainer log", and opens `Ruling: …` issues (`needs-person`) for what only a | |
| 161 | +person decides. Here, as a `proof` problem: | |
| 162 | + | |
| 163 | +- **Clean-up judged for reading** (skill `judge-cleanup`): every pull request measured at its head against its base | |
| 164 | + with `house/maintainer/tools/measure.py` (the same debt counters upstream's `technical-debt-metrics.py` reports), | |
| 165 | + import-line changes named in the verdict ("import lines only" is never settled by `build` alone), statements compared | |
| 166 | + before and after. | |
| 167 | +- **The progress table** in "Where it stands": that measure at the project's first commit and at main, and the `build` | |
| 168 | + time of main's tip, refreshed after merges. | |
| 169 | +- **Main replayed** in full (`house/maintainer/replay.sh`) at the start of a round when it moved. | |
| 170 | +- **Sources watched**: `leanprover-community/riemann-hypothesis` moves by hundreds of pull requests a day. Each round | |
| 171 | + reads what changed there since the last; a fix or lemma worth having becomes one issue here naming the commit, and | |
| 172 | + what its AGENTS.md learned about which changes help becomes a proposed line for the lists above. | |
| 173 | + | |
| 174 | +Judge every pull request against the two lists above: whether the proof is easier to read after it, not only whether | |
| 175 | +it is shorter or faster. | |
| 176 | + | |
| 177 | +- **Merge** a change we want once `challenge` and `build` have passed on its head, and the description says what it | |
| 178 | + changes and why. | |
| 179 | +- **Request changes** when the description and the diff disagree, when it is two changes in one, when it is on the | |
| 180 | + second list (say which item), or when a reference is added without the edition and theorem number. | |
| 181 | +- **Request changes** when `challenge` or `build` failed: quote the check's last line. | |
| 182 | +- **Escalate** a change to the challenge files, to `checks/` or `docker/`, to `lakefile.toml`'s libraries or dependencies, a new | |
| 183 | + dependency, or two reviews that disagree: say in one sentence what a person must decide. | |
| 184 | +- **Close** a repeat of a change already merged or open, pointing to it, and a mass change opened before the first of | |
| 185 | + its kind was wanted. | |
| 186 | + | |
| 187 | +Never merge on the author's word that it builds: only `build` on its head says so. After a merge, add to `KNOWN.md` what changed and, if it took a lemma | |
| 188 | +from a library, which one. | |
+31 −0 KNOWN.md added View file
| @@ -0,0 +1,31 @@ | ||
| 1 | +# Known | |
| 2 | + | |
| 3 | +What is established about this problem, one fact a line, each with where it comes from: job 12, result 40, issue 7, commit 1a2b3c4 or route `<branch>`. The site checks every pointer and shows the page in the project's status. Its maintainer keeps this file; propose a line in a pull request. | |
| 4 | + | |
| 5 | +## The judge rejects | |
| 6 | + | |
| 7 | +- A `lakefile.toml` change beyond a `require`'s `rev`, `leanOptions`, `defaultTargets`, `lean_exe` or `[cache]`; a package outside leanprover and leanprover-community on GitHub (Tau Ceti excepted); a toolchain that is not a release; files under `.lake/`. | |
| 8 | +- Any change to `Challenge.lean`, `src/Statements.lean` or `comparator.json`: they state what is proved, and `challenge` compares them with the approved version (checks/frozen.json). | |
| 9 | +- `sorry`, `admit`, an `axiom` declaration, `native_decide`, `implemented_by` or `extern` in any Lean file, outside comments and strings. | |
| 10 | +- A `lakefile.lean` beside `lakefile.toml`: Lake would read it instead. | |
| 11 | + | |
| 12 | +## Tried, did not work | |
| 13 | + | |
| 14 | +- Upstream, 2026-11-21 to 11-25: five days of crowd cleanup of the first release took it from 17.4 million lines to about 14 million; a rewrite by a few people with Claude then replaced it with 300,000 (lsernau/grh-lean, 2026-11-25). Pruning and deduplicating a dump line by line did not get near what rewriting did. | |
| 15 | +- Upstream, 2026-11-24: a batch of pull requests that documented and cited classical theorems, written by an agent, was merged and then flagged by a number theorist: every one he checked was wrong. Since then a reference is added only with the edition and the number, checked against the source. | |
| 16 | +- Upstream, 2026-11-27: a version announced as under 55,000 lines was read by a contributor, who found that it mainly dropped comments and blank lines. Fewer lines is not the measure. | |
| 17 | + | |
| 18 | +## Mind | |
| 19 | + | |
| 20 | +- The starting point is leanprover-community/riemann-hypothesis at 630d1e43b442cab27717c3ebf94d218dea608374 (2026-12-01 16:11 UTC): 806 Lean files under `src/`, 484,789 lines with comments, on Lean v4.37.0-rc1 with Mathlib 31ce06ea and Tau Ceti 2a9233e5. From there this project is its own line; upstream moves on independently. | |
| 21 | +- 2026-12-02: the proof is machine-checked and unread. The certificate of 2026-11-21 (Lean FRO and Mathlib Initiative) names the Riemann hypothesis in the first release of 17.4 million lines, not GRH and not this edition; this edition's README said "No mathematician has read it through, and no paper comes with it" (2026-11-25); nothing is refereed; Clay lists the problem as "Active" and has published nothing on it. Sources in README.md. | |
| 22 | +- "GRH" in the five theorems means Dirichlet L-functions, every modulus and character; the last three theorems say nothing about zeros with Re s ≤ 0. | |
| 23 | +- `build` runs in the Lean image `shoal-rh-lean:630d1e43` (docker/), with no network: the image holds the toolchain, the dependencies and a build of the approved main. A toolchain or Mathlib bump passes `challenge` but needs a new image, and the tag in scienceslack.json moved with it, before `build` can pass. | |
| 24 | +- Mathlib and Tau Ceti move together: Tau Ceti's cached oleans work only against the Mathlib commit in `lakefile.toml` (`scripts/tauceti-cache-get.py`). Bump both or neither, and rebuild the image. | |
| 25 | +- Editing import lines can change intermediate statements without any error: upstream measured 80 and 114 declarations that elaborated with other instances after two import-only pull requests, and one that lost a hypothesis ([upstream's report](https://github.com/leanprover-community/riemann-hypothesis/issues/8343), 2026-11-26 to 11-29). The five theorems are protected by Comparator; the lemmas between are not. A pull request that changes imports says so. | |
| 26 | +- `src/Lib/Speed.lean`, imported everywhere through `Lib/Base`, changes instance priorities and the default `simp` set for the whole development (GUIDE.md section 5): a proof that works in a scratch file may not work here, and the reverse. | |
| 27 | +- Counted at the starting commit: 31 `seal` lines in 22 files (S-2); 187 lines in 85 files call `nlinarith` (S-3); REFERENCES.md marks 108 citations "work found, no place given", 32 "place confirmed at second hand", 7 "not compared" (V-3); INDEX.md has 235 rows of known results (V-4). | |
| 28 | +- Upstream counted 289 declarations that nothing reachable from `Main` and `Statements` uses ([upstream's count](https://github.com/leanprover-community/riemann-hypothesis/issues/11857), at 91fcaabb, 2026-11-30) and judged most deliberate: 118 are `@[simp]` lemmas or instances, 85 are in seven modules added on purpose (S-1). | |
| 29 | +- `anyGeometry`, the definition a critique of the first release calls vacuous, does not occur under `src/` here (`git grep`, 2026-12-02). Whether the critique's point carries over in another form is V-5's question, not settled by that. | |
| 30 | +- Left out at the start, as not the proof: upstream's GitHub workflows and the scripts only they run, `CACHE.md` and `CONTRIBUTORS.md`. The cache scripts `lake exe cache get` runs, and `scripts/PrintAxioms.lean`, are kept. | |
| 31 | +- The first release itself is at https://github.com/homeowmorphism/riemann-hypothesis-original, and the community's five days of work on it on upstream's `alpoge` branch. Neither is here. | |
+157 −69 README.md View file
| @@ -1,89 +1,177 @@ | ||
| 1 | -# riemann-hypothesis | |
| 2 | - | |
| 3 | -A community-led effort to clean up and maintain a Lean formalization of the 2026 proofs of the Riemann Hypothesis and of GRH for Dirichlet L-functions. | |
| 4 | - | |
| 5 | -> [!CAUTION] | |
| 6 | -> This repo recently moved to a highly condensed version on November 25, 2026. Prior progress is preserved on the `alpoge` branch. | |
| 7 | - | |
| 8 | -The purpose of this repo is to create an artifact that is: | |
| 9 | - | |
| 10 | -- **accessible**: we want to improve build performance and modularity to enable researchers to feasibly engage with the proof even without access to massive amounts of compute. | |
| 11 | -- **readable**: we want to improve code quality, aspirationally to Mathlib levels. This includes lemma organization, formatting and idiomatic style, eliminating linter warnings, slop-free documentation, and more. | |
| 12 | -- **integrated with the community**: we would like to add bibliographic references to prior work where appropriate, and rely on existing formalization projects when possible. | |
| 13 | - | |
| 14 | -Please note: we are **not** looking for: | |
| 15 | - | |
| 16 | -- claims about your own machine's builds / comparator run | |
| 17 | -- adding files which are not necessary for the Riemann Hypothesis proof | |
| 18 | - | |
| 19 | -This work is taking place on the `main` branch, which is based on a copy of the readable | |
| 20 | -edition (`grh/`) of https://github.com/lsernau/grh-lean at commit 72fead102f663d5c7a407964a13dc0cf9d977207. | |
| 21 | - | |
| 22 | -The `alpoge` branch retains the progress the community made towards cleaning up the original version of the proof released by Levent Alpöge in the first few days before the aforementioned readable edition was released. | |
| 23 | - | |
| 24 | -The `original` branch preserves the first publicly-released version of the proof retrieved on 2026-11-20 from <https://alpo.ge/remark.pdf>. | |
| 25 | - | |
| 26 | -If you want to open the original proof without compiling it, see the repo | |
| 27 | -[riemann-hypothesis-original](https://github.com/homeowmorphism/riemann-hypothesis-original). | |
| 28 | -It keeps the published Lean source unchanged and provides a prebuilt cache for it. | |
| 29 | - | |
| 30 | -## Theorem Statements | |
| 31 | - | |
| 32 | -[`src/Main.lean`](src/Main.lean) proves the following theorems: | |
| 1 | +# Riemann hypothesis: the Lean proof, cleaned up together | |
| 2 | + | |
| 3 | +A Lean proof of the Riemann hypothesis, and of GRH for Dirichlet L-functions, exists: Levent Alpöge's, working with | |
| 4 | +Claude, 2026-11-20. Andrew Sutherland and Michael Rubinstein checked it by machine, and the Lean FRO and the Mathlib | |
| 5 | +Initiative certified the Riemann hypothesis in its first release on 2026-11-21. Not yet: a mathematician who has read | |
| 6 | +it through, a refereed paper, or any word from Clay, which still lists the problem as active. | |
| 7 | + | |
| 8 | +This project is a community effort to make that proof smaller, faster to build and readable, and to write down what it | |
| 9 | +says. | |
| 10 | + | |
| 11 | +## Where it stands (as of 2026-12-02) | |
| 12 | + | |
| 13 | +| Step | State | Who, when, where it is written | | |
| 14 | +|---|---|---| | |
| 15 | +| Announced | A Lean proof and a four-page note, no paper | Levent Alpöge, working with Claude, 2026-11-20: "I believe I have, working with Claude, discovered a proof of the Riemann Hypothesis" ([remark.pdf](https://alpo.ge/remark.pdf), undated). The first release is 175,187 files, 17.4 million lines. | | |
| 16 | +| Machine-checked | Yes, several times, by people outside | Andrew Sutherland (MIT): every module compiles (2026-11-20); Lean's kernel, nanoda, two verified checkers and `lake comparator` accept, the last on 2026-11-25 ([his record](https://math.mit.edu/~drew/grh/), updated 2026-11-27). Michael Rubinstein (Waterloo), 2026-11-21 ([his record](https://mrubinst.github.io/grh-lean-verification/)). The 300,000-line edition this project starts from: nanoda, two verified checkers and `lake comparator --paranoid` accept ([Sutherland](https://math.mit.edu/~drew/shortgrh/), 2026-11-26). | | |
| 17 | +| Certified | Yes, for the Riemann hypothesis in the first release | The Lean FRO and the Mathlib Initiative, 2026-11-21: "We hereby certify that both the statement and the proof of the Riemann Hypothesis are correct." ([statement](https://leanprover-community.github.io/blog/posts/riemann-hypothesis/)). It names the Riemann hypothesis, not GRH. | | |
| 18 | +| Read by experts | Not yet | The edition we start from says: "No mathematician has read it through, and no paper comes with it" ([lsernau/grh-lean](https://github.com/lsernau/grh-lean), 2026-11-25). Terence Tao on one step, 2026-11-30: "I don't understand the details". The [G.R.H. Polymath](https://terrytao.wordpress.com/2026/11/24/g-r-h-polymath/) (since 2026-11-24) has as its first goal "a human-readable and understandable proof". Outlines exist ([Rubinstein's](https://www.math.uwaterloo.ca/~mrubinst/alpoge_claude_grh/), 45 pages, 2026-11-27, says its three main theorems "are not proved there"); a preprint claims a complete written proof ([arXiv:2611.38136](https://arxiv.org/abs/2611.38136), 2026-11-27), and nobody is known to have checked it. | | |
| 19 | +| Published | No | Nothing refereed. The author: "I will do a proper job in a proper writeup" (remark.pdf). | | |
| 20 | +| Recognised by Clay | No ruling | Clay lists the problem under "Active problems" ([its page](https://www.claymath.org/millennium/riemann-hypothesis/), read 2026-12-02) and has published nothing on this proof. Its [rules](https://www.claymath.org/wp-content/uploads/2022/03/millennium_prize_rules_0.pdf) (2018-09-26) ask for publication in a refereed outlet and two years of scrutiny after it. | | |
| 21 | + | |
| 22 | +What to keep in mind when you read that table: | |
| 23 | + | |
| 24 | +- **"GRH" here means Dirichlet L-functions**, every modulus and character. Dedekind zeta functions, Hecke and | |
| 25 | + automorphic L-functions are not among the five theorems. | |
| 26 | +- **The Lean in this project is not the text that was certified.** The first release was 17.4 million lines. On | |
| 27 | + 2026-11-25 Luke Sernau and colleagues at Anthropic, with Claude, published a rewrite of about 300,000 lines that | |
| 28 | + "follows that proof's method; many steps are proved by other arguments" (its README), and the community's cleanup | |
| 29 | + moved to it the same day. Its checks are the machine-checked row above and the `build` check here. | |
| 30 | +- **Doubts have been raised and answered, in public.** A critique says the first release's geometry is vacuous; a | |
| 31 | + reply ([arXiv:2611.37492](https://arxiv.org/abs/2611.37492), 2026-11-27) finds the objection does not break the | |
| 32 | + logic and adds "it is not a certification of the claimed proof"; Lean's maintainers said the critique can be | |
| 33 | + ignored (Lean Zulip, 2026-11-21). Piece V-5 reads such reports against this tree. | |
| 34 | +- **Nothing here is progress on the Riemann hypothesis.** The theorems are fixed and only the proof's text and what | |
| 35 | + is written about it change. Whether the proof is accepted is for its readers, its referees and Clay. | |
| 36 | + | |
| 37 | +## Where this comes from | |
| 38 | + | |
| 39 | +This project starts from [leanprover-community/riemann-hypothesis](https://github.com/leanprover-community/riemann-hypothesis) | |
| 40 | +at `630d1e43b442cab27717c3ebf94d218dea608374` (2026-12-01 16:11 UTC), which is in turn based on the readable edition | |
| 41 | +(`grh/`) of [lsernau/grh-lean](https://github.com/lsernau/grh-lean) at `72fead10`. From that commit on it is its own | |
| 42 | +line: this project and upstream develop independently. | |
| 43 | + | |
| 44 | +Upstream stays useful as evidence. In twelve days its crowd cleanup merged 8,579 pull requests by 215 people | |
| 45 | +(several hundred a day, and it goes on) and closed 2,904 unmerged, and its maintainers rewrote their rules as they | |
| 46 | +went. Which kinds of change turned out to help | |
| 47 | +this very proof, and which hurt it, is what the two lists in [`AGENTS.md`](AGENTS.md) record; upstream's own README | |
| 48 | +and AGENTS.md at our starting commit are kept in [`UPSTREAM.md`](UPSTREAM.md). A good change made upstream since then | |
| 49 | +can be brought over as an ordinary pull request by whoever wants to (piece M-5). Upstream's GitHub CI (workflows, the | |
| 50 | +scripts only they run, `CACHE.md`, `CONTRIBUTORS.md`) is left out: this project's CI is `checks/`. | |
| 51 | + | |
| 52 | +Thanks to Levent Alpöge, to Luke Sernau and his colleagues for the edition this starts from, and to the maintainers | |
| 53 | +and contributors of leanprover-community/riemann-hypothesis, whose tree, guide and rules these are. | |
| 54 | + | |
| 55 | +## What this project is for | |
| 56 | + | |
| 57 | +To make the proof: | |
| 58 | + | |
| 59 | +- **accessible**: faster to build and more modular, so a researcher without a large machine can engage with it | |
| 60 | + (S-1 to S-6); | |
| 61 | +- **readable**: code quality, aspirationally at Mathlib's level: lemmas organised, named and documented, long proofs | |
| 62 | + split into steps with names, no linter warnings, docstrings that say what is proved (P-1 to P-7); | |
| 63 | +- **integrated with the community**: results from Mathlib and [Tau Ceti](https://github.com/TauCetiProject/TauCeti) | |
| 64 | + in place of our own proofs of them, lemmas at their natural generality, references where they belong (M-1 to M-5); | |
| 65 | +- **checked by reading**: the five statements against the problem, each known result against the literature, the | |
| 66 | + citations against their sources, builds rerun as jobs the site knows (V-1 to V-5); | |
| 67 | +- **written as mathematics**: an outline, the last step, the data, one chapter at a time, each statement with its | |
| 68 | + Lean declaration beside it and a second reader's check, and a reading path in Chinese (T-1 to T-7). | |
| 69 | + | |
| 70 | +The Lean work is the main line. The reading and writing pieces are the share of it that needs no build. | |
| 71 | + | |
| 72 | +We are **not** looking for | |
| 73 | + | |
| 74 | +- claims about your own machine's build or Comparator run with nothing the site can check; | |
| 75 | +- files that are neither the proof nor an account of it; | |
| 76 | +- any change to what is proved, or to how it is built and judged. The `challenge` check fails it; | |
| 77 | +- a change that makes the code shorter or faster but harder to read; | |
| 78 | +- many small pull requests for their number. Nothing here counts them. | |
| 79 | + | |
| 80 | +## How to take part | |
| 81 | + | |
| 82 | +| You have | Take | It needs | | |
| 83 | +|---|---|---| | |
| 84 | +| ten minutes and a browser | V-3 (ten citations), P-4 (one row of the guide), P-5 (twenty rows of the index) | reading and `git grep` | | |
| 85 | +| Lean on your machine | P-1 (one folder's linter warnings), S-5 (a hypothesis no proof uses), M-1 (a lemma Mathlib has), then P-2, P-7, S-2, S-3, S-6, M-2, M-4, M-5 | Lean and the build cache; you compile a few files | | |
| 86 | +| a day, and number theory | V-2, V-4, T-4, T-5, T-6, a chapter of T-2 | reading; the sources | | |
| 87 | +| Chinese | T-7, the reading path | reading | | |
| 88 | +| a large machine | V-1, S-4, S-1 | a build from source | | |
| 89 | + | |
| 90 | +The issues are the pieces; each says what to do, what it needs, when it closes and what it does not show. Most hold | |
| 91 | +many people at once, each on a unit of their own (a folder, a file, a row, ten citations): take a unit nobody has | |
| 92 | +(`git fetch origin issues && git show origin/issues:BOARD.md`), name your branch after it, and say `Part of #<issue>` | |
| 93 | +in your pull request. One change in one pull request. [`AGENTS.md`](AGENTS.md) has the first session, command by | |
| 94 | +command. | |
| 95 | + | |
| 96 | +## How work is judged, and when | |
| 97 | + | |
| 98 | +| Who | What it looks at | When | | |
| 99 | +|---|---|---| | |
| 100 | +| `challenge` | the three fixed files and the build configuration are as approved; no `sorry`, `admit`, `axiom`, `native_decide`, `implemented_by` or `extern` in the source | on a push, in seconds | | |
| 101 | +| `build` | in the project's Lean image ([`docker/`](docker/README.md)), with no network: `lake build` ends without error, no module reports `sorry`, the five theorems depend on no axiom beyond `propext`, `Classical.choice` and `Quot.sound`, and Comparator says Lean's kernel and nanoda accept the proof | on a push that changes Lean; its limit is six hours | | |
| 102 | +| a second reader | for a note, an audit or a chapter: are its statements the Lean's, are its sources the ones it names | in a review on the pull request | | |
| 103 | +| the house's maintainer agent | is it a change we want ([`AGENTS.md`](AGENTS.md)), is it readable, does it claim no more than its evidence | in its rounds, about every three hours | | |
| 104 | + | |
| 105 | +A pull request that changes Lean is merged only once `challenge` and `build` have passed on its head; one that changes | |
| 106 | +only notes, guides or chapters, once a second reader has reviewed it. The checks' code is `checks/` at the approved | |
| 107 | +version, so a branch that edits it changes nothing about its own verdict. The site reads each pull request within | |
| 108 | +minutes of a push and takes it in once the checks and the evidence its piece asks for are there. The house's | |
| 109 | +maintainer agent (`riemann-maintainer`) comes about every three hours while people are working here, and at least twice | |
| 110 | +a day, to review and to keep this page and the pieces current; a question written to it in the channels or with | |
| 111 | +`@riemann-maintainer` is answered within minutes. Its reviews start "Review of `<commit>`: ready", "changes needed" or | |
| 112 | +"needs a person"; a person decides what it leaves to a person. You need not wait for `build` in your session: push, | |
| 113 | +say so on the issue, and come back to the verdict. | |
| 114 | + | |
| 115 | +## The theorems | |
| 116 | + | |
| 117 | +[`src/Main.lean`](src/Main.lean) proves: | |
| 33 | 118 | |
| 34 | 119 | | Theorem | Statement | |
| 35 | 120 | |---|---| |
| 36 | 121 | | `riemannHypothesis` | Mathlib's `RiemannHypothesis` | |
| 37 | -| `riemannZeta_eq_zero_re` | the same statement as `riemannHypothesis` but spelled out without Mathlib's definition of the statement | | |
| 38 | -| `LFunction_ne_zero_of_half_lt_re` | L(χ, s) ≠ 0 for Re s > 1/2, for every modulus and every Dirichlet character, except the trivial character at s = 1 | | |
| 122 | +| `riemannZeta_eq_zero_re` | the same, spelled out without Mathlib's definition | | |
| 123 | +| `LFunction_ne_zero_of_half_lt_re` | L(χ, s) ≠ 0 for Re s > 1/2, every modulus and Dirichlet character, except the trivial character at s = 1 | | |
| 39 | 124 | | `LFunction_eq_zero_re` | every zero of L(χ, s) with 0 < Re s < 1 has Re s = 1/2 | |
| 40 | -| `LFunction_eq_zero_re_of_isPrimitive` | the special case of `LFunction_eq_zero_re` for primitive characters | | |
| 125 | +| `LFunction_eq_zero_re_of_isPrimitive` | the case of primitive characters | | |
| 41 | 126 | |
| 42 | -[`src/Statements.lean`](src/Statements.lean) provides the statements of all of these theorems, and only imports Mathlib to state them. It is imported by both [`src/Main.lean`](src/Main.lean) and [`Challenge.lean`](Challenge.lean) | |
| 127 | +[`src/Statements.lean`](src/Statements.lean) states them, importing only Mathlib. [`Challenge.lean`](Challenge.lean) | |
| 128 | +imports only `src/Statements.lean` and declares the five theorems with `sorry`. Comparator | |
| 129 | +([`comparator.json`](comparator.json)) checks that `Main` proves exactly those statements, with no axioms beyond | |
| 130 | +`propext`, `Quot.sound` and `Classical.choice`, and that Lean's kernel and nanoda both accept the proof. | |
| 43 | 131 | |
| 44 | -[`Challenge.lean`](Challenge.lean) imports *only* [`src/Statements.lean`](src/Statements.lean), and declares the same five theorems with `sorry` in place of the proofs. | |
| 132 | +**These three files are fixed.** So is the build configuration, as far as Comparator depends on it: `lakefile.toml` | |
| 133 | +changes only in a `require`'s `rev`, `leanOptions`, `defaultTargets`, `lean_exe` or `[cache]`; every package is a Git | |
| 134 | +repository of leanprover or leanprover-community, or Tau Ceti; the toolchain is a release; no `lakefile.lean`, nothing | |
| 135 | +under `.lake/`. If you think a statement is wrong, open an issue titled "Ruling: …". | |
| 45 | 136 | |
| 46 | -Comparator checks that `Main.lean` proves exactly those statements, that it uses no axioms other than `propext`, `Quot.sound` and | |
| 47 | -`Classical.choice`, and that Lean's kernel and nanoda both accept the proof. | |
| 137 | +## Build | |
| 48 | 138 | |
| 49 | -## Cache | |
| 139 | +Most pieces need no build. If yours does: | |
| 50 | 140 | |
| 51 | -``` | |
| 52 | -lake exe cache get | |
| 141 | +```sh | |
| 142 | +lake exe cache get # Mathlib's cache, then Tau Ceti's, then this proof's, from upstream's servers | |
| 53 | 143 | lake build |
| 144 | +lake env lean scripts/PrintAxioms.lean # the axioms of the five theorems | |
| 54 | 145 | ``` |
| 55 | 146 | |
| 56 | -This needs Python 3.11 or newer and curl 7.71 or newer, with no credentials. The command restores | |
| 57 | -the Mathlib, Tau Ceti, and project caches in that order. Run it before editing the Lean sources | |
| 58 | -or build configuration so it can match the published build inputs. | |
| 59 | -`lake exe mathlib/cache get` fetches Mathlib alone. | |
| 147 | +`lake exe cache get` needs Python 3.11 or newer and curl 7.71 or newer, with no credentials; run it before you edit | |
| 148 | +the Lean sources. Upstream's cache has a record for the build inputs of our starting commit (looked up 2026-12-02); | |
| 149 | +whether it restores in this project's tree, and still as a baseline once `main` here has moved on, is not tested yet. | |
| 150 | +It saves the build, and it proves nothing: upstream's own note says the cached files "were built from an unverified | |
| 151 | +third-party proof, and the cache does not verify anything". A build from source is hours: the edition's authors give | |
| 152 | +one to two hours on 12 cores with 24 GB of memory, and upstream's runners spend about four CPU-hours on a full rebuild | |
| 153 | +(read from its CI on 2026-12-01). The `build` check's own time on this project is not measured yet (2026-12-02: its | |
| 154 | +image is still being made). Mathlib and Tau Ceti move together: Tau Ceti's cached files work only against the Mathlib | |
| 155 | +commit in `lakefile.toml`. | |
| 60 | 156 | |
| 61 | -See [`CACHE.md`](CACHE.md) for details. | |
| 157 | +Comparator ships with the toolchain (Lean v4.35.0 and later): with `bwrap` and the toolchain's `nanoda_bin` on | |
| 158 | +`PATH`, `lake comparator --config comparator.json` from the repository's root. The `build` check runs the same. | |
| 62 | 159 | |
| 63 | 160 | ## Layout |
| 64 | 161 | |
| 65 | -*For now, this section is copied from https://github.com/lsernau/grh-lean. It may be out of date and is subject to change.* | |
| 66 | - | |
| 67 | -About 300,000 lines of code; 433,000 non-blank lines with comments; 477,000 lines in all. | |
| 68 | -- `src/Lib` (495 files): background results, classed as known in the literature, that Mathlib lacks, with the steps of their proofs. It imports nothing from `src/New`. | |
| 69 | -- `src/New` (306 files): the set-up and the steps of the argument, in folders that follow its order. The main inequality is in `src/New/Reduction/MainInequality.lean`, the theorem in half-plane form in `src/New/Reduction/OneSidedBound.lean`. | |
| 70 | -- `src/Lib/Speed.lean` holds the main settings that apply to the whole development (instance priorities, `simp` lemmas taken out of the default set, one added `simp` lemma). With the file emptied, everything still compiled on Lean 4.33.1; on the current toolchain a few files rely on it (see its module note). `GUIDE.md` explains them. | |
| 71 | -- `GUIDE.md`: start here. It gives the reading order, a glossary, sizes and conventions. `CONTENTS.md`: every file with its title. `INDEX.md`: the results, with sources or related work and files. | |
| 72 | -- `REFERENCES.md` lists the citations and says which were compared with their sources. | |
| 73 | - | |
| 74 | -## Acknowledgements | |
| 75 | - | |
| 76 | -Thanks to the Lean FRO and BAIF for providing resources to run CI here; others have contributed too, if you'd like acknowledgement here let @kim-em know. | |
| 77 | - | |
| 78 | -[`CONTRIBUTORS.md`](CONTRIBUTORS.md) lists everyone with a merged pull request. | |
| 79 | - | |
| 80 | -## License | |
| 162 | +806 Lean files under `src/`, 484,789 lines with comments, about 300,000 of them code. | |
| 81 | 163 | |
| 82 | -The proof belongs to its author Levent Alpöge with Claude and was originally published without a license. The repo https://github.com/lsernau/grh-lean uses Apache 2.0, and so does this repo; see [`LICENSE`](LICENSE), [`NOTICE`](NOTICE) and [`ATTRIBUTION.md`](ATTRIBUTION.md). | |
| 164 | +- `src/Lib` (501 files in 16 folders): background results, known in the literature, that Mathlib lacks. It imports | |
| 165 | + nothing from `src/New`. | |
| 166 | +- `src/New` (303 files in 8 folders): the set-up and the steps of the argument, in folders that follow its order. | |
| 167 | + The main inequality is `src/New/Reduction/MainInequality.lean`, the half-plane form | |
| 168 | + `src/New/Reduction/OneSidedBound.lean`. | |
| 169 | +- [`GUIDE.md`](GUIDE.md): start here, with the reading order, a glossary, sizes and conventions. | |
| 170 | + [`CONTENTS.md`](CONTENTS.md): every file with its title. [`INDEX.md`](INDEX.md): the results, with sources. | |
| 171 | + [`REFERENCES.md`](REFERENCES.md): the citations, and which were compared with their sources. | |
| 172 | +- `docs/`: what this project writes about the proof: `exposition/` (the proof as mathematics), `audit/`, `statements/`, `zh/`. | |
| 173 | +- `checks/`: this project's CI; `docker/`: the Lean image `build` runs in. `KNOWN.md`: what is known, dated. | |
| 83 | 174 | |
| 84 | -*Soon, we will re-integrate Formal Conjectures. This is out of date.* | |
| 175 | +## Licence | |
| 85 | 176 | |
| 86 | -The declarations in `comparator/` that will be copied from | |
| 87 | -[formal-conjectures](https://github.com/google-deepmind/formal-conjectures) are copyright The Formal | |
| 88 | -Conjectures Authors, under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). | |
| 89 | -The files that hold them carry the notice. | |
| 177 | +Upstream's files, kept as they are: [`LICENSE`](LICENSE), [`NOTICE`](NOTICE), [`ATTRIBUTION.md`](ATTRIBUTION.md). | |
+155 −0 README.zh.md added View file
| @@ -0,0 +1,155 @@ | ||
| 1 | +# 黎曼猜想:一起把证明改好 | |
| 2 | + | |
| 3 | +黎曼猜想(以及狄利克雷 L 函数的 GRH)已经有一份 Lean 证明:阿尔波格与 Claude,2026-11-20。Andrew Sutherland 和 Michael | |
| 4 | +Rubinstein 用机器核对过它,Lean FRO 与 Mathlib Initiative 在 2026-11-21 认证了首次发布里的黎曼猜想。还没有的:读完它的 | |
| 5 | +数学家、经过审稿的论文、克雷的任何表态(克雷仍把这道题列在“Active problems”下)。 | |
| 6 | + | |
| 7 | +本项目把这份证明改得更小、编译更快、更好读,并把它说了什么写下来。 | |
| 8 | + | |
| 9 | +## 现状(截至 2026-12-02) | |
| 10 | + | |
| 11 | +| 步骤 | 状态 | 谁、何时、写在哪 | | |
| 12 | +|---|---|---| | |
| 13 | +| 宣布 | 一份 Lean 证明和四页说明,没有论文 | 阿尔波格(Levent Alpöge)与 Claude,2026-11-20:“I believe I have, working with Claude, discovered a proof of the Riemann Hypothesis”([remark.pdf](https://alpo.ge/remark.pdf),无日期)。首次发布 175,187 个文件、1,740 万行。 | | |
| 14 | +| 机器核对 | 通过,多人独立做过多次 | Andrew Sutherland(MIT):全部模块编译通过(2026-11-20);Lean 内核、nanoda、两个带形式化证明的检查器和 `lake comparator` 都接受,最后一项完成于 2026-11-25([他的记录](https://math.mit.edu/~drew/grh/),2026-11-27 更新)。Michael Rubinstein(Waterloo),2026-11-21([他的记录](https://mrubinst.github.io/grh-lean-verification/))。本项目起点所用的 30 万行版本:nanoda、两个检查器和 `lake comparator --paranoid` 都接受([Sutherland](https://math.mit.edu/~drew/shortgrh/),2026-11-26)。 | | |
| 15 | +| 机构认证 | 有,针对首次发布里的黎曼猜想 | Lean FRO 与 Mathlib Initiative,2026-11-21:“We hereby certify that both the statement and the proof of the Riemann Hypothesis are correct.”([声明](https://leanprover-community.github.io/blog/posts/riemann-hypothesis/))。声明说的是黎曼猜想,没有提 GRH。 | | |
| 16 | +| 专家读过 | 还没有 | 起点版本自己写着:“No mathematician has read it through, and no paper comes with it”([lsernau/grh-lean](https://github.com/lsernau/grh-lean),2026-11-25)。陶哲轩 2026-11-30 谈其中一步:“I don't understand the details”。[G.R.H. Polymath](https://terrytao.wordpress.com/2026/11/24/g-r-h-polymath/)(2026-11-24 起)的第一个目标是“a human-readable and understandable proof”。已有若干提纲([Rubinstein 的](https://www.math.uwaterloo.ca/~mrubinst/alpoge_claude_grh/) 45 页,2026-11-27,说明三条主要定理“are not proved there”);一篇预印本声称给出完整的书面证明([arXiv:2611.38136](https://arxiv.org/abs/2611.38136),2026-11-27),尚不知有人核对过。 | | |
| 17 | +| 发表 | 没有 | 没有经过审稿的文本。作者说:“I will do a proper job in a proper writeup”(remark.pdf)。 | | |
| 18 | +| 克雷认定 | 没有表态 | 克雷把这道题列在“Active problems”下([题目页](https://www.claymath.org/millennium/riemann-hypothesis/),2026-12-02 读),没有就这份证明发表任何文字。它的[规则](https://www.claymath.org/wp-content/uploads/2022/03/millennium_prize_rules_0.pdf)(2018-09-26)要求在有审稿的刊物上发表,并在发表后经受两年检验。 | | |
| 19 | + | |
| 20 | +读这张表时要记住: | |
| 21 | + | |
| 22 | +- **这里的 GRH 指狄利克雷 L 函数**,所有模和所有特征。Dedekind ζ 函数、Hecke 与自守 L 函数不在五条定理之内。 | |
| 23 | +- **本项目里的 Lean 不是被认证的那份文本。** 首次发布有 1,740 万行。2026-11-25,Luke Sernau 和 Anthropic 的同事借助 Claude | |
| 24 | + 发布了约 30 万行的重写版,它“follows that proof's method; many steps are proved by other arguments”(其 README),社区的 | |
| 25 | + 清理当天转到这一版上。它经过的核对是上表“机器核对”一行,以及本项目的 `build` 检验。 | |
| 26 | +- **质疑提出过,也公开回应过。** 有一篇批评说首次发布里的几何条件是空的;一篇回应([arXiv:2611.37492](https://arxiv.org/abs/2611.37492), | |
| 27 | + 2026-11-27)认为这个反对不破坏逻辑,同时写明“it is not a certification of the claimed proof”;Lean 的维护者说这篇批评可以 | |
| 28 | + 不理(Lean Zulip,2026-11-21)。子任务 V-5 对照本项目的代码去读这类报告。 | |
| 29 | +- **这里做的事都不是黎曼猜想本身的进展。** 定理固定不动,变的只是证明的写法和关于它的文字。证明是否被接受,由读它的人、 | |
| 30 | + 审稿人和克雷来说。 | |
| 31 | + | |
| 32 | +## 从哪来 | |
| 33 | + | |
| 34 | +本项目从 [leanprover-community/riemann-hypothesis](https://github.com/leanprover-community/riemann-hypothesis) 的 | |
| 35 | +`630d1e43b442cab27717c3ebf94d218dea608374`(2026-12-01 16:11 UTC)开始,它又基于 | |
| 36 | +[lsernau/grh-lean](https://github.com/lsernau/grh-lean) `72fead10` 的可读版(`grh/`)。从这个提交起,本项目是自己的一条线: | |
| 37 | +它和上游各自发展。 | |
| 38 | + | |
| 39 | +上游仍是很有用的证据。十二天里那边的众人清理合并了 215 人的 8,579 个 PR(每天几百个,现在还在继续),另有 2,904 个关闭 | |
| 40 | +未合并,维护者一边做一边改规则。 | |
| 41 | +哪几类改动对这份证明真有帮助、哪几类有害,记在 [`AGENTS.md`](AGENTS.md) 的两张清单里;上游在起点提交的 README 和 AGENTS.md | |
| 42 | +原样保存在 [`UPSTREAM.md`](UPSTREAM.md)。起点之后上游做出的好改动,谁愿意都可以作为普通 PR 搬过来(子任务 M-5)。上游的 | |
| 43 | +GitHub CI(workflow、只有它用的脚本、`CACHE.md`、`CONTRIBUTORS.md`)没有带过来:本项目的 CI 是 `checks/`。 | |
| 44 | + | |
| 45 | +感谢阿尔波格,感谢 Luke Sernau 和他的同事写出本项目起点的版本,感谢 leanprover-community/riemann-hypothesis 的维护者和 | |
| 46 | +贡献者:这棵代码树、阅读指南和规则都出自他们。 | |
| 47 | + | |
| 48 | +## 这个项目做什么 | |
| 49 | + | |
| 50 | +把证明改成: | |
| 51 | + | |
| 52 | +- **用得起**:编译更快、更模块化,没有大机器的研究者也能上手(S-1 到 S-6); | |
| 53 | +- **读得懂**:代码质量向 Mathlib 看齐:引理有条理、有名字、有文档,长证明拆成有名字的步骤,没有 linter 警告, | |
| 54 | + 文档字符串说清证了什么(P-1 到 P-7); | |
| 55 | +- **和社区接上**:Mathlib 和 [Tau Ceti](https://github.com/TauCetiProject/TauCeti) 已有的结果用它们的,引理写到它本来的 | |
| 56 | + 一般性,文献出处放在该放的地方(M-1 到 M-5); | |
| 57 | +- **靠读来核对**:五条陈述是不是原题,每条已知结果是不是文献里的那条,引用是不是对得上原文,把编译作为站点认得的作业 | |
| 58 | + 重跑(V-1 到 V-5); | |
| 59 | +- **写成数学**:提纲、最后一步、数据,一章一章地写,每条陈述旁边放着它的 Lean 声明,由第二个读者核对;还有一条中文 | |
| 60 | + 阅读路径(T-1 到 T-7)。 | |
| 61 | + | |
| 62 | +Lean 上的工作是主线。阅读和写作的子任务是其中不需要编译的那一部分。 | |
| 63 | + | |
| 64 | +我们**不要**: | |
| 65 | + | |
| 66 | +- 只说“我机器上编译过了”或“Comparator 跑过了”,却没有站点能核对的东西; | |
| 67 | +- 既不是证明、也不是对证明的说明的文件; | |
| 68 | +- 改动证了什么,或者改动怎么编译、怎么判。`challenge` 检验会拦下; | |
| 69 | +- 让代码更短或更快、却更难读的改动; | |
| 70 | +- 为了数量而开的许多小 PR。这里不数 PR 的个数。 | |
| 71 | + | |
| 72 | +## 怎么参与 | |
| 73 | + | |
| 74 | +| 你有 | 做哪块 | 需要什么 | | |
| 75 | +|---|---|---| | |
| 76 | +| 十分钟和一个浏览器 | V-3(十条引用)、P-4(阅读指南的一行)、P-5(索引的二十行) | 阅读和 `git grep` | | |
| 77 | +| 本机有 Lean | P-1(一个文件夹的 linter 警告)、S-5(没有证明用到的假设)、M-1(Mathlib 已有的引理),然后是 P-2、P-7、S-2、S-3、S-6、M-2、M-4、M-5 | Lean 和编译缓存;只编译几个文件 | | |
| 78 | +| 一天时间,懂数论 | V-2、V-4、T-4、T-5、T-6,T-2 的一章 | 阅读;文献 | | |
| 79 | +| 中文 | T-7,中文阅读路径 | 阅读 | | |
| 80 | +| 一台大机器 | V-1、S-4、S-1 | 从源码完整编译 | | |
| 81 | + | |
| 82 | +Issue 就是子任务;每块写明做什么、需要什么、什么时候算完成、它不能说明什么。多数子任务可以很多人同时做,各占一个单元 | |
| 83 | +(一个文件夹、一个文件、一行、十条引用):挑一个没人占的单元(`git fetch origin issues && git show origin/issues:BOARD.md`), | |
| 84 | +用它给分支起名,在 PR 里写 `Part of #<issue>`。一个 PR 只做一件事。[`AGENTS.md`](AGENTS.md) 里有第一次会话的逐条命令。 | |
| 85 | + | |
| 86 | +## 怎么判,什么时候判 | |
| 87 | + | |
| 88 | +| 谁来判 | 看什么 | 什么时候 | | |
| 89 | +|---|---|---| | |
| 90 | +| `challenge` | 三个固定文件和编译配置与批准的版本一致;源码里没有 `sorry`、`admit`、`axiom`、`native_decide`、`implemented_by`、`extern` | 推送后几秒 | | |
| 91 | +| `build` | 在本项目的 Lean 镜像里([`docker/`](docker/README.md))断网运行:`lake build` 无错结束,没有模块报 `sorry`,五条定理只依赖 `propext`、`Classical.choice`、`Quot.sound`,Comparator 说 Lean 内核和 nanoda 都接受 | 改了 Lean 的推送之后;上限六小时 | | |
| 92 | +| 第二个读者 | 笔记、核读或一章数学:其中的陈述是不是 Lean 里的陈述,出处是不是它写的那个 | PR 上的评审 | | |
| 93 | +| 站点的 maintainer agent | 是不是我们要的改动([`AGENTS.md`](AGENTS.md)),是否更好读,有没有说得比证据多 | 它的每一轮,大约每三小时 | | |
| 94 | + | |
| 95 | +改了 Lean 的 PR,只有 `challenge` 和 `build` 在最新提交上都通过才会合并;只改笔记、指南或章节的 PR,第二个读者评审过才会合并。 | |
| 96 | +检验的代码是批准版本的 `checks/`,分支上改它不影响自己的判定。站点在推送后几分钟内读到每个 PR,检验和子任务要的证据都齐了就收进来。站点的 maintainer agent | |
| 97 | +(`riemann-maintainer`)在有人做事时大约每三小时来一轮,每天至少两轮:评审,并让这一页和子任务保持最新;在频道里或用 `@riemann-maintainer` 写给它的问题,几分钟内回答。 | |
| 98 | +它的评审以“Review of `<commit>`: ready”“changes needed”或“needs a person”开头;它留给人的事,由人决定。 | |
| 99 | +不必在会话里等 `build`:推送后在 Issue 上说一声,过后回来看判定。 | |
| 100 | + | |
| 101 | +## 五条定理 | |
| 102 | + | |
| 103 | +[`src/Main.lean`](src/Main.lean) 证明: | |
| 104 | + | |
| 105 | +| 定理 | 陈述 | | |
| 106 | +|---|---| | |
| 107 | +| `riemannHypothesis` | Mathlib 的 `RiemannHypothesis` | | |
| 108 | +| `riemannZeta_eq_zero_re` | 同一命题,不借 Mathlib 的定义写出 | | |
| 109 | +| `LFunction_ne_zero_of_half_lt_re` | 对每个模和每个狄利克雷特征,Re s > 1/2 时 L(χ, s) ≠ 0(平凡特征在 s = 1 处除外) | | |
| 110 | +| `LFunction_eq_zero_re` | L(χ, s) 在 0 < Re s < 1 内的零点都满足 Re s = 1/2 | | |
| 111 | +| `LFunction_eq_zero_re_of_isPrimitive` | 本原特征的情形 | | |
| 112 | + | |
| 113 | +[`src/Statements.lean`](src/Statements.lean) 写出这些陈述,只引入 Mathlib。[`Challenge.lean`](Challenge.lean) 只引入 | |
| 114 | +`src/Statements.lean`,用 `sorry` 声明这五条定理。Comparator([`comparator.json`](comparator.json))核对 `Main` 证的正是 | |
| 115 | +这些陈述,只用 `propext`、`Quot.sound`、`Classical.choice` 三条公理,并且 Lean 内核和 nanoda 都接受。 | |
| 116 | + | |
| 117 | +**这三个文件不能改。** 编译配置中 Comparator 依赖的部分也一样:`lakefile.toml` 只能改 `require` 的 `rev`、`leanOptions`、 | |
| 118 | +`defaultTargets`、`lean_exe` 和 `[cache]`;每个依赖都是 leanprover 或 leanprover-community 的 Git 仓库,或 Tau Ceti;工具链 | |
| 119 | +必须是发布版;不能有 `lakefile.lean`,不能提交 `.lake/` 下的文件。觉得哪条陈述有问题,开一个标题以“Ruling:”开头的 Issue。 | |
| 120 | + | |
| 121 | +## 自己编译 | |
| 122 | + | |
| 123 | +多数子任务不需要编译。需要的话: | |
| 124 | + | |
| 125 | +```sh | |
| 126 | +lake exe cache get # 依次取 Mathlib、Tau Ceti 和本证明的缓存,来自上游的服务器 | |
| 127 | +lake build | |
| 128 | +lake env lean scripts/PrintAxioms.lean # 五条定理用到的公理 | |
| 129 | +``` | |
| 130 | + | |
| 131 | +`lake exe cache get` 需要 Python 3.11 以上和 curl 7.71 以上,不需要凭据;改 Lean 源码之前先跑它。上游的缓存里有我们起点 | |
| 132 | +提交的编译输入对应的记录(2026-12-02 查);它在本项目的代码树里能不能恢复,本项目的 `main` 往前走之后还能不能作为基线 | |
| 133 | +恢复,都还没有试过。缓存省掉编译,但不证明任何事:上游自己的说明写着,缓存里的文件“were built from an unverified | |
| 134 | +third-party proof, and the cache does not verify anything”。从源码编译要几个小时:这一版的作者给的数字是 12 核、24 GB | |
| 135 | +内存一到两小时,上游的运行器完整重编约四个 CPU 小时(2026-12-01 从它的 CI 读出)。`build` 检验在本项目上要多久,还没有测 | |
| 136 | +(2026-12-02:它的镜像还在做)。Mathlib 和 Tau Ceti 要一起动:Tau Ceti 的缓存只对 `lakefile.toml` 里那个 Mathlib 提交有效。 | |
| 137 | + | |
| 138 | +Comparator 随工具链提供(Lean v4.35.0 起):`PATH` 上有 `bwrap` 和工具链自带的 `nanoda_bin` 时,在仓库根目录运行 | |
| 139 | +`lake comparator --config comparator.json`。`build` 检验跑的是同一条。 | |
| 140 | + | |
| 141 | +## 目录 | |
| 142 | + | |
| 143 | +`src/` 下 806 个 Lean 文件,连注释 484,789 行,其中代码约 30 万行。 | |
| 144 | + | |
| 145 | +- `src/Lib`(16 个文件夹,501 个文件):文献里已有、Mathlib 还没有的背景结果。它不引入 `src/New` 的任何东西。 | |
| 146 | +- `src/New`(8 个文件夹,303 个文件):论证的铺垫和各步,文件夹的顺序就是论证的顺序。主不等式在 | |
| 147 | + `src/New/Reduction/MainInequality.lean`,半平面形式在 `src/New/Reduction/OneSidedBound.lean`。 | |
| 148 | +- [`GUIDE.md`](GUIDE.md):从这里读起,有阅读顺序、术语表、各量的大小和约定。[`CONTENTS.md`](CONTENTS.md):每个文件和它的 | |
| 149 | + 标题。[`INDEX.md`](INDEX.md):结果和出处。[`REFERENCES.md`](REFERENCES.md):引用,以及哪些对照过原文。 | |
| 150 | +- `docs/`:本项目关于这份证明写下的东西:`exposition/`(写成数学的证明)、`audit/`、`statements/`、`zh/`。 | |
| 151 | +- `checks/`:本项目的 CI;`docker/`:`build` 所用的 Lean 镜像。`KNOWN.md`:已知的事,带日期。 | |
| 152 | + | |
| 153 | +## 许可 | |
| 154 | + | |
| 155 | +上游的文件,原样保留:[`LICENSE`](LICENSE)、[`NOTICE`](NOTICE)、[`ATTRIBUTION.md`](ATTRIBUTION.md)。 | |
+160 −0 UPSTREAM.md added View file
| @@ -0,0 +1,160 @@ | ||
| 1 | +# What upstream says | |
| 2 | + | |
| 3 | +This project starts from [leanprover-community/riemann-hypothesis](https://github.com/leanprover-community/riemann-hypothesis) at `630d1e43b442cab27717c3ebf94d218dea608374` (2026-12-01). Its README and AGENTS.md at that commit follow, unchanged; `README.md` and `AGENTS.md` here are this project's. | |
| 4 | + | |
| 5 | +## README.md | |
| 6 | + | |
| 7 | +### riemann-hypothesis | |
| 8 | + | |
| 9 | +A community-led effort to clean up and maintain a Lean formalization of the 2026 proofs of the Riemann Hypothesis and of GRH for Dirichlet L-functions. | |
| 10 | + | |
| 11 | +> [!CAUTION] | |
| 12 | +> This repo recently moved to a highly condensed version on November 25, 2026. Prior progress is preserved on the `alpoge` branch. | |
| 13 | + | |
| 14 | +The purpose of this repo is to create an artifact that is: | |
| 15 | + | |
| 16 | +- **accessible**: we want to improve build performance and modularity to enable researchers to feasibly engage with the proof even without access to massive amounts of compute. | |
| 17 | +- **readable**: we want to improve code quality, aspirationally to Mathlib levels. This includes lemma organization, formatting and idiomatic style, eliminating linter warnings, slop-free documentation, and more. | |
| 18 | +- **integrated with the community**: we would like to add bibliographic references to prior work where appropriate, and rely on existing formalization projects when possible. | |
| 19 | + | |
| 20 | +Please note: we are **not** looking for: | |
| 21 | + | |
| 22 | +- claims about your own machine's builds / comparator run | |
| 23 | +- adding files which are not necessary for the Riemann Hypothesis proof | |
| 24 | + | |
| 25 | +This work is taking place on the `main` branch, which is based on a copy of the readable | |
| 26 | +edition (`grh/`) of https://github.com/lsernau/grh-lean at commit 72fead102f663d5c7a407964a13dc0cf9d977207. | |
| 27 | + | |
| 28 | +The `alpoge` branch retains the progress the community made towards cleaning up the original version of the proof released by Levent Alpöge in the first few days before the aforementioned readable edition was released. | |
| 29 | + | |
| 30 | +The `original` branch preserves the first publicly-released version of the proof retrieved on 2026-11-20 from <https://alpo.ge/remark.pdf>. | |
| 31 | + | |
| 32 | +If you want to open the original proof without compiling it, see the repo | |
| 33 | +[riemann-hypothesis-original](https://github.com/homeowmorphism/riemann-hypothesis-original). | |
| 34 | +It keeps the published Lean source unchanged and provides a prebuilt cache for it. | |
| 35 | + | |
| 36 | +#### Theorem Statements | |
| 37 | + | |
| 38 | +[`src/Main.lean`](src/Main.lean) proves the following theorems: | |
| 39 | + | |
| 40 | +| Theorem | Statement | | |
| 41 | +|---|---| | |
| 42 | +| `riemannHypothesis` | Mathlib's `RiemannHypothesis` | | |
| 43 | +| `riemannZeta_eq_zero_re` | the same statement as `riemannHypothesis` but spelled out without Mathlib's definition of the statement | | |
| 44 | +| `LFunction_ne_zero_of_half_lt_re` | L(χ, s) ≠ 0 for Re s > 1/2, for every modulus and every Dirichlet character, except the trivial character at s = 1 | | |
| 45 | +| `LFunction_eq_zero_re` | every zero of L(χ, s) with 0 < Re s < 1 has Re s = 1/2 | | |
| 46 | +| `LFunction_eq_zero_re_of_isPrimitive` | the special case of `LFunction_eq_zero_re` for primitive characters | | |
| 47 | + | |
| 48 | +[`src/Statements.lean`](src/Statements.lean) provides the statements of all of these theorems, and only imports Mathlib to state them. It is imported by both [`src/Main.lean`](src/Main.lean) and [`Challenge.lean`](Challenge.lean) | |
| 49 | + | |
| 50 | +[`Challenge.lean`](Challenge.lean) imports *only* [`src/Statements.lean`](src/Statements.lean), and declares the same five theorems with `sorry` in place of the proofs. | |
| 51 | + | |
| 52 | +Comparator checks that `Main.lean` proves exactly those statements, that it uses no axioms other than `propext`, `Quot.sound` and | |
| 53 | +`Classical.choice`, and that Lean's kernel and nanoda both accept the proof. | |
| 54 | + | |
| 55 | +#### Cache | |
| 56 | + | |
| 57 | +``` | |
| 58 | +lake exe cache get | |
| 59 | +lake build | |
| 60 | +``` | |
| 61 | + | |
| 62 | +This needs Python 3.11 or newer and curl 7.71 or newer, with no credentials. The command restores | |
| 63 | +the Mathlib, Tau Ceti, and project caches in that order. Run it before editing the Lean sources | |
| 64 | +or build configuration so it can match the published build inputs. | |
| 65 | +`lake exe mathlib/cache get` fetches Mathlib alone. | |
| 66 | + | |
| 67 | +See [`CACHE.md`](CACHE.md) for details. | |
| 68 | + | |
| 69 | +#### Layout | |
| 70 | + | |
| 71 | +*For now, this section is copied from https://github.com/lsernau/grh-lean. It may be out of date and is subject to change.* | |
| 72 | + | |
| 73 | +About 300,000 lines of code; 433,000 non-blank lines with comments; 477,000 lines in all. | |
| 74 | +- `src/Lib` (495 files): background results, classed as known in the literature, that Mathlib lacks, with the steps of their proofs. It imports nothing from `src/New`. | |
| 75 | +- `src/New` (306 files): the set-up and the steps of the argument, in folders that follow its order. The main inequality is in `src/New/Reduction/MainInequality.lean`, the theorem in half-plane form in `src/New/Reduction/OneSidedBound.lean`. | |
| 76 | +- `src/Lib/Speed.lean` holds the main settings that apply to the whole development (instance priorities, `simp` lemmas taken out of the default set, one added `simp` lemma). With the file emptied, everything still compiled on Lean 4.33.1; on the current toolchain a few files rely on it (see its module note). `GUIDE.md` explains them. | |
| 77 | +- `GUIDE.md`: start here. It gives the reading order, a glossary, sizes and conventions. `CONTENTS.md`: every file with its title. `INDEX.md`: the results, with sources or related work and files. | |
| 78 | +- `REFERENCES.md` lists the citations and says which were compared with their sources. | |
| 79 | + | |
| 80 | +#### Acknowledgements | |
| 81 | + | |
| 82 | +Thanks to the Lean FRO and BAIF for providing resources to run CI here; others have contributed too, if you'd like acknowledgement here let @kim-em know. | |
| 83 | + | |
| 84 | +[`CONTRIBUTORS.md`](CONTRIBUTORS.md) lists everyone with a merged pull request. | |
| 85 | + | |
| 86 | +#### License | |
| 87 | + | |
| 88 | +The proof belongs to its author Levent Alpöge with Claude and was originally published without a license. The repo https://github.com/lsernau/grh-lean uses Apache 2.0, and so does this repo; see [`LICENSE`](LICENSE), [`NOTICE`](NOTICE) and [`ATTRIBUTION.md`](ATTRIBUTION.md). | |
| 89 | + | |
| 90 | +*Soon, we will re-integrate Formal Conjectures. This is out of date.* | |
| 91 | + | |
| 92 | +The declarations in `comparator/` that will be copied from | |
| 93 | +[formal-conjectures](https://github.com/google-deepmind/formal-conjectures) are copyright The Formal | |
| 94 | +Conjectures Authors, under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). | |
| 95 | +The files that hold them carry the notice. | |
| 96 | + | |
| 97 | +## AGENTS.md | |
| 98 | + | |
| 99 | +### AGENTS.md | |
| 100 | + | |
| 101 | +Read [README.md](README.md) and [GUIDE.md](GUIDE.md) first. `main` is the readable edition of the | |
| 102 | +proof, and what we want now is a proof that people can read. A change that makes the code shorter | |
| 103 | +or faster but harder to read is not welcome. | |
| 104 | + | |
| 105 | +If you have agent time to spare and no particular change in mind, work on the GRH roadmap of | |
| 106 | +[Tau Ceti](https://github.com/TauCetiProject/TauCeti) instead. | |
| 107 | + | |
| 108 | +#### Changes we want | |
| 109 | + | |
| 110 | +- Using a result from Mathlib or Tau Ceti in place of our own proof of it, and deleting ours. | |
| 111 | + Check that the statements agree, hypotheses included. If the library states it in another form, | |
| 112 | + keep our lemma as a short wrapper rather than adding a conversion at every caller. | |
| 113 | +- Deleting declarations that nothing uses. | |
| 114 | +- Proving once, as a lemma, an argument that appears several times, and using it everywhere. | |
| 115 | +- Splitting a long proof into lemmas with names and docstrings. A comment that explains a step | |
| 116 | + moves with it. | |
| 117 | +- A more general lemma in place of an old one, if its proof is about as easy. Move the callers to | |
| 118 | + it and delete the old one. | |
| 119 | +- Fixing linter warnings, wrong docstrings and open issues. A docstring says what its declaration | |
| 120 | + states, including both directions of an `iff`. | |
| 121 | + | |
| 122 | +#### Changes we don't want | |
| 123 | + | |
| 124 | +- Inlining a lemma into its only caller, or folding helper lemmas or named `have` steps into one | |
| 125 | + long proof. A step with a name still tells the reader what it proves. | |
| 126 | +- Cutting an `iff` down to one direction, or dropping conclusions from a lemma, because no caller | |
| 127 | + needs them. | |
| 128 | +- Replacing `simp` with a long `simp only [...]` list, or expanding a tactic into many | |
| 129 | + hand-written steps, to save a second or a few lines. | |
| 130 | +- A `simp` or other flexible tactic followed by steps that depend on the exact form it leaves. | |
| 131 | + Make it the last step, or use `simp only`. | |
| 132 | +- A new or wider `seal` without a timing that shows it is needed. | |
| 133 | +- Adding or changing a reference to the literature without checking it against the source. Say | |
| 134 | + which edition you checked and give the theorem number. | |
| 135 | + | |
| 136 | +#### Pull requests | |
| 137 | + | |
| 138 | +Keep each pull request to one change; fixing linter warnings in the files you edit doesn't count | |
| 139 | +as a second one. Check that it compiles (`lake exe cache get`, then `lake build`) before you open | |
| 140 | +it, but don't write in it that it builds or that nothing else changed: CI checks the build. Titles | |
| 141 | +follow [Mathlib's convention](https://leanprover-community.github.io/contribute/commit.html). In | |
| 142 | +the description, say in two or three sentences what the change does and why it makes the proof | |
| 143 | +easier to read, and keep the title and description in step with the diff when you push more | |
| 144 | +commits. Leave out timings and heartbeat counts unless speed is the reason for the change; then | |
| 145 | +give the few numbers a maintainer needs to decide, per declaration where you can, and say how you | |
| 146 | +measured them. | |
| 147 | + | |
| 148 | +If you want to make the same kind of change in many places, open one pull request first and wait | |
| 149 | +for a maintainer to say we want it before you open the others. | |
| 150 | + | |
| 151 | +A pull request is merged only after a reviewer (Triage role or more) has approved its current head | |
| 152 | +commit. When a reviewer hands it back to you with the `awaiting-author` label, make the changes | |
| 153 | +and then comment `ready`, with nothing else in the comment. | |
| 154 | + | |
| 155 | +#### Batches | |
| 156 | + | |
| 157 | +A batch takes only pull requests that a reviewer has approved on their current head commit, and | |
| 158 | +none labelled `awaiting-author` or held by a maintainer. Merge each with its own merge commit. To | |
| 159 | +take one out, rebuild the batch without it and force-push; don't revert its merge commit. List the | |
| 160 | +pull requests you left out in the batch's description, with the reason for each. | |
+27 −0 checks/build.json added View file
| @@ -0,0 +1,27 @@ | ||
| 1 | +{ | |
| 2 | + "permitted_axioms": [ | |
| 3 | + "propext", | |
| 4 | + "Classical.choice", | |
| 5 | + "Quot.sound" | |
| 6 | + ], | |
| 7 | + "comparator_command": [ | |
| 8 | + "lake", | |
| 9 | + "comparator", | |
| 10 | + "--config" | |
| 11 | + ], | |
| 12 | + "comparator": [ | |
| 13 | + "comparator.json" | |
| 14 | + ], | |
| 15 | + "comparator_success": [ | |
| 16 | + "nanoda kernel accepts the solution", | |
| 17 | + "Lean default kernel accepts the solution", | |
| 18 | + "Your solution is okay!" | |
| 19 | + ], | |
| 20 | + "timeout": 21600, | |
| 21 | + "frozen": [ | |
| 22 | + "Challenge.lean", | |
| 23 | + "src/Statements.lean" | |
| 24 | + ], | |
| 25 | + "in_place": true, | |
| 26 | + "replay": "round" | |
| 27 | +} | |
+386 −0 checks/build.py added View file
| @@ -0,0 +1,386 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""The `build` check: the pushed commit compiles, uses no `sorry`, its theorems depend only on the permitted axioms, | |
| 3 | +and Comparator accepts it against the approved challenge. | |
| 4 | + | |
| 5 | +Usage: build.py <commit's tree> [<build.json>] (BUILD_REPLAY=1: with Comparator even where build.json has | |
| 6 | + "replay": "round", see below) | |
| 7 | + | |
| 8 | +This is leanprover-community/riemann-hypothesis's `build.yml` ("lake build", the merge queue's required check), made a | |
| 9 | +check of this site, plus the Comparator run its README asks for. It runs in the project's Lean image (`docker/`), with | |
| 10 | +no network, on the site's runner, as root in the runner's container. | |
| 11 | + | |
| 12 | +The commit's Lean is code the check runs: an `#eval`, an `initialize` or an elaborator in it runs while Lean compiles | |
| 13 | +the file or imports it, and can print anything, including Comparator's success lines, or rewrite `lake` itself. So | |
| 14 | +nothing the commit's build prints is trusted, and none of its code runs as root: | |
| 15 | + | |
| 16 | +1. the approved version (the checkout this script is in, PROOF_APPROVED to override) is compiled as root, from the | |
| 17 | + image's `.lake`, and each Comparator configuration's challenge module is exported (`export_command`) before | |
| 18 | + anything of the commit runs. Its definitions, not the commit's, are what the statements mean; | |
| 19 | +2. the commit's tree is copied to a folder of its own and given the image's `.lake` (the dependencies, read-only, and | |
| 20 | + the build of the approved main, made when the image was built): Lake then rebuilds only what the commit changed. | |
| 21 | + As `nobody`, it runs `lake build`, and `lake build` of every library the approved lakefile.toml declares (the | |
| 22 | + default targets are a key a pull request may change), which must end without error and with no module reporting a | |
| 23 | + declaration that uses `sorry` except the challenge's own files (`frozen` in build.json: they state the theorems | |
| 24 | + with `sorry` on purpose); then it exports each configuration's solution module, and the theorems of build.json; | |
| 25 | +3. every process of `nobody` is killed; then, as `nobody`, Comparator judges each export pair: the statements and the | |
| 26 | + definitions they use as approved, no axiom beyond the permitted ones (a `sorry` is the axiom `sorryAx`), and a | |
| 27 | + replay through Lean's kernel (and nanoda, where the configuration asks). The theorems of build.json are judged the | |
| 28 | + same way against their own export: axioms and kernel. The judge reads text exports only and never loads an `.olean` | |
| 29 | + of the commit, so what it prints is the verdict; | |
| 30 | +4. the commit's `lean-toolchain` must be the image's: a bump needs a new image (docker/README.md). | |
| 31 | + | |
| 32 | +Two Comparators are served (`comparator_kind` in build.json). "lake", the default: the toolchain's own (Lean 4.35 and | |
| 33 | +later), `lake comparator --challenge-from-export … --solution-from-export … --inadvisably-no-sandbox`. "standalone": | |
| 34 | +leanprover/comparator as a binary, for the toolchains before it, which builds and exports by itself through `landrun` | |
| 35 | +and has no way to be handed exports. It is given one: COMPARATOR_LANDRUN names a stand-in this script writes, which | |
| 36 | +does nothing for `lake build`, prints step 1's or step 2's export for `lean4export <module>`, and starts an external | |
| 37 | +kernel (nanoda_bin) as it is; Comparator's own comparison, axiom walk and kernels then run as upstream wrote them. | |
| 38 | +Neither Comparator's own sandbox is what holds the commit here. bwrap cannot start in the runner's container (no user | |
| 39 | +namespaces). landrun can (Landlock, measured on the production host 12-02), but upstream's guarantee needs three things | |
| 40 | +the check does not have: nothing of the commit compiled before Comparator runs, a user who is not root, and no | |
| 41 | +AF_UNIX (kernels before 7.1). Step 2, as `nobody`, stands in for both. | |
| 42 | + | |
| 43 | +Where the build is kept. With `"in_place": true` and an image whose `.lake/build` belongs to `nobody`, both sides use | |
| 44 | +that folder itself: root first, for the approved challenge, then the commit, which may write anything there; nothing | |
| 45 | +is read from it as approved after that, and the container is thrown away with what it wrote. A job then costs the | |
| 46 | +disk of what it recompiled. Without it the build is copied for each side, as before (a 600 MB build: fine; 40 GB: | |
| 47 | +not). | |
| 48 | + | |
| 49 | +When Comparator runs. A replay sends the whole proof through a kernel on one core: minutes for a small library, hours | |
| 50 | +for a large one. With `"replay": "round"` in build.json a push gets step 2's build and `sorry` scan only, and the last | |
| 51 | +line says so: that is the commit's own Lean reporting on itself, a filter and not a verdict. The replay (all four | |
| 52 | +steps) is then run once per maintainer round, on main or on a batch of pull requests, with BUILD_REPLAY=1; its result | |
| 53 | +is filed as a report. Without the key every push is replayed. | |
| 54 | + | |
| 55 | +The `sorry` scan of step 2 reads the commit's own build log, which the commit's code can write to: it catches an | |
| 56 | +honest `sorry` anywhere in the library, and a hidden one cannot reach a judged theorem, since step 3 reads the axioms | |
| 57 | +from the exports. Run as another user than root (tests, a machine of one's own) it does the same steps without | |
| 58 | +switching to `nobody`. | |
| 59 | + | |
| 60 | +Each step's wall time is printed as it ends (`-- … s`). Its last line says what held, or the first thing that did | |
| 61 | +not. Exit 0 passes, 1 fails. | |
| 62 | +""" | |
| 63 | + | |
| 64 | +from __future__ import annotations | |
| 65 | + | |
| 66 | +import json | |
| 67 | +import os | |
| 68 | +import re | |
| 69 | +import shlex | |
| 70 | +import shutil | |
| 71 | +import subprocess | |
| 72 | +import sys | |
| 73 | +import tempfile | |
| 74 | +import time | |
| 75 | +import tomllib | |
| 76 | +from pathlib import Path | |
| 77 | + | |
| 78 | +SORRY = re.compile(r"declaration uses ['`]sorry['`]") | |
| 79 | +# where a warning comes from: "warning: Challenge.lean:2:8: declaration uses `sorry`" (a path, possibly ./ or absolute) | |
| 80 | +WHERE = re.compile(r"(?:^|\s)(?:\./)?([^\s:]+\.lean):\d+:\d+:") | |
| 81 | +NOBODY = 65534 # nobody:nogroup in Ubuntu | |
| 82 | +# What is exported with the theorems, as `lake comparator` asks when it exports by itself (Lean 4.35.0, | |
| 83 | +# src/lake/Lake/CLI/Check.lean: builtinTargets, primitiveTargets): the kernel's built-in constants, Quot when Quot.sound | |
| 84 | +# is permitted, then the configuration's theorems, axioms and definitions. | |
| 85 | +PRIMITIVES = [ | |
| 86 | + "Nat.add", "Nat.sub", "Nat.mul", "Nat.pow", "Nat.gcd", "Nat.div", "Nat.mod", "Nat.beq", "Nat.ble", "Nat.land", | |
| 87 | + "Nat.lor", "Nat.xor", "Nat.shiftLeft", "Nat.shiftRight", "String.ofList", "Char.ofNat", "List", "eagerReduce", | |
| 88 | + "Nat", "String", "String.mk", "Char", "optParam", "autoParam", "semiOutParam", "outParam", | |
| 89 | +] | |
| 90 | +QUOT = ["Quot", "Quot.mk", "Quot.lift", "Quot.ind"] | |
| 91 | +NO_SANDBOX = "WARNING: Sandbox disabled, this run is not trustworthy." | |
| 92 | + | |
| 93 | + | |
| 94 | +class Wrong(Exception): | |
| 95 | + pass | |
| 96 | + | |
| 97 | + | |
| 98 | +ROOT = os.geteuid() == 0 | |
| 99 | + | |
| 100 | + | |
| 101 | +def toolchain_bin(cwd: Path) -> str: | |
| 102 | + """The toolchain's own bin folder (elan puts only lean, lake and leanchecker on PATH; Comparator looks nanoda_bin | |
| 103 | + up on PATH), or nothing where elan is not there.""" | |
| 104 | + try: | |
| 105 | + return str(Path(subprocess.run(["elan", "which", "lean"], cwd=cwd, capture_output=True, text=True, timeout=60, | |
| 106 | + check=True).stdout.strip()).parent) | |
| 107 | + except (OSError, subprocess.SubprocessError): | |
| 108 | + return "" | |
| 109 | + | |
| 110 | + | |
| 111 | +BIN = "" # set in main: the toolchain's bin folder, first on every PATH below | |
| 112 | + | |
| 113 | + | |
| 114 | +def env_for(home: Path) -> dict[str, str]: | |
| 115 | + """What a process of the commit or the judge sees: the image's PATH and elan, a HOME of its own, and git told | |
| 116 | + that the image's repositories, which root owns, are safe to read (Lake asks git about each package).""" | |
| 117 | + keep = {k: v for k, v in os.environ.items() if k in ("PATH", "ELAN_HOME", "LANG", "LC_ALL", "LEAN_NUM_THREADS")} | |
| 118 | + if BIN: | |
| 119 | + keep["PATH"] = f"{BIN}:{keep.get('PATH', '/usr/bin:/bin')}" | |
| 120 | + return {**keep, "HOME": str(home), "GIT_CONFIG_COUNT": "1", "GIT_CONFIG_KEY_0": "safe.directory", | |
| 121 | + "GIT_CONFIG_VALUE_0": "*"} | |
| 122 | + | |
| 123 | + | |
| 124 | +def run(cmd: list[str], cwd: Path, timeout: int, log: Path | None = None, *, nobody: bool = False, | |
| 125 | + env: dict[str, str] | None = None, out=None) -> str: | |
| 126 | + """Run a command, keep what it printed in `log`, and fail with its last lines if it fails. With `out`, its standard | |
| 127 | + output goes to that file instead. With `nobody` (and as root), it runs as nobody, with no supplementary group.""" | |
| 128 | + print(f"$ {' '.join(cmd)}", flush=True) | |
| 129 | + who = {"user": NOBODY, "group": NOBODY, "extra_groups": []} if nobody and ROOT else {} | |
| 130 | + began = time.monotonic() | |
| 131 | + try: | |
| 132 | + p = subprocess.run(cmd, cwd=cwd, stdout=out or subprocess.PIPE, stderr=subprocess.STDOUT if out is None else subprocess.PIPE, | |
| 133 | + text=True, timeout=timeout, env=env, **who) | |
| 134 | + except subprocess.TimeoutExpired: | |
| 135 | + raise Wrong(f"{' '.join(cmd)} took longer than {timeout} s") | |
| 136 | + said = (p.stdout if out is None else p.stderr) or "" | |
| 137 | + if log: | |
| 138 | + log.write_text(said, encoding="utf-8") | |
| 139 | + tail = "\n".join(said.replace(NO_SANDBOX, "").strip().splitlines()[-25:]) | |
| 140 | + if tail: | |
| 141 | + print(tail, flush=True) | |
| 142 | + print(f"-- {time.monotonic() - began:.0f} s", flush=True) | |
| 143 | + if p.returncode != 0: | |
| 144 | + # with the first error it gave (Lean's, or Comparator's verdict), so the last line says why | |
| 145 | + why = next((line.strip() for line in said.splitlines() if re.match(r"(error|uncaught exception)\b", line.strip()) | |
| 146 | + and line.strip() != "error: build failed"), "") | |
| 147 | + raise Wrong(f"{' '.join(cmd)} ended with exit {p.returncode}" + (f": {why[:300]}" if why else "")) | |
| 148 | + return said | |
| 149 | + | |
| 150 | + | |
| 151 | +def kill_nobody() -> None: | |
| 152 | + """End every process of nobody at once: kill -1 from nobody reaches exactly those, itself included.""" | |
| 153 | + if ROOT: | |
| 154 | + subprocess.run(["bash", "-c", "kill -KILL -1"], user=NOBODY, group=NOBODY, extra_groups=[], | |
| 155 | + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | |
| 156 | + | |
| 157 | + | |
| 158 | +def give_lake(base: Path, project: Path, in_place: bool = False) -> None: | |
| 159 | + """The image's .lake for a project: its packages shared and read-only (a symbolic link), the rest a copy; in place, | |
| 160 | + the build is shared too, and whoever builds in the project writes into the image's own folder.""" | |
| 161 | + (project / ".lake").mkdir() | |
| 162 | + for entry in (base / ".lake").iterdir(): | |
| 163 | + if entry.name == "packages" or (in_place and entry.name == "build"): | |
| 164 | + (project / ".lake" / entry.name).symlink_to(entry) | |
| 165 | + elif entry.is_dir(): | |
| 166 | + shutil.copytree(entry, project / ".lake" / entry.name, symlinks=True) | |
| 167 | + else: | |
| 168 | + shutil.copy2(entry, project / ".lake" / entry.name) | |
| 169 | + | |
| 170 | + | |
| 171 | +def chown_nobody(folder: Path) -> None: | |
| 172 | + """Give a folder and what is in it to nobody. What is nobody's already is left alone: in a folder of the image | |
| 173 | + itself, a chown copies the file into the container.""" | |
| 174 | + if ROOT: | |
| 175 | + for here, dirs, files in os.walk(folder): | |
| 176 | + for path in [Path(here)] + [Path(here) / name for name in files + [d for d in dirs if (Path(here) / d).is_symlink()]]: | |
| 177 | + if os.lstat(path).st_uid != NOBODY: | |
| 178 | + os.lchown(path, NOBODY, NOBODY) | |
| 179 | + | |
| 180 | + | |
| 181 | +def targets(config: dict) -> list[str]: | |
| 182 | + axioms = config["permitted_axioms"] | |
| 183 | + return (QUOT if "Quot.sound" in axioms else []) + config.get("theorem_names", []) + axioms + PRIMITIVES \ | |
| 184 | + + config.get("definition_names", []) | |
| 185 | + | |
| 186 | + | |
| 187 | +EXPORT = ["lake", "env", "leanexport"] # build.json's export_command, set in main | |
| 188 | + | |
| 189 | + | |
| 190 | +def export(module: str, names: list[str], dest: Path, cwd: Path, timeout: int, nobody: bool, env: dict[str, str]) -> None: | |
| 191 | + with dest.open("w") as f: | |
| 192 | + run([*EXPORT, module, "--", *names], cwd, timeout, nobody=nobody, env=env, out=f) | |
| 193 | + print(f"-- {dest.name}: {dest.stat().st_size / 1e6:.0f} MB", flush=True) | |
| 194 | + | |
| 195 | + | |
| 196 | +def judge_command(spec: dict, config: Path, challenge: Path, solution: Path, modules: tuple[str, str], folder: Path) -> tuple[list[str], dict[str, str]]: | |
| 197 | + """How Comparator is started on two exports, and what is added to its environment.""" | |
| 198 | + if spec.get("comparator_kind", "lake") != "standalone": | |
| 199 | + return spec["comparator_command"] + [str(config), "--challenge-from-export", str(challenge), "--solution-from-export", str(solution), | |
| 200 | + "--inadvisably-no-sandbox"], {} | |
| 201 | + # the standalone Comparator starts everything through landrun: this stands in for it (the module docstring says why) | |
| 202 | + for module in modules: | |
| 203 | + if not re.fullmatch(r"[\w.'«»]+", module): | |
| 204 | + raise Wrong(f"{module!r} is not a module name") | |
| 205 | + stand_in = folder / f"{config.stem}-landrun" | |
| 206 | + serve = "".join(f" {shlex.quote('lean4export ' + m)}) exec cat {shlex.quote(str(e))} ;;\n" for m, e in dict(zip(modules, (challenge, solution))).items()) | |
| 207 | + stand_in.write_text('#!/bin/sh\n# in landrun\'s place: the builds are done, and the exports made\n' | |
| 208 | + 'while [ $# -gt 0 ] && [ "$1" != -- ]; do shift; done\n[ $# -gt 1 ] || exit 2\nshift\n' | |
| 209 | + f'case "$1 $2" in\n "lake build") exit 0 ;;\n{serve} lake\\ *|lean4export\\ *) echo "not served: $*" >&2; exit 2 ;;\nesac\nexec "$@"\n') | |
| 210 | + stand_in.chmod(0o755) | |
| 211 | + (folder / ".lake").mkdir(exist_ok=True) # Comparator makes it in its folder otherwise, which nobody cannot | |
| 212 | + return spec["comparator_command"] + [str(config)], {"COMPARATOR_LANDRUN": str(stand_in)} | |
| 213 | + | |
| 214 | + | |
| 215 | +def imports_of(path: Path) -> list[str]: | |
| 216 | + """The modules a file's header imports.""" | |
| 217 | + found = [] | |
| 218 | + for line in path.read_text(encoding="utf-8").splitlines(): | |
| 219 | + m = re.match(r"\s*(?:public\s+)?import\s+(.+)", line) | |
| 220 | + if m: | |
| 221 | + found += m.group(1).split() | |
| 222 | + elif line.strip() and not line.lstrip().startswith(("--", "/-", "module", "prelude")): | |
| 223 | + break | |
| 224 | + return found | |
| 225 | + | |
| 226 | + | |
| 227 | +def main(argv: list[str]) -> int: | |
| 228 | + if len(argv) < 2: | |
| 229 | + print(__doc__.strip().splitlines()[2]) | |
| 230 | + return 2 | |
| 231 | + tree = Path(argv[1]).resolve() | |
| 232 | + spec = json.loads((Path(argv[2]) if len(argv) > 2 else Path(__file__).with_name("build.json")).read_text(encoding="utf-8")) | |
| 233 | + approved = Path(os.environ.get("PROOF_APPROVED") or Path(__file__).resolve().parents[1]) | |
| 234 | + base = Path(os.environ.get("PROOF_BASE", "/opt/proof")) | |
| 235 | + timeout = int(spec.get("timeout", 6 * 3600)) | |
| 236 | + logs = Path(os.environ.get("BUILD_LOGS", ".")).resolve() | |
| 237 | + logs.mkdir(parents=True, exist_ok=True) | |
| 238 | + work = Path(tempfile.mkdtemp(prefix="build-")) | |
| 239 | + os.chmod(work, 0o711) # nobody passes through to its own folders, and reads nothing else here | |
| 240 | + try: | |
| 241 | + if not (tree / "lakefile.toml").is_file(): | |
| 242 | + print("Nothing to check yet: the commit has no lakefile.toml.") | |
| 243 | + return 0 | |
| 244 | + if not (base / ".lake").is_dir(): | |
| 245 | + raise Wrong(f"{base}/.lake is not there: this check runs in the project's Lean image (docker/README.md)") | |
| 246 | + # 4. the image's toolchain (read, not run) | |
| 247 | + want = (tree / "lean-toolchain").read_text(encoding="utf-8").strip() | |
| 248 | + have = (base / "lean-toolchain").read_text(encoding="utf-8").strip() | |
| 249 | + if want != have: | |
| 250 | + raise Wrong(f"the commit asks for {want}; the image has {have}: a toolchain bump needs a new image (docker/README.md)") | |
| 251 | + global BIN, EXPORT | |
| 252 | + BIN = toolchain_bin(base) | |
| 253 | + # Lake starts a `lean` for every core it sees, and the runner's --cpus is a share of time, not a count of | |
| 254 | + # cores: on a 128-core host a job of 4 CPUs would start 128 (lean-poincare, 12-02) | |
| 255 | + if os.environ.get("SLURM_CPUS_PER_TASK"): | |
| 256 | + os.environ.setdefault("LEAN_NUM_THREADS", os.environ["SLURM_CPUS_PER_TASK"]) | |
| 257 | + EXPORT = spec.get("export_command", EXPORT) | |
| 258 | + configs = [(name, json.loads((approved / name).read_text(encoding="utf-8"))) for name in spec.get("comparator", [])] | |
| 259 | + theorems = spec.get("theorems", []) if spec.get("axioms_file") else [] | |
| 260 | + # a push of a project that replays once a round gets the build and its own account of the axioms, no judge | |
| 261 | + replay = spec.get("replay", "push") != "round" or os.environ.get("BUILD_REPLAY") == "1" | |
| 262 | + in_place = bool(spec.get("in_place")) | |
| 263 | + built = base / ".lake" / "build" | |
| 264 | + if in_place and ROOT and os.stat(built).st_uid != NOBODY: | |
| 265 | + raise Wrong(f"{built} is not nobody's: build.json's in_place needs an image made for it (docker/README.md)") | |
| 266 | + judge = work / "judge" | |
| 267 | + judge.mkdir() | |
| 268 | + # 1. the approved challenges, as root, before anything of the commit runs | |
| 269 | + if configs and replay: | |
| 270 | + mine = work / "approved" | |
| 271 | + # (not the commit's tree, nor the job's logs: on the runner both sit in the approved checkout, /work) | |
| 272 | + shutil.copytree(approved, mine, symlinks=True, ignore=lambda d, names: [n for n in names if n in (".git", ".lake") | |
| 273 | + or (Path(d) / n).resolve() in (tree, logs)]) | |
| 274 | + give_lake(base, mine, in_place) | |
| 275 | + for i, (name, config) in enumerate(configs): | |
| 276 | + run(["lake", "build", config["challenge_module"]], mine, timeout, logs / f"challenge-{i}.log") | |
| 277 | + export(config["challenge_module"], targets(config), judge / f"challenge-{i}.export", mine, timeout, False, None) | |
| 278 | + if in_place: | |
| 279 | + chown_nobody(built) # what root compiled there, the commit's Lake may have to write again | |
| 280 | + # 2. the commit, as nobody, in a folder of its own. In place, the image's build is from here on the commit's: | |
| 281 | + # nothing below reads it as approved | |
| 282 | + proof, home, solve = work / "proof", work / "home", work / "solve" | |
| 283 | + shutil.copytree(tree, proof, symlinks=True, ignore=shutil.ignore_patterns(".git", ".lake")) | |
| 284 | + give_lake(base, proof, in_place) | |
| 285 | + for folder in (home, solve): | |
| 286 | + folder.mkdir() | |
| 287 | + for folder in (proof, home, solve): | |
| 288 | + chown_nobody(folder) | |
| 289 | + env = env_for(home) | |
| 290 | + try: | |
| 291 | + out = run(["lake", "build"], proof, timeout, logs / "build.log", nobody=True, env=env) | |
| 292 | + # and every library the approved lakefile declares, whatever the commit's defaultTargets say (a key a pull | |
| 293 | + # request may change): a proof in a library left out of the default build was never compiled, and passed | |
| 294 | + # (12-01, Goldbach: Open/<Name>.lean, its library without globs) | |
| 295 | + approved_lakefile = approved / "lakefile.toml" | |
| 296 | + libs = [lib["name"] for lib in tomllib.loads(approved_lakefile.read_text(encoding="utf-8")).get("lean_lib", [])] if approved_lakefile.exists() else [] | |
| 297 | + if libs: | |
| 298 | + out += "\n" + run(["lake", "build", *libs], proof, timeout, logs / "build-libs.log", nobody=True, env=env) | |
| 299 | + frozen = tuple(spec.get("frozen", [])) | |
| 300 | + | |
| 301 | + def allowed(line: str) -> bool: | |
| 302 | + m = WHERE.search(line) | |
| 303 | + if not m: | |
| 304 | + return False | |
| 305 | + path = os.path.normpath(m.group(1)) # a library with srcDir "src" names src/../Challenge.lean | |
| 306 | + path = path[len(str(proof)) + 1:] if path.startswith(str(proof) + "/") else path | |
| 307 | + return path in frozen | |
| 308 | + sorries = [line for line in out.splitlines() if SORRY.search(line) and not allowed(line)] | |
| 309 | + if sorries: | |
| 310 | + print("\n".join(sorries[:20])) | |
| 311 | + raise Wrong(f"the build reports {len(sorries)} declaration(s) that use sorry") | |
| 312 | + reported = 0 | |
| 313 | + if not replay: | |
| 314 | + # what the commit's own Lean says its theorems rest on: a filter (the commit's code runs in that Lean), | |
| 315 | + # which the round's replay does not rely on | |
| 316 | + names = [t for _, config in configs for t in config.get("theorem_names", [])] + theorems | |
| 317 | + modules = [config["solution_module"] for _, config in configs] + (imports_of(approved / spec["axioms_file"]) if theorems else []) | |
| 318 | + (solve / "ShoalAxioms.lean").write_text("".join(f"import {m}\n" for m in dict.fromkeys(modules)) + "".join(f"#print axioms {t}\n" for t in names)) | |
| 319 | + chown_nobody(solve) | |
| 320 | + out = run(["lake", "env", "lean", str(solve / "ShoalAxioms.lean")], proof, timeout, logs / "axioms.log", nobody=True, env=env) if names else "" | |
| 321 | + for t in names: | |
| 322 | + found = re.findall(rf"'{re.escape(t)}' (does not depend on any axioms|depends on axioms: \[([^\]]*)\])", out) | |
| 323 | + extra = sorted({a for _, listed in found for a in listed.replace(",", " ").split()} - set(spec["permitted_axioms"])) | |
| 324 | + if extra: | |
| 325 | + raise Wrong(f"{t} depends on {', '.join(extra)}: only {', '.join(spec['permitted_axioms'])} are permitted") | |
| 326 | + if not found: | |
| 327 | + raise Wrong(f"Lean did not say which axioms {t} depends on") | |
| 328 | + reported, configs, theorems = len(names), [], [] | |
| 329 | + for i, (name, config) in enumerate(configs): | |
| 330 | + export(config["solution_module"], targets(config), solve / f"solution-{i}.export", proof, timeout, True, env) | |
| 331 | + if theorems: | |
| 332 | + # the theorems, in scope through the approved axioms file's imports, compiled as a module of their own | |
| 333 | + (solve / "ShoalTheorems.lean").write_text("".join(f"import {m}\n" for m in imports_of(approved / spec["axioms_file"]))) | |
| 334 | + chown_nobody(solve) | |
| 335 | + run(["lake", "env", "lean", "-R", str(solve), "-o", str(solve / "ShoalTheorems.olean"), str(solve / "ShoalTheorems.lean")], | |
| 336 | + proof, timeout, logs / "theorems.log", nobody=True, env=env) | |
| 337 | + config = {"permitted_axioms": spec["permitted_axioms"], "theorem_names": theorems} | |
| 338 | + export("ShoalTheorems", targets(config), solve / "theorems.export", proof, timeout, True, | |
| 339 | + {**env, "LEAN_PATH": str(solve)}) | |
| 340 | + finally: | |
| 341 | + kill_nobody() | |
| 342 | + # 3. the judge, as nobody, on the exports alone | |
| 343 | + for i, (name, config) in enumerate(configs): | |
| 344 | + # the configuration as parsed, where nobody can read it: the runner's job folder is closed to others (12-01) | |
| 345 | + mine_config = judge / f"{i}-{Path(name).name}" | |
| 346 | + mine_config.write_text(json.dumps(config)) | |
| 347 | + cmd, more = judge_command(spec, mine_config, judge / f"challenge-{i}.export", solve / f"solution-{i}.export", | |
| 348 | + (config["challenge_module"], config["solution_module"]), judge) | |
| 349 | + out = run(cmd, judge, timeout, logs / f"comparator-{i}.log", nobody=True, env={**env_for(judge), **more}) | |
| 350 | + missing = [s for s in spec["comparator_success"] if s not in out] | |
| 351 | + if missing: | |
| 352 | + raise Wrong(f"Comparator on {name} did not say: {missing[0]}") | |
| 353 | + if theorems: | |
| 354 | + # Comparator with the theorems' export as both sides: the statements trivially agree, so what it judges is | |
| 355 | + # the axioms and the kernel's replay | |
| 356 | + gen = judge / "theorems.json" | |
| 357 | + gen.write_text(json.dumps({"challenge_module": "ShoalTheorems", "solution_module": "ShoalTheorems", "theorem_names": theorems, | |
| 358 | + "permitted_axioms": spec["permitted_axioms"]})) | |
| 359 | + cmd, more = judge_command(spec, gen, solve / "theorems.export", solve / "theorems.export", ("ShoalTheorems", "ShoalTheorems"), judge) | |
| 360 | + out = run(cmd, judge, timeout, logs / "axioms.log", nobody=True, env={**env_for(judge), **more}) | |
| 361 | + if "Your solution is okay!" not in out: | |
| 362 | + raise Wrong("Comparator did not accept the theorems' axioms") | |
| 363 | + said = ["lake build passes with no sorry"] | |
| 364 | + if reported: | |
| 365 | + said.append(f"{reported} theorem(s) report {', '.join(spec['permitted_axioms'])} only") | |
| 366 | + if not replay: | |
| 367 | + said.append("not replayed: Comparator judges this project once per maintainer round") | |
| 368 | + if theorems: | |
| 369 | + said.append(f"{len(theorems)} theorem(s) on {', '.join(spec['permitted_axioms'])} only") | |
| 370 | + if configs: | |
| 371 | + said.append(f"Comparator accepts {', '.join(name for name, _ in configs)}") | |
| 372 | + print("ok: " + "; ".join(said)) | |
| 373 | + return 0 | |
| 374 | + except Wrong as e: | |
| 375 | + print(f"FAILED: {e}") | |
| 376 | + return 1 | |
| 377 | + except (OSError, ValueError, KeyError) as e: | |
| 378 | + print(f"FAILED: {e}") | |
| 379 | + return 1 | |
| 380 | + finally: | |
| 381 | + kill_nobody() | |
| 382 | + shutil.rmtree(work, ignore_errors=True) | |
| 383 | + | |
| 384 | + | |
| 385 | +if __name__ == "__main__": | |
| 386 | + sys.exit(main(sys.argv)) | |
+15 −0 checks/build.sbatch added View file
| @@ -0,0 +1,15 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=lake-build | |
| 3 | +#SBATCH --partition=lean | |
| 4 | +#SBATCH --time=01:00:00 | |
| 5 | +#SBATCH --cpus-per-task=4 | |
| 6 | +#SBATCH --mem=16G | |
| 7 | +# lake build (upstream's build.yml), the sorry and axiom gates, and Comparator, on the pushed commit ($SS_INPUT), in the | |
| 8 | +# project's Lean image (docker/) with no network. A push gets the build and the gates (main: 17 s, 1 GB at 4 CPUs, | |
| 9 | +# 12-02). Comparator's replay runs once per maintainer round with BUILD_REPLAY=1 ("replay": "round" in build.json): on | |
| 10 | +# the production host on 12-02 it exported 4.7 GB in 4 min, nanoda took ~10 min, and Lean's kernel had run 90 min and | |
| 11 | +# held 62 GB without a verdict when the run was stopped. These limits are the push's, not the replay's. | |
| 12 | +# The approved checks/build.py and checks/build.json say what is run; the image holds the toolchain, the dependencies | |
| 13 | +# and a build of the approved main, so only what the commit changed is rebuilt. Logs go beside the job's output. | |
| 14 | +set -euo pipefail | |
| 15 | +BUILD_LOGS="$PWD/logs" python3 -I checks/build.py "$SS_INPUT" checks/build.json | |
+221 −0 checks/challenge.py added View file
| @@ -0,0 +1,221 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""The `challenge` check: a push may change how the theorems are proved, never what is proved or how it is judged. | |
| 3 | + | |
| 4 | +Usage: challenge.py <commit's tree> [<frozen.json>] | |
| 5 | + | |
| 6 | +This is leanprover-community/riemann-hypothesis's `challenge-files.yml` ("Comparator challenge files and build | |
| 7 | +configuration are unchanged"), made a check of this site. Upstream compares a pull request's head with the commit it | |
| 8 | +branched off; here the approved version of the project is the reference, and `frozen.json`, beside this script in | |
| 9 | +that version, records what it holds: | |
| 10 | + | |
| 11 | +- `files`: the Comparator challenge, its configuration and the statements they import, each by its SHA-256. A commit | |
| 12 | + fails if any of them is missing or differs (Comparator would accept a change there, since both sides would see it). | |
| 13 | +- `lakefile`: `lakefile.toml` as approved, without the keys a pull request may change (FREE: `leanOptions`, | |
| 14 | + `defaultTargets`, `lean_exe`, `[cache]`, and each `require`'s `rev`). The libraries, their sources, Lean's arguments | |
| 15 | + and the dependencies' names and addresses stay as they are, so `Challenge` and the solution keep naming these files. | |
| 16 | +- `manifest`: the settings of `lake-manifest.json` (everything but its packages) and where Mathlib comes from. | |
| 17 | + | |
| 18 | +It also fails a commit that adds `lakefile.lean` (Lake reads it instead of `lakefile.toml`), lists a package that is not | |
| 19 | +a Git repository of leanprover or leanprover-community on GitHub nor one in `trusted`, names a toolchain that is not a | |
| 20 | +release of leanprover/lean4, adds files under `.lake/`, or holds a symbolic link among the frozen files; and, as | |
| 21 | +upstream's build does, one that puts `sorry`, `admit`, an `axiom`, `native_decide`, `implemented_by` or `extern` in its | |
| 22 | +Lean source (comments and strings skipped). | |
| 23 | + | |
| 24 | +A Mathlib or toolchain bump passes: it changes `rev`, the packages' revisions and `lean-toolchain`. The `build` check | |
| 25 | +then needs a Lean image for it. It reads files only and runs nothing from the commit. Standard library only, Python | |
| 26 | +3.11 or newer (tomllib). Exit 0 passes, 1 fails. | |
| 27 | +""" | |
| 28 | + | |
| 29 | +from __future__ import annotations | |
| 30 | + | |
| 31 | +import hashlib | |
| 32 | +import json | |
| 33 | +import os | |
| 34 | +import re | |
| 35 | +import sys | |
| 36 | +import tomllib | |
| 37 | +from pathlib import Path | |
| 38 | + | |
| 39 | +FREE = {"leanOptions", "defaultTargets", "lean_exe", "cache"} | |
| 40 | +TRUSTED = ("https://github.com/leanprover-community/", "https://github.com/leanprover/") | |
| 41 | +TOOLCHAIN = re.compile(r"leanprover/lean4:v[0-9][0-9A-Za-z.+-]*") | |
| 42 | +FORBIDDEN = [ | |
| 43 | + (re.compile(r"\bsorry\b"), "sorry"), | |
| 44 | + (re.compile(r"\bsorryAx\b"), "sorryAx"), # the axiom behind sorry, which \bsorry\b does not see | |
| 45 | + # the tactic, not a field or projection that happens to be called admit (`admit : P x`, `h.admit`, `admit (x)`) | |
| 46 | + (re.compile(r"(?<![.\w'])admit\b(?!['\w])(?![ \t]*[:(])"), "admit"), | |
| 47 | + (re.compile(r"(?m)^[ \t]*(?:@\[[^\]]*\][ \t]*)?(?:(?:private|protected|noncomputable)[ \t]+)*axiom\b"), "an axiom declaration"), | |
| 48 | + (re.compile(r"\bnative_decide\b"), "native_decide"), | |
| 49 | + (re.compile(r"\bimplemented_by\b"), "implemented_by"), | |
| 50 | + (re.compile(r"@\[\s*extern\b"), "extern"), | |
| 51 | +] | |
| 52 | +# a file without any of these words anywhere, comments included, needs no closer look | |
| 53 | +ANY = re.compile(r"sorry|admit|axiom|native_decide|implemented_by|extern") | |
| 54 | +SKIP_DIRS = {".git", ".lake", "lake-packages", "__pycache__", "node_modules"} | |
| 55 | + | |
| 56 | + | |
| 57 | +def strip(text: str) -> str: | |
| 58 | + """Lean source without its comments and string literals: `--` to the end of the line, nested `/- … -/`, and | |
| 59 | + "…" with its escapes. What is left is code, so a docstring that mentions `sorry` is not a `sorry`.""" | |
| 60 | + out: list[str] = [] | |
| 61 | + i, n, depth = 0, len(text), 0 | |
| 62 | + while i < n: | |
| 63 | + if depth: | |
| 64 | + if text.startswith("/-", i): | |
| 65 | + depth += 1 | |
| 66 | + i += 2 | |
| 67 | + elif text.startswith("-/", i): | |
| 68 | + depth -= 1 | |
| 69 | + i += 2 | |
| 70 | + else: | |
| 71 | + if text[i] == "\n": | |
| 72 | + out.append("\n") | |
| 73 | + i += 1 | |
| 74 | + continue | |
| 75 | + if text.startswith("/-", i): | |
| 76 | + depth = 1 | |
| 77 | + i += 2 | |
| 78 | + elif text.startswith("--", i): | |
| 79 | + j = text.find("\n", i) | |
| 80 | + i = n if j < 0 else j | |
| 81 | + elif text[i] == '"': | |
| 82 | + i += 1 | |
| 83 | + while i < n and text[i] != '"': | |
| 84 | + i += 2 if text[i] == "\\" else 1 | |
| 85 | + i += 1 | |
| 86 | + elif text[i] == "'" and i + 2 < n and text[i + 2] == "'": | |
| 87 | + i += 3 # a character literal such as '"' | |
| 88 | + else: | |
| 89 | + out.append(text[i]) | |
| 90 | + i += 1 | |
| 91 | + return "".join(out) | |
| 92 | + | |
| 93 | + | |
| 94 | +def sha256(path: Path) -> str: | |
| 95 | + h = hashlib.sha256() | |
| 96 | + with path.open("rb") as f: | |
| 97 | + for block in iter(lambda: f.read(1 << 20), b""): | |
| 98 | + h.update(block) | |
| 99 | + return h.hexdigest() | |
| 100 | + | |
| 101 | + | |
| 102 | +def lakefile_view(text: str) -> dict: | |
| 103 | + """lakefile.toml without what a pull request may change: upstream's `lakefile()`.""" | |
| 104 | + config = tomllib.loads(text) | |
| 105 | + view = {key: value for key, value in config.items() if key not in FREE} | |
| 106 | + view["require"] = [{key: value for key, value in require.items() if key != "rev"} for require in config.get("require", [])] | |
| 107 | + return view | |
| 108 | + | |
| 109 | + | |
| 110 | +def manifest_view(text: str) -> tuple[dict, dict]: | |
| 111 | + """lake-manifest.json's settings, and its packages by name: upstream's `manifest()`.""" | |
| 112 | + data = json.loads(text) | |
| 113 | + return {key: value for key, value in data.items() if key != "packages"}, {p.get("name"): p for p in data.get("packages", [])} | |
| 114 | + | |
| 115 | + | |
| 116 | +def canonical(value) -> str: | |
| 117 | + return json.dumps(value, sort_keys=True, ensure_ascii=False) | |
| 118 | + | |
| 119 | + | |
| 120 | +def frozen_of(root: Path, files: list[str], trusted: list[str]) -> dict: | |
| 121 | + """What frozen.json holds for a tree: run on the approved version to make it (`--freeze`).""" | |
| 122 | + settings, packages = manifest_view((root / "lake-manifest.json").read_text(encoding="utf-8")) | |
| 123 | + return { | |
| 124 | + "files": {path: sha256(root / path) for path in files}, | |
| 125 | + "lakefile": json.loads(canonical(lakefile_view((root / "lakefile.toml").read_text(encoding="utf-8")))), | |
| 126 | + "manifest": {"settings": settings, "mathlib": (packages.get("mathlib") or {}).get("url")}, | |
| 127 | + "trusted": trusted, | |
| 128 | + } | |
| 129 | + | |
| 130 | + | |
| 131 | +def lean_files(root: Path): | |
| 132 | + for here, dirs, names in os.walk(root): | |
| 133 | + dirs[:] = sorted(d for d in dirs if d not in SKIP_DIRS) | |
| 134 | + for name in sorted(names): | |
| 135 | + if name.endswith(".lean"): | |
| 136 | + yield Path(here) / name | |
| 137 | + | |
| 138 | + | |
| 139 | +def check(root: Path, frozen: dict) -> tuple[list[str], str]: | |
| 140 | + wrong: list[str] = [] | |
| 141 | + for rel, want in sorted(frozen["files"].items()): | |
| 142 | + p = root / rel | |
| 143 | + if p.is_symlink() or (p.exists() and not p.is_file()): | |
| 144 | + wrong.append(f"{rel} is not a plain file: it is a Comparator challenge file") | |
| 145 | + elif not p.is_file(): | |
| 146 | + wrong.append(f"{rel} is missing: it is a Comparator challenge file") | |
| 147 | + elif sha256(p) != want: | |
| 148 | + wrong.append(f"{rel} differs from the approved version: it is a Comparator challenge file") | |
| 149 | + if (root / "lakefile.lean").exists(): | |
| 150 | + wrong.append("lakefile.lean is added: Lake would read it instead of lakefile.toml") | |
| 151 | + try: | |
| 152 | + lake = root / "lakefile.toml" | |
| 153 | + if not lake.is_file() or canonical(lakefile_view(lake.read_text(encoding="utf-8"))) != canonical(frozen["lakefile"]): | |
| 154 | + wrong.append("lakefile.toml changes other than in a require's rev, leanOptions, defaultTargets, lean_exe or [cache]") | |
| 155 | + settings, packages = manifest_view((root / "lake-manifest.json").read_text(encoding="utf-8")) | |
| 156 | + if canonical(settings) != canonical(frozen["manifest"]["settings"]): | |
| 157 | + wrong.append("lake-manifest.json: its settings change") | |
| 158 | + if (packages.get("mathlib") or {}).get("url") != frozen["manifest"]["mathlib"]: | |
| 159 | + wrong.append("lake-manifest.json: where Mathlib comes from changes") | |
| 160 | + for name, package in packages.items(): | |
| 161 | + url = str(package.get("url")) | |
| 162 | + if package.get("type") != "git" or not (url.startswith(TRUSTED) or url in frozen.get("trusted", [])): | |
| 163 | + wrong.append(f"lake-manifest.json: the package {name} is not a Git repository of leanprover-community or leanprover on GitHub, nor one this project trusts") | |
| 164 | + except (OSError, ValueError, tomllib.TOMLDecodeError, AttributeError) as problem: | |
| 165 | + wrong.append(f"the build configuration could not be read: {problem}") | |
| 166 | + toolchain = (root / "lean-toolchain").read_text(encoding="utf-8").strip() if (root / "lean-toolchain").is_file() else "" | |
| 167 | + if not TOOLCHAIN.fullmatch(toolchain): | |
| 168 | + wrong.append(f"lean-toolchain: {toolchain!r} is not a release of leanprover/lean4") | |
| 169 | + if (root / ".lake").exists(): | |
| 170 | + wrong.append(".lake/ is added: Lake keeps what it builds and fetches there") | |
| 171 | + files = lines = 0 | |
| 172 | + for p in lean_files(root): | |
| 173 | + rel = p.relative_to(root).as_posix() | |
| 174 | + text = p.read_text(encoding="utf-8", errors="replace") | |
| 175 | + files += 1 | |
| 176 | + lines += text.count("\n") | |
| 177 | + if rel in frozen["files"] or not ANY.search(text): | |
| 178 | + continue | |
| 179 | + code = strip(text) | |
| 180 | + for rx, what in FORBIDDEN: | |
| 181 | + m = rx.search(code) | |
| 182 | + if m: | |
| 183 | + wrong.append(f"{rel}:{code.count(chr(10), 0, m.start()) + 1} uses {what}") | |
| 184 | + break | |
| 185 | + return wrong, f"{len(frozen['files'])} challenge files and the build configuration as approved; {files} Lean files, {lines} lines, toolchain {toolchain}" | |
| 186 | + | |
| 187 | + | |
| 188 | +def main(argv: list[str]) -> int: | |
| 189 | + if len(argv) >= 2 and argv[1] == "--freeze": | |
| 190 | + # challenge.py --freeze <approved tree> <frozen file>... [--trust <url>]...: print frozen.json for that tree | |
| 191 | + args, trusted = argv[3:], [] | |
| 192 | + while "--trust" in args: | |
| 193 | + i = args.index("--trust") | |
| 194 | + trusted.append(args[i + 1]) | |
| 195 | + del args[i:i + 2] | |
| 196 | + print(json.dumps(frozen_of(Path(argv[2]), args, trusted), indent=2, ensure_ascii=False)) | |
| 197 | + return 0 | |
| 198 | + if len(argv) < 2: | |
| 199 | + print(__doc__.strip().splitlines()[2]) | |
| 200 | + return 2 | |
| 201 | + root = Path(argv[1]) | |
| 202 | + frozen = json.loads((Path(argv[2]) if len(argv) > 2 else Path(__file__).with_name("frozen.json")).read_text(encoding="utf-8")) | |
| 203 | + if not any(lean_files(root)): | |
| 204 | + print("Nothing to check yet: the commit holds no Lean file.") | |
| 205 | + return 0 | |
| 206 | + wrong, said = check(root, frozen) | |
| 207 | + for w in wrong[:50]: | |
| 208 | + print(w) | |
| 209 | + if len(wrong) > 50: | |
| 210 | + print(f"… and {len(wrong) - 50} more") | |
| 211 | + if wrong: | |
| 212 | + print("These files say what the proof is judged against and how it is built, and a pull request may not change them;") | |
| 213 | + print("if one has to, open an issue titled \"Ruling: …\" for a person who maintains the project.") | |
| 214 | + print(f"FAILED: {wrong[0]}") | |
| 215 | + return 1 | |
| 216 | + print(f"ok: {said}") | |
| 217 | + return 0 | |
| 218 | + | |
| 219 | + | |
| 220 | +if __name__ == "__main__": | |
| 221 | + sys.exit(main(sys.argv)) | |
+10 −0 checks/challenge.sbatch added View file
| @@ -0,0 +1,10 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=challenge | |
| 3 | +#SBATCH --time=5:00 | |
| 4 | +# Comparator challenge files and build configuration are unchanged (upstream's challenge-files.yml): the approved | |
| 5 | +# checks/challenge.py compares the pushed commit ($SS_INPUT) with what checks/frozen.json records of the approved | |
| 6 | +# version, and looks through its Lean source for sorry, admit, axiom and the like. It reads files only and runs nothing | |
| 7 | +# from the commit. The job's working directory is the approved version, so a branch that edits checks/ changes nothing | |
| 8 | +# about its own verdict. | |
| 9 | +set -euo pipefail | |
| 10 | +python3 -I checks/challenge.py "$SS_INPUT" checks/frozen.json | |
+63 −0 checks/frozen.json added View file
| @@ -0,0 +1,63 @@ | ||
| 1 | +{ | |
| 2 | + "files": { | |
| 3 | + "Challenge.lean": "b729a3ccbc3290cf9d9356d8dd8009ad19b5bad10bb50d5a4711ff3d5133b055", | |
| 4 | + "src/Statements.lean": "5dcfb235de403e45f96ca2528a022421d911d1ddc0af3509e4e2d4524fd7fb9f", | |
| 5 | + "comparator.json": "af227d4d6a09bd1449d297a745a7a28d1ecd22ecf85ec62deb2825bd0f164304" | |
| 6 | + }, | |
| 7 | + "lakefile": { | |
| 8 | + "lean_lib": [ | |
| 9 | + { | |
| 10 | + "globs": [ | |
| 11 | + "Lib.+" | |
| 12 | + ], | |
| 13 | + "name": "Lib" | |
| 14 | + }, | |
| 15 | + { | |
| 16 | + "globs": [ | |
| 17 | + "New.+" | |
| 18 | + ], | |
| 19 | + "name": "New" | |
| 20 | + }, | |
| 21 | + { | |
| 22 | + "name": "Main", | |
| 23 | + "roots": [ | |
| 24 | + "Statements", | |
| 25 | + "Main" | |
| 26 | + ] | |
| 27 | + }, | |
| 28 | + { | |
| 29 | + "name": "Challenge", | |
| 30 | + "srcDir": ".." | |
| 31 | + } | |
| 32 | + ], | |
| 33 | + "moreLeanArgs": [ | |
| 34 | + "--tstack=400000" | |
| 35 | + ], | |
| 36 | + "name": "GRH", | |
| 37 | + "platformIndependent": true, | |
| 38 | + "require": [ | |
| 39 | + { | |
| 40 | + "git": "https://github.com/leanprover-community/mathlib4", | |
| 41 | + "name": "mathlib" | |
| 42 | + }, | |
| 43 | + { | |
| 44 | + "git": "https://github.com/TauCetiProject/TauCeti", | |
| 45 | + "name": "TauCeti" | |
| 46 | + } | |
| 47 | + ], | |
| 48 | + "srcDir": "src" | |
| 49 | + }, | |
| 50 | + "manifest": { | |
| 51 | + "settings": { | |
| 52 | + "version": "1.3.0", | |
| 53 | + "packagesDir": ".lake/packages", | |
| 54 | + "name": "GRH", | |
| 55 | + "lakeDir": ".lake", | |
| 56 | + "fixedToolchain": false | |
| 57 | + }, | |
| 58 | + "mathlib": "https://github.com/leanprover-community/mathlib4" | |
| 59 | + }, | |
| 60 | + "trusted": [ | |
| 61 | + "https://github.com/TauCetiProject/TauCeti" | |
| 62 | + ] | |
| 63 | +} | |
+65 −0 docker/README.md added View file
| @@ -0,0 +1,65 @@ | ||
| 1 | +# Lean image | |
| 2 | + | |
| 3 | +`lean.Dockerfile` builds the image the riemann-hypothesis build check runs in. Tag: | |
| 4 | + | |
| 5 | +``` | |
| 6 | +shoal-rh-lean:630d1e43 | |
| 7 | +``` | |
| 8 | + | |
| 9 | +`scienceslack.json` refers to this exact name. | |
| 10 | + | |
| 11 | +## Build | |
| 12 | + | |
| 13 | +On the machine whose runner will use it, with a checkout of the project's main as the context (not this folder, and | |
| 14 | +not a clone of upstream: the image is the build of our main): | |
| 15 | + | |
| 16 | +```bash | |
| 17 | +git clone <the project's repository> /tmp/rh-main | |
| 18 | +sh /tmp/rh-main/docker/build.sh /tmp/rh-main # tag: the one scienceslack.json names | |
| 19 | +MIRRORS=cn CPUSET=64-127 sh /tmp/rh-main/docker/build.sh /tmp/rh-main # on the Beijing host, on those cores | |
| 20 | +``` | |
| 21 | + | |
| 22 | +`build.sh` is one `docker build` with the classic builder and the host's network. `MIRRORS=cn` takes apt from Aliyun, the Lean release | |
| 23 | +and seven of the Lean packages (Mathlib among them) from SJTU's mirror; elan, Tau Ceti, plausible and LeanSearchClient still come from github.com, each | |
| 24 | +tried ten times. The build needs the network (GitHub, the Lean release, the Mathlib, Tau Ceti and project caches). Nothing is published: the runner that runs the check must have | |
| 25 | +the image locally. | |
| 26 | + | |
| 27 | +Built on the production host on 2026-12-02 (16 cores, `MIRRORS=cn`): image | |
| 28 | +`sha256:da30feeb683371b767e16bc1eccb85f55e8261b3fc17ccfcc2d6fe2feecc707a`, 5.3 GB, 19 minutes. Upstream's cache had | |
| 29 | +the project's build for `630d1e43`, so `lake build` of the four libraries took 11 s (26,379 jobs; `.lake/build` 2.2 GB). | |
| 30 | +On main, with the runner's flags: the per-push `build` (`"replay": "round"`: build, `sorry` scan, the theorems' axioms | |
| 31 | +as the commit's Lean reports them) 17 s at 4 CPUs, 0.9 GB; the full replay exports 4.7 GB in 4 minutes, nanoda takes | |
| 32 | +about 10 minutes, and Lean's kernel had run 90 minutes and held 62 GB without a verdict when the run was stopped (07:47): it runs once per maintainer round. | |
| 33 | + | |
| 34 | +## What is in it | |
| 35 | + | |
| 36 | +- `/opt/elan`: elan with the upstream's toolchain installed and set as the default, so `lake` works offline. | |
| 37 | +- `/opt/proof`: the project's main (the context), with `.lake` fully built (dependencies, their oleans, and every library of `lakefile.toml`: Lib, New, Main and Challenge). `PROOF_BASE=/opt/proof`. `.lake/build` belongs to `nobody`, and everything under `/opt` is readable by `nobody`: the check compiles a commit as that user. | |
| 38 | +- On `PATH`: `lake` (with `lake comparator`), `lean`, `nanoda_bin`, `leanchecker`, `bwrap`; also `python3`, `git`, `curl`, `zstd` and a C toolchain. | |
| 39 | + | |
| 40 | +## How the check uses it | |
| 41 | + | |
| 42 | +The check runs the image with `--network none`. It copies the pushed commit's tree to a writable directory, gives it `/opt/proof/.lake` (or links its `packages`), and runs `lake build`, `lake env lean scripts/PrintAxioms.lean` and `lake comparator --config comparator.json`. Lake then recompiles only what the commit changed. `lake exe cache get` cannot run there, which is why the image does it at build time. | |
| 43 | + | |
| 44 | +The project does not depend on Comparator, and the image builds none: since v4.35.0 Lean ships it as `lake comparator` | |
| 45 | +(sandboxed with bubblewrap), with its exporter and `nanoda_bin`, as the goldbach-spectral-bridge image uses them. The | |
| 46 | +standalone `leanprover/comparator` and `lean4export` are deprecated and have no tag for v4.37.0-rc1. The check runs | |
| 47 | +`lake comparator --config comparator.json`; the image puts the toolchain's `nanoda_bin` and `leanchecker` on `PATH`. | |
| 48 | + | |
| 49 | +The image fetches three caches, as upstream's `lake exe cache get` (`scripts/lake-cache-get.sh`) does: Mathlib's in the dependencies' layer, then Tau Ceti's (`scripts/tauceti-cache-get.py`) and the project's own (`scripts/ci-cache-get.py`; Python 3.11+ and curl 7.71+, which Ubuntu 24.04 has). The project's cache is what upstream's CI published for the `src` tree, `lakefile.toml`, `lake-manifest.json` and toolchain of its own commits: it matches while our main's `src` is byte for byte a commit of upstream's main (at the pin it is: upstream has a record for `630d1e43`), and no longer once we have merged our own changes. Then exit 3 (no record) is accepted and the full `lake build` that follows compiles what the caches did not supply, about 4 CPU-hours from nothing. | |
| 50 | + | |
| 51 | +## Pins | |
| 52 | + | |
| 53 | +All pins are full hashes in `ARG`s at the top of `lean.Dockerfile`. The build checks the context's `lean-toolchain`, the toolchain file's SHA-256 and the Mathlib and Tau Ceti checkouts against them, and fails otherwise. | |
| 54 | + | |
| 55 | +| ARG | Value | Source | | |
| 56 | +| --- | --- | --- | | |
| 57 | +| `UPSTREAM_COMMIT` | `630d1e43b442cab27717c3ebf94d218dea608374` | leanprover-community/riemann-hypothesis, `upstream.json` | | |
| 58 | +| `TOOLCHAIN` | `leanprover/lean4:v4.37.0-rc1` | upstream `lean-toolchain` | | |
| 59 | +| `LEAN_SHA256` | `2e1bbb832870bb81b7131cb70b13aec2cc7ed9f22e2bdbb236b86076ae20382d` | the digest GitHub lists for `lean-4.37.0-rc1-linux.tar.zst` | | |
| 60 | +| `MATHLIB_COMMIT` | `31ce06eaadf4a200c0e1407c5f10953cf606b8f8` | upstream `lakefile.toml` / `lake-manifest.json` | | |
| 61 | +| `TAUCETI_COMMIT` | `2a9233e5be32675476ae438bef6f6dd4ba93eb64` | upstream `lakefile.toml` / `lake-manifest.json` | | |
| 62 | + | |
| 63 | +## Rebuild when main moves | |
| 64 | + | |
| 65 | +The image is the build of one commit of main. Rebuild it, under a new tag, whenever main's `lean-toolchain` or `lake-manifest.json` changes (for example a new Lean release, or new Mathlib or Tau Ceti pins): set the pins it moves in `lean.Dockerfile`, build from a checkout of the new main as above, and change the tag in `scienceslack.json` in the same PR. The check refuses a commit whose `lean-toolchain` differs from the image's. Rebuilding after other changes to main is optional: it only makes the checks faster, since less has to be recompiled. | |
+25 −0 docker/build.sh added View file
| @@ -0,0 +1,25 @@ | ||
| 1 | +#!/bin/sh | |
| 2 | +# Build the Lean image of the `build` check, on the machine whose runner will use it. | |
| 3 | +# | |
| 4 | +# sh docker/build.sh <checkout of the project's main> [<tag>] | |
| 5 | +# | |
| 6 | +# MIRRORS=cn take apt, the Lean release and seven of the Lean packages from the mirrors a host in Beijing can reach | |
| 7 | +# (lean.Dockerfile's ARGs) | |
| 8 | +# CPUSET=32-63 the cores the build may use (Docker's classic builder honours it; the default is all of them) | |
| 9 | +# | |
| 10 | +# The tag is the one the project's rules name for the `build` check (scienceslack.json) unless given. One | |
| 11 | +# `docker build` of lean.Dockerfile with the checkout as its context: the tools and the toolchain, the dependencies | |
| 12 | +# with Mathlib's cache (a layer that stays while lakefile.toml, lake-manifest.json and lean-toolchain stay), then the | |
| 13 | +# tree and its build. | |
| 14 | +set -eu | |
| 15 | +main=$(cd "$1" && pwd) | |
| 16 | +tag=${2:-$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["checks"]["build"]["image"])' "$main/scienceslack.json")} | |
| 17 | +if [ -e "$main/.lake" ]; then echo "$main holds .lake: build from a clean checkout" >&2; exit 2; fi | |
| 18 | +cpus=${CPUSET:+--cpuset-cpus $CPUSET} | |
| 19 | +mirrors= | |
| 20 | +if [ "${MIRRORS:-}" = cn ]; then | |
| 21 | + mirrors="--build-arg APT_MIRROR=http://mirrors.aliyun.com/ubuntu --build-arg GIT_MIRROR=https://mirror.sjtu.edu.cn/git/lean4-packages --build-arg LEAN_DL=https://mirror.sjtu.edu.cn/elan/leanprover/lean4/releases/download" | |
| 22 | +fi | |
| 23 | +# (the classic builder: BuildKit ignores --cpuset-cpus; the host's network: through Docker's bridge downloads crawl) | |
| 24 | +DOCKER_BUILDKIT=0 docker build --network host $cpus $mirrors -f "$main/docker/lean.Dockerfile" -t "$tag" "$main" | |
| 25 | +docker image inspect --format "$tag {{.Id}} {{.Size}} bytes" "$tag" | |
+159 −0 docker/lean.Dockerfile added View file
| @@ -0,0 +1,159 @@ | ||
| 1 | +# Lean image for the riemann-hypothesis `build` check (checks/build.py). | |
| 2 | +# | |
| 3 | +# Build with a checkout of the project's main as the context, not this folder (docker/build.sh does it, with the | |
| 4 | +# mirrors a host in Beijing needs): | |
| 5 | +# git clone <the project's repository> /tmp/rh-main | |
| 6 | +# sh /tmp/rh-main/docker/build.sh /tmp/rh-main | |
| 7 | +# | |
| 8 | +# The project's main is leanprover-community/riemann-hypothesis at its pinned commit, without its GitHub CI | |
| 9 | +# (upstream.json `drop`), with this project's files on top, and whatever has been merged since. The image holds it | |
| 10 | +# fully built in /opt/proof. The check runs with --network none: it reads a commit's tree, uses /opt/proof/.lake and | |
| 11 | +# runs lake build, the exporter and `lake comparator`. Nothing is downloaded at check time. | |
| 12 | +# | |
| 13 | +# Every pin is a full hash in an ARG below, checked once it is fetched. See README.md for where each comes from. | |
| 14 | + | |
| 15 | +FROM ubuntu:24.04 | |
| 16 | + | |
| 17 | +# --- Where the downloads come from ------------------------------------------ | |
| 18 | + | |
| 19 | +# The defaults are each project's own servers. From Beijing (docker/build.sh with MIRRORS=cn): the Ubuntu archive by | |
| 20 | +# plain http from Aliyun (ca-certificates is not installed yet at the first apt step), and the Lean release from | |
| 21 | +# SJTU's mirror: github.com, where releases.lean-lang.org sends elan for it, gave this host the file at anything from | |
| 22 | +# 17 KB/s to 20 MB/s within ten minutes (12-02). raw.githubusercontent.com is not used: Beijing cannot reach it. | |
| 23 | +ARG APT_MIRROR= | |
| 24 | +ARG LEAN_DL=https://github.com/leanprover/lean4/releases/download | |
| 25 | + | |
| 26 | +# --- Pins ------------------------------------------------------------------- | |
| 27 | + | |
| 28 | +# leanprover-community/riemann-hypothesis, which the project starts from, and its lean-toolchain at that commit. The | |
| 29 | +# context must hold that toolchain; LEAN_SHA256 is the digest GitHub lists for lean-4.37.0-rc1-linux.tar.zst. | |
| 30 | +ARG UPSTREAM_COMMIT=630d1e43b442cab27717c3ebf94d218dea608374 | |
| 31 | +ARG TOOLCHAIN=leanprover/lean4:v4.37.0-rc1 | |
| 32 | +ARG LEAN_SHA256=2e1bbb832870bb81b7131cb70b13aec2cc7ed9f22e2bdbb236b86076ae20382d | |
| 33 | +# From the project's lake-manifest.json; checked once the dependencies are fetched. | |
| 34 | +ARG MATHLIB_COMMIT=31ce06eaadf4a200c0e1407c5f10953cf606b8f8 | |
| 35 | +ARG TAUCETI_COMMIT=2a9233e5be32675476ae438bef6f6dd4ba93eb64 | |
| 36 | + | |
| 37 | +# Comparator: since v4.35.0 Lean ships it as `lake comparator` (sandboxed with bubblewrap), with the exporter and | |
| 38 | +# nanoda_bin beside it, so nothing is built for it here. | |
| 39 | + | |
| 40 | +# --- System packages -------------------------------------------------------- | |
| 41 | + | |
| 42 | +# python3 (3.12) and curl (8.5) run the check and meet the cache scripts' needs (>= 3.11, >= 7.71); bubblewrap is | |
| 43 | +# the sandbox `lake comparator` runs in where user namespaces are allowed (the check's container has none). | |
| 44 | +ENV DEBIAN_FRONTEND=noninteractive | |
| 45 | +RUN if [ -n "$APT_MIRROR" ]; then sed -i "s#http://archive.ubuntu.com/ubuntu#$APT_MIRROR#; s#http://security.ubuntu.com/ubuntu#$APT_MIRROR#" /etc/apt/sources.list.d/ubuntu.sources; fi \ | |
| 46 | + && apt-get update && apt-get install -y --no-install-recommends \ | |
| 47 | + ca-certificates curl git python3 build-essential zstd bubblewrap \ | |
| 48 | + && rm -rf /var/lib/apt/lists/* | |
| 49 | + | |
| 50 | +# The check runs Lake as another user than the one that built; let git (Lake asks it about each package) read every | |
| 51 | +# repository in the image. | |
| 52 | +RUN git config --system --add safe.directory '*' | |
| 53 | + | |
| 54 | +# clone-at <url> <dir> <commit>: that one commit of a repository, without its history, checked out and checked. From | |
| 55 | +# Beijing a connection to github.com times out, stalls or breaks off every few tries (12-02), and Lake clones each | |
| 56 | +# package once and does not try again: so every package of the manifest is fetched this way before Lake runs, a fetch | |
| 57 | +# that stalls is cut off, and each is tried ten times. | |
| 58 | +RUN printf '%s\n' '#!/bin/sh' 'set -eu' \ | |
| 59 | + 'n=0; until rm -rf "$2" && git init -q "$2" && git -C "$2" remote add origin "$1" && timeout 600 git -C "$2" -c http.lowSpeedLimit=1000 -c http.lowSpeedTime=30 fetch -q --depth 1 origin "$3"; do n=$((n+1)); [ "$n" -lt 10 ]; sleep 5; done' \ | |
| 60 | + 'git -C "$2" -c advice.detachedHead=false checkout -q FETCH_HEAD' \ | |
| 61 | + 'test "$(git -C "$2" rev-parse HEAD)" = "$3"' > /usr/local/bin/clone-at \ | |
| 62 | + && chmod 755 /usr/local/bin/clone-at | |
| 63 | + | |
| 64 | +# --- Lean ------------------------------------------------------------------- | |
| 65 | + | |
| 66 | +# elan from its GitHub release. The toolchain as its release file, checked against the SHA-256 GitHub lists for the | |
| 67 | +# asset, unpacked where elan keeps a toolchain of that name (elan then takes it for installed), and made the default. | |
| 68 | +ENV ELAN_HOME=/opt/elan | |
| 69 | +ENV PATH=/usr/local/bin:/opt/elan/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin | |
| 70 | +RUN curl -sSfL --retry 8 --retry-all-errors --connect-timeout 20 https://github.com/leanprover/elan/releases/download/v4.1.2/elan-x86_64-unknown-linux-gnu.tar.gz -o /tmp/elan.tgz \ | |
| 71 | + && tar -xzf /tmp/elan.tgz -C /tmp && /tmp/elan-init -y --no-modify-path --default-toolchain none && rm /tmp/elan-init /tmp/elan.tgz | |
| 72 | +RUN v="${TOOLCHAIN#*:v}" && dir="/opt/elan/toolchains/$(echo "${TOOLCHAIN}" | sed 's#/#--#; s#:#---#')" \ | |
| 73 | + && curl -sSfL --retry 8 --retry-all-errors --connect-timeout 20 -C - "${LEAN_DL}/v$v/lean-$v-linux.tar.zst" -o /tmp/lean.tar.zst \ | |
| 74 | + && echo "${LEAN_SHA256} /tmp/lean.tar.zst" | sha256sum -c - \ | |
| 75 | + && mkdir -p "$dir" && tar --zstd -xf /tmp/lean.tar.zst -C "$dir" --strip-components 1 && rm /tmp/lean.tar.zst \ | |
| 76 | + && elan default "${TOOLCHAIN}" && chmod -R a+rX /opt/elan \ | |
| 77 | + && lean --version | grep -q "version $v" | |
| 78 | + | |
| 79 | +# --- The dependencies ------------------------------------------------------- | |
| 80 | + | |
| 81 | +# From the three files that name them, so that a change elsewhere in main does not fetch Mathlib's cache (5 GB) again. | |
| 82 | +# Each package of the manifest at its commit first (clone-at), then Mathlib's oleans: a few of the cache's downloads | |
| 83 | +# fail now and then, and each try fetches only what is missing. Its download store (~/.cache/mathlib) is unpacked | |
| 84 | +# into .lake by then and removed. The check compiles a commit as `nobody`, and the cache unpacks its files 0600: they | |
| 85 | +# are made readable here, in the layer that makes them (a chmod in a later layer copies every file it visits). | |
| 86 | +# (Mathlib's cache by its own name: `lake exe cache` is this project's script, which needs the whole tree.) | |
| 87 | +# GIT_MIRROR (docker/build.sh with MIRRORS=cn: https://mirror.sjtu.edu.cn/git/lean4-packages) serves the seven | |
| 88 | +# packages it holds, Mathlib among them, at the same commits (each is checked below or by Lake against the manifest); | |
| 89 | +# the others still come from github.com. The packages keep their github.com addresses, and the setting, root's own, | |
| 90 | +# is removed once they are fetched. On 12-02 github.com could not be reached from Beijing for minutes at a time. | |
| 91 | +ARG GIT_MIRROR= | |
| 92 | +WORKDIR /opt/proof | |
| 93 | +COPY lakefile.toml lake-manifest.json lean-toolchain /opt/proof/ | |
| 94 | +RUN test "$(cat lean-toolchain)" = "${TOOLCHAIN}" \ | |
| 95 | + && if [ -n "$GIT_MIRROR" ]; then for r in leanprover-community/mathlib4 leanprover-community/batteries leanprover-community/aesop \ | |
| 96 | + leanprover-community/quote4 leanprover-community/ProofWidgets4 leanprover-community/import-graph leanprover/lean4-cli; do \ | |
| 97 | + git config --global url."$GIT_MIRROR/${r#*/}".insteadOf "https://github.com/$r"; done; fi \ | |
| 98 | + && python3 -c 'import json; [print(p["url"], ".lake/packages/" + p["name"], p["rev"]) for p in json.load(open("lake-manifest.json"))["packages"]]' \ | |
| 99 | + | while read -r url dir rev; do clone-at "$url" "$dir" "$rev" || exit 1; done \ | |
| 100 | + && rm -f /root/.gitconfig \ | |
| 101 | + && test "$(git -C .lake/packages/mathlib rev-parse HEAD)" = "${MATHLIB_COMMIT}" \ | |
| 102 | + && test "$(git -C .lake/packages/TauCeti rev-parse HEAD)" = "${TAUCETI_COMMIT}" \ | |
| 103 | + && export MATHLIB_CACHE_GET_URL=https://cache.mathlib.org/mathlib4 \ | |
| 104 | + && (lake exe mathlib/cache get || lake exe mathlib/cache get || lake exe mathlib/cache get) \ | |
| 105 | + && test "$(git -C .lake/packages/mathlib rev-parse HEAD)" = "${MATHLIB_COMMIT}" \ | |
| 106 | + && rm -rf /root/.cache/mathlib \ | |
| 107 | + && chmod -R a+rX /opt/proof | |
| 108 | + | |
| 109 | +# --- The project ------------------------------------------------------------ | |
| 110 | + | |
| 111 | +# The context is a checkout of the project's main. Two more caches come first, as scripts/lake-cache-get.sh fetches | |
| 112 | +# them after Mathlib's (`lake exe cache get` itself would fetch Mathlib's 5 GB again): Tau Ceti's oleans, and the | |
| 113 | +# project's own, which upstream's CI published for the src tree, lakefile.toml, lake-manifest.json and toolchain of | |
| 114 | +# its commits. The project's is looked up by the Git tree of src, so the tree is made a commit for the lookup. Exit 3 | |
| 115 | +# means no record matches (our main has moved away from upstream's): `lake build` then compiles what the caches did | |
| 116 | +# not supply, about 4 CPU-hours from nothing. The full build of every library of lakefile.toml (the default targets Lib, New and Main, | |
| 117 | +# then Challenge) follows either way, so a pull request's build recompiles only what it changed. Lake's download store | |
| 118 | +# (.lake/cache, the packed copies of what is now unpacked in .lake/build) is removed once `lake build --no-build` | |
| 119 | +# shows that nothing needs it; | |
| 120 | +# and the build becomes `nobody`'s (checks/build.py can then build a commit on top of it in place, `in_place` in | |
| 121 | +# checks/build.json, instead of copying it for every job). Only what lacks read access is chmod-ed: a chmod of all of | |
| 122 | +# /opt/proof here would copy Mathlib into this layer. | |
| 123 | +COPY . /opt/proof | |
| 124 | +RUN rm -rf .git \ | |
| 125 | + && test -f Challenge.lean && test -f src/Statements.lean && test ! -e lakefile.lean \ | |
| 126 | + && grep -q "${UPSTREAM_COMMIT}" docker/lean.Dockerfile \ | |
| 127 | + && git init -q . && echo /.lake/ > .git/info/exclude && git add -A \ | |
| 128 | + && git -c user.name=image -c user.email=image@localhost commit -q -m "main, for the cache lookup" \ | |
| 129 | + && export LAKE_CACHE_DIR=/opt/proof/.lake/cache && ulimit -Sn "$(ulimit -Hn)" \ | |
| 130 | + && (python3 scripts/tauceti-cache-get.py || python3 scripts/tauceti-cache-get.py || python3 scripts/tauceti-cache-get.py) \ | |
| 131 | + && { s=0; for i in 1 2 3; do s=0; python3 scripts/ci-cache-get.py || s=$?; [ "$s" = 0 ] || [ "$s" = 3 ] && break; sleep 10; done; \ | |
| 132 | + echo "project cache: exit $s (0 restored, 3 no record for these inputs)"; [ "$s" = 0 ] || [ "$s" = 3 ]; } \ | |
| 133 | + && unset LAKE_CACHE_DIR && rm -rf .git \ | |
| 134 | + && lake build Lib New Main Challenge \ | |
| 135 | + && grep -q "${MATHLIB_COMMIT}" lake-manifest.json \ | |
| 136 | + && du -sh .lake/cache .lake/build \ | |
| 137 | + && mv .lake/cache /tmp/lake-cache \ | |
| 138 | + && if lake build --no-build && lake build --no-build Challenge; then rm -rf /tmp/lake-cache; else mv /tmp/lake-cache .lake/cache; fi \ | |
| 139 | + && find .lake/build -name "*.setup.json" -delete \ | |
| 140 | + && chown -R nobody:nogroup .lake/build \ | |
| 141 | + && find /opt/proof \( -type f ! -perm -004 -o -type d ! -perm -005 \) -exec chmod a+rX {} + | |
| 142 | + | |
| 143 | +# --- Comparator's second kernel ---------------------------------------------- | |
| 144 | + | |
| 145 | +# The toolchain's own nanoda_bin and leanchecker, on PATH for `lake comparator`. | |
| 146 | +# (elan 4.1.2 has no `elan which --toolchain`; the default toolchain's prefix is the same folder.) | |
| 147 | +RUN ln -s "$(lean --print-prefix)/bin/nanoda_bin" /usr/local/bin/nanoda_bin \ | |
| 148 | + && ln -s "$(lean --print-prefix)/bin/leanchecker" /usr/local/bin/leanchecker \ | |
| 149 | + && test -x /usr/local/bin/nanoda_bin && test -x /usr/local/bin/leanchecker \ | |
| 150 | + && lake comparator --help >/dev/null | |
| 151 | + | |
| 152 | +# Every tool must be on PATH. | |
| 153 | +RUN for t in bwrap nanoda_bin leanchecker lake lean git python3 which; do \ | |
| 154 | + command -v "$t" >/dev/null || { echo "missing: $t"; exit 1; }; \ | |
| 155 | + done | |
| 156 | + | |
| 157 | +ENV PROOF_BASE=/opt/proof | |
| 158 | +WORKDIR /opt/proof | |
| 159 | +CMD ["/bin/bash"] | |