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

| 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"] |