Birch and Swinnerton-Dyer: certified ranks in Lean
ECCompute: Lean that certifies rank lower bounds for 480 elliptic curves, up to rank ≥ 31. Certify more, rerun it, read what 2026 claimed about BSD

| 1 | # Lean image for the birch-swinnerton-dyer `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/bsd-main |
| 6 | # sh /tmp/bsd-main/docker/build.sh /tmp/bsd-main |
| 7 | # |
| 8 | # The project's main is b-mehta/EllipticCurveRank at its pinned commit, without .github (upstream.json `drop`), with |
| 9 | # this project's Statement.lean, Challenge.lean, Solution.lean, PrintAxioms.lean, comparator.json and lakefile.toml on |
| 10 | # top, and whatever has been merged since. The image holds it fully built in /opt/proof. The check runs with |
| 11 | # --network none: it reads a commit's tree, uses /opt/proof/.lake and runs lake build, the exporter and |
| 12 | # `lake comparator`. Nothing is downloaded at check time. |
| 13 | # |
| 14 | # Every pin is a full hash in an ARG below, checked once it is fetched. See README.md for where each comes from. |
| 15 | |
| 16 | FROM ubuntu:24.04 |
| 17 | |
| 18 | # --- Where the downloads come from ------------------------------------------ |
| 19 | |
| 20 | # The defaults are each project's own servers. From Beijing (docker/build.sh with MIRRORS=cn): the Ubuntu archive by |
| 21 | # plain http from Aliyun (ca-certificates is not installed yet at the first apt step), and the Lean release from |
| 22 | # SJTU's mirror: github.com, where releases.lean-lang.org sends elan for it, gave this host the file at anything from |
| 23 | # 17 KB/s to 20 MB/s within ten minutes (12-02). raw.githubusercontent.com is not used: Beijing cannot reach it. |
| 24 | ARG APT_MIRROR= |
| 25 | ARG LEAN_DL=https://github.com/leanprover/lean4/releases/download |
| 26 | |
| 27 | # --- Pins ------------------------------------------------------------------- |
| 28 | |
| 29 | # b-mehta/EllipticCurveRank (ECCompute), which the project starts from, and its lean-toolchain at that commit. The |
| 30 | # context must hold that toolchain; LEAN_SHA256 is the digest GitHub lists for lean-4.36.0-linux.tar.zst. |
| 31 | ARG UPSTREAM_COMMIT=9cb92e9a7ddf28666d89cb221a89fb35de75b4d3 |
| 32 | ARG TOOLCHAIN=leanprover/lean4:v4.36.0 |
| 33 | ARG LEAN_SHA256=2b7ab1ed8b92d2e6abfaf41344823b510064dbc9c0260cac73eb496ab2dea6eb |
| 34 | # From the project's lake-manifest.json (lakefile.toml asks for Mathlib's tag v4.36.0). |
| 35 | ARG MATHLIB_COMMIT=fc4f59e577feb1a4956671bc04ac18aaaf8cd842 |
| 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 runs the check; curl and zstd are what Lake and Mathlib's cache tool use; bubblewrap is the sandbox |
| 43 | # `lake comparator` runs in where user namespaces are allowed (the check's container has none: checks/build.py). |
| 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 | # GIT_MIRROR (docker/build.sh with MIRRORS=cn: https://mirror.sjtu.edu.cn/git/lean4-packages) serves the seven |
| 87 | # packages it holds, Mathlib among them, at the same commits (each is checked below or by Lake against the manifest); |
| 88 | # the others still come from github.com. The packages keep their github.com addresses, and the setting, root's own, |
| 89 | # is removed once they are fetched. On 12-02 github.com could not be reached from Beijing for minutes at a time. |
| 90 | ARG GIT_MIRROR= |
| 91 | WORKDIR /opt/proof |
| 92 | COPY lakefile.toml lake-manifest.json lean-toolchain /opt/proof/ |
| 93 | RUN test "$(cat lean-toolchain)" = "${TOOLCHAIN}" \ |
| 94 | && if [ -n "$GIT_MIRROR" ]; then for r in leanprover-community/mathlib4 leanprover-community/batteries leanprover-community/aesop \ |
| 95 | leanprover-community/quote4 leanprover-community/ProofWidgets4 leanprover-community/import-graph leanprover/lean4-cli; do \ |
| 96 | git config --global url."$GIT_MIRROR/${r#*/}".insteadOf "https://github.com/$r"; done; fi \ |
| 97 | && python3 -c 'import json; [print(p["url"], ".lake/packages/" + p["name"], p["rev"]) for p in json.load(open("lake-manifest.json"))["packages"]]' \ |
| 98 | | while read -r url dir rev; do clone-at "$url" "$dir" "$rev" || exit 1; done \ |
| 99 | && rm -f /root/.gitconfig \ |
| 100 | && test "$(git -C .lake/packages/mathlib rev-parse HEAD)" = "${MATHLIB_COMMIT}" \ |
| 101 | && (lake exe cache get || lake exe cache get || lake exe cache get) \ |
| 102 | && test "$(git -C .lake/packages/mathlib rev-parse HEAD)" = "${MATHLIB_COMMIT}" \ |
| 103 | && rm -rf /root/.cache/mathlib \ |
| 104 | && chmod -R a+rX /opt/proof |
| 105 | |
| 106 | # --- The project ------------------------------------------------------------ |
| 107 | |
| 108 | # The context is a checkout of the project's main. A full build of every library of lakefile.toml (the default |
| 109 | # targets ECCompute, Curves and Solution, then Statement and Challenge) and of the axiom print follows, so a pull request's build recompiles only what it changed. The 480 |
| 110 | # curve files are the work: each reduces its certificate in the kernel (README.md has the time); |
| 111 | # and the build becomes `nobody`'s (checks/build.py can then build a commit on top of it in place, `in_place` in |
| 112 | # checks/build.json, instead of copying it for every job). Only what lacks read access is chmod-ed: a chmod of all of |
| 113 | # /opt/proof here would copy Mathlib into this layer. |
| 114 | COPY . /opt/proof |
| 115 | RUN rm -rf .git \ |
| 116 | && test -f Statement.lean && test -f Challenge.lean && test -f Curves.lean && test ! -e lakefile.lean \ |
| 117 | && grep -q "${UPSTREAM_COMMIT}" docker/lean.Dockerfile \ |
| 118 | && lake build ECCompute Curves Statement Solution Challenge \ |
| 119 | && lake env lean PrintAxioms.lean > /dev/null \ |
| 120 | && grep -q "${MATHLIB_COMMIT}" lake-manifest.json \ |
| 121 | && find .lake/build -name "*.setup.json" -delete \ |
| 122 | && chown -R nobody:nogroup .lake/build \ |
| 123 | && find /opt/proof \( -type f ! -perm -004 -o -type d ! -perm -005 \) -exec chmod a+rX {} + |
| 124 | |
| 125 | # --- Comparator's second kernel ---------------------------------------------- |
| 126 | |
| 127 | # The toolchain's own nanoda_bin and leanchecker, on PATH for `lake comparator`. |
| 128 | # (elan 4.1.2 has no `elan which --toolchain`; the default toolchain's prefix is the same folder.) |
| 129 | RUN ln -s "$(lean --print-prefix)/bin/nanoda_bin" /usr/local/bin/nanoda_bin \ |
| 130 | && ln -s "$(lean --print-prefix)/bin/leanchecker" /usr/local/bin/leanchecker \ |
| 131 | && test -x /usr/local/bin/nanoda_bin && test -x /usr/local/bin/leanchecker \ |
| 132 | && lake comparator --help >/dev/null |
| 133 | |
| 134 | # Every tool must be on PATH. |
| 135 | RUN for t in bwrap nanoda_bin leanchecker lake lean git python3 which; do \ |
| 136 | command -v "$t" >/dev/null || { echo "missing: $t"; exit 1; }; \ |
| 137 | done |
| 138 | |
| 139 | ENV PROOF_BASE=/opt/proof |
| 140 | WORKDIR /opt/proof |
| 141 | CMD ["/bin/bash"] |