Lean 4 is a programming language and theorem prover. Four pieces are involved in getting and building its packages.
lean compiler, Lake and the core libraries, and is named by a GitHub repository and release tag, such as leanprover/lean4:v4.36.0.lean-toolchain file.This post goes through the quirks we found in Lake and Reservoir and what they mean for supply chain security. As Lean is increasingly used to verify software, the supply chain that delivers those proofs deserves the same scrutiny as any other.
Pros
Cons
version in its manifest. These can conflict (§3).lakefile.toml and the lockfile is lake-manifest.jsonThe manifest comes in two forms. The TOML form is declarative.
name = "hello"
[[require]]
name = "mathlib"
scope = "leanprover-community"
rev = "v4.36.0"
The Lean form is imperative, because it is a Lean program.
import Lake
open Lake DSL
package hello
require "leanprover-community" / "mathlib" @ git "v4.36.0"
Running lake update resolves either form into the lockfile.
Every dependency source is cloned into .lake/packages inside the project and compiled from source.
However, building from source can take hours, so Lake also downloads prebuilt binaries in three cases.
leanprover and leanprover-community scopes, such as batteries. Reservoir lists a hash for each archive, but Lake does not check it before unpacking.lake exe cache get is mathlib’s own tool. It downloads prebuilt .olean files for the locked mathlib commit. Mathlib runs it through its own post_update hook, so every project that depends on mathlib downloads these files on lake update by default.preferReleaseBuild := true makes Lake download a package’s build archive from its GitHub release, uploaded with lake upload. The package’s developer sets this in their own manifest.In every case the choice is made upstream, by Lake or by the package’s developer, not by the downstream user.
The user can only opt out, with lake build --no-cache or MATHLIB_NO_CACHE_ON_UPDATE=1.
There are two ways to declare a package’s version.
version field in the manifest# foo's manifest (lakefile.toml)
name = "foo"
version = "1.2.0"
# consumer's manifest (lakefile.toml)
[[require]]
name = "foo"
scope = "alice"
version = "1.2.0"
# foo's GitHub repository
# release tagged v1.2.0
# consumer's manifest (lakefile.toml)
[[require]]
name = "foo"
scope = "alice"
rev = "v1.2.0" # a tag, branch or commit
Nothing keeps the two in sync.
All 123 mathlib revisions indexed by Reservoir report version 0.0.0, while their Git tags follow Lean releases (v4.36.0, v4.37.0-rc1).
This is probably done intentionally to ensure there is only one source of truth for the version.
Requirements may point at branches and tags, both of which can be moved or force-pushed.
[[require]]
name = "mathlib"
scope = "leanprover-community"
rev = "v4.36.0"
The lockfile stores that request (inputRev) next to the commit it resolved to (rev).
This keeps the version pinned even if the tag is moved.
{"name": "mathlib",
"scope": "leanprover-community",
"url": "https://github.com/leanprover-community/mathlib4",
"inputRev": "v4.36.0",
"rev": "fc4f59e577feb1a4956671bc04ac18aaaf8cd842",
"inherited": false}
Lake stores no checksum of the fetched sources, and there is nothing like Go’s checksum database.
This matters because references are mutable in the manifest.
A tag can be moved to a different commit (v4.36.0 can be moved to a different commit).
If this commit is malicious, lake update will happily fetch it and record the new commit in the lockfile.
Thus, compromising the Lean project.
Lake has two commands that matter here.
lake update resolves dependencies. It turns every Git reference in the manifest into a commit SHA and writes those pins to the lockfile.lake build compiles the project and all its dependencies. It uses the pinned commits and never resolves anything itself.Here is what lake build does in each case.
lake update.rev. The build warns that the lockfile is out of date and keeps using the pinned commit.The lockfile lists every package in the workspace in one array.
Direct (the declared) dependencies are listed with "inherited": false while
transitive dependencies carry "inherited": true,
{"name": "batteries",
"inputRev": "main",
"rev": "b4b25a3886a16daacaf6615c2eea7170a6e8f458",
"inherited": true}
You cannot tell whether batteries sits at depth 2 or depth 5, or which dependency brought it in, and Lake has no cargo tree or npm ls.
A manifest written in Lean is a program, so loading a dependency’s manifest already runs its code.
Packages can also register post_update hooks.
post_update pkg do
let child ← IO.Process.spawn {cmd := "sh", args := #["-c", "echo hello from a dependency"]}
let _ ← child.wait
lake update runs the hooks of every package in the workspace without a sandbox.
Reservoir has no publish step and only indexes sources, but it runs a build farm and hosts the resulting binaries.
It crawls GitHub daily and lists every repository that meets its inclusion criteria, which are a public non-fork repository, a lockfile at the repository root, an OSI-approved license and at least two stars.
It builds each package with the toolchain named in its own lean-toolchain file, and also with the latest stable and release-candidate Lean releases.
The package page then shows “builds on Lean v4.36.0” or “fails to build”.
Lake does no dependency conflict resolution.
It keeps one copy per package name and does not compare versions.
lake update works in three steps, described in a doc comment in Lake/Load/Resolve.lean.
require of the root is resolved to a commit and stored first, so the root’s own pins always win.inherited, unless a package with that name is already there.The source gives two reasons for the reverse order.
Later requires should shadow earlier ones, like later definitions in a file, and requirements written by the user should beat those inherited from dependencies.
Take the graph from our earlier post.
The root requires D1, D2, D3 and D4 in that order, and each pulls in a different version of Dx.

Lake reads D4’s lockfile first, finds Dx v1.5.0 there and copies it into the root lockfile.
The copies under D3, D2 and D1 are ignored.
Depth plays no role here, because each direct dependency’s lockfile already lists its whole subtree, and Lake copies those lockfiles before the breadth-first walk starts.
| Ecosystem | Rule | Dx |
|---|---|---|
| Maven | Nearest to the root, then first declared | v1.2.0 |
| Go | Highest of the required minimums (MVS) | v1.5.0 |
| Lake | Root’s own pin, then the lockfile of the last declared dependency | v1.5.0 |
Because no versions are compared, conflicts are never reported during resolution.
If D2 was tested against Dx v1.2.0 and uses an API that v1.5.0 removed, lake update succeeds and the error appears later as a compile error inside D2.
Adding a direct require for Dx in the root avoids this, since the root’s pins always win.