Repository navigation
Container image with Lean, Mathlib, the engine and the workbench, plus CI that smoke-tests it and publishes on version tags - #14
Merged
Conversation
serve keeps binding 127.0.0.1 by default; --host or CRYPTIFICATE_HOST is now the only way to widen it. With CRYPTIFICATE_CONTAINER=1 (set by the container image) serve says how to reach it through a published port, and rust.refinement says the image does not check the refinement proofs.
A multi-stage Dockerfile: elan with the pinned Lean toolchain, Mathlib's build cache and lake build of lean/; the release engine with every locked crate fetched; the schema package, service and workbench. The Debian slim runtime runs as uid 1000 under tini, keeps the service on loopback unless --host or CRYPTIFICATE_HOST widens it, and checks its own health on /api/capabilities. scripts/docker-smoke.py runs check, verify and serve inside the image.
… image The container branch ran only when the state directory held no valid refinement.json, so a mounted host state directory or a reused volume made the image report the refinement proofs as checked on this machine. The image cannot check them; it now returns not_established before reading the record.
A cache hit copied every claim of the run it came from, including rust.refinement, whose status depends on whether this machine checked the refinement proofs. A state directory reused from a source checkout could so carry a proved refinement claim into the container image, and a refinement check recorded after a cached run did not show on later hits. The claim is now rebuilt from the current refinement status; the cached Lean-backed claims are unchanged.
The image's health check polls 127.0.0.1:$PORT, and serve --port does not change PORT, so the port change docs/docker.md described left Docker polling 4173 and reporting a working container unhealthy. The docs now give the port with -e PORT, and serve prints a note inside the image when --port differs from PORT.
Resolve the overlap with the branches merged before it, as in the release/v0.2.0 integration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cryptificate now has a container route alongside
npm start. A multi-stageDockerfilebuilds one image holding everythingcryptificate serve,check,experimentandverifyneed: the pinned Lean toolchain, the builtlean/package with Mathlib's compiled library, the release engine, the Rust toolchain and C linker that native experiments compile with (every locked crate is already in the image), the service and the workbench. A newdockerworkflow builds the image with Buildx and the GitHub Actions cache. It then runs smoke tests inside the image and, onv*tags only, pushes the tested image toghcr.io/4waan/cryptificate.The image has not been built on this machine. There is no Docker daemon here and not enough free disk. The CI job is the first place the image gets built. Below I list what I checked natively instead.
What is changed (precise)
No Lean theorem, template, certificate or acceptance rule changes. Nothing in
lean/,refinement/,lean-toolchain,lake-manifest.jsonor the lakefiles is touched.Dockerfile(new)debian:trixie-slim,rust:1.97.1-slim-trixieandnode:22.23.4-trixie-slim, with digests read from Docker Hub on 2026-11-02. There is no# syntax=line, so no unpinned frontend image is pulled.leanstage:elan-initis byte-identical to the elan 4.2.4 binary installed here.lean/lean-toolchainand runslake exe cache get. Both run beforeCOPY lean/, so editing Lean sources does not repeat the Mathlib download.lake build. These are the same steps asscripts/setup.sh.enginestage:cargo build --release --locked --bin cryptificate-engine, thencargo fetch --locked, so generated native variants later build offline.webstage:npm ci, then builds the schema package, the server and the web app. The schema package is copied beforenpm cibecausenpm ciruns itspreparescript (tsc). I confirmed that annpm ciwith only thepackage.jsonfiles fails with TS5058.runtimestage:debian:trixie-slimand addsgit,gcc,libc6-dev,tiniandca-certificates, plus the node binary. It copies the Rust toolchain and cargo cache, the engine, the elan toolchain andlean/with its.lake, and the server, schema and webdistoutputs.crates/kernelsandcrates/native, which are recorded with native results,refinement/extract.sha256,examples/designsandexamples/programs.cryptificate) undertini, withEXPOSE 4173.GET /api/capabilitieson127.0.0.1:$PORT, made withnode'sfetch.CARGO_NET_OFFLINE=true,CRYPTIFICATE_ROOT,CRYPTIFICATE_HOME=/var/lib/cryptificate,CRYPTIFICATE_ENGINE,CRYPTIFICATE_LEAN_DIRandCRYPTIFICATE_CONTAINER=1, plusCRYPTIFICATE_REVISIONfrom a build argument.lake env lean --versionandcryptificate --versionboth work as uid 1000.gitis in the runtime: Lake runsgit rev-parse HEADandgit diff --exit-code HEADin every package beforelake env lean. I observed this with a logginggitwrapper. Copying between stages changes inodes and ctimes, so the image setscore.checkStat=minimalandcore.trustctime=false. Git then compares only mtime and size and does not rehash the packages on every check. This reasoning follows git's documentation; I have not measured it in an image..dockerignore: excludes**/.lake,**/target,**/node_modules,**/dist,examples/bundles,examples/measurementsand root-level*.tar.gz. It also excludes.cryptificate,.git,refinement/*(exceptextract.sha256),python,docsandschemas.apps/web/public/recorded/*.tar.gzis kept. I checked that no tracked file the build needs matches an exclude pattern.Server (
apps/server)servetakes its bind address from--host, elseCRYPTIFICATE_HOST, else127.0.0.1(serveHostinserver.ts).CRYPTIFICATE_CONTAINER=1,serveadds a note (bindNotes): a loopback bind is not reachable throughdocker run -p, the port should be published as-p 127.0.0.1:P:P, and the port number should be the same on both sides.CRYPTIFICATE_CONTAINER=1, when--portdiffers fromPORT,servenotes that the image's health check pollsPORT, so Docker would report the container unhealthy, and says to use-e PORT=…instead.--host 0.0.0.0, theHostheader must still be a loopback name, and writes must still come from the service's own origin. The new tests pin both points.rust.refinementin the image: withCRYPTIFICATE_CONTAINER=1it is neverproved.refinementStatusreturnsnot_establishedbefore reading<state>/refinement.json, with a note saying the image does not check the refinement proofs. Arefinement.jsonin a mounted host state directory or a reused volume records a check made elsewhere, so it is ignored. Outside the image the logic is unchanged.rust.refinementon proof-cache hits: a cache hit used to copy every claim of the run it came from. It now rebuildsrust.refinementfrom the current refinement status (withCurrentRefinementinclaims.ts). That status depends on the machine, not on the cached certificate. Every other cached claim is copied as before. Without this, a cache in a reused state directory could carry aprovedrefinement claim into the image. It also fixes an older gap: a refinement check recorded after a cached run did not show on later hits.apps/server/README.mddocumentCRYPTIFICATE_HOST,PORT,CRYPTIFICATE_ROOTandCRYPTIFICATE_CONTAINER.apps/server/README.mdanddocs/evidence-model.md(the "Cached exact result" badge) now say that the refinement claim is recomputed on a cache hit.scripts/docker-smoke.py(new, standard library pluspython/cryptificate)Given an image, the script runs these checks inside containers, with the repository's
examples/mounted:--version.check examples/designs/aes.jsonprovesmatrix.mds,offsets.dispersion,sbox.bijectiveandactivity.bound.checkwithaes-wrong-wire.jsongivescircuit.equivalenceandnative.correctnessrefuted(cargo andgccinside the image) andrust.refinementnot_established.verify examples/bundles/aes-wrong-wire/*.tar.gzpasses:ok, unchanged input digest, at least one match and no mismatch.servewith no flags is healthy inside the container, cannot be reached through the published port, and prints the note.serve --host 0.0.0.0with-p 127.0.0.1:4173:4173:/serves HTML;POSTgets403.serve --host 0.0.0.0 -e PORT=4175with-p 127.0.0.1:4175:4175(port set bySMOKE_OTHER_PORT) is healthy, answers capabilities through 4175 and prints no health-check note.serve --port 4175withoutPORTprints the note that the health check polls 4173.Steps 1 to 4 run with
--network none..github/workflows/docker.yml(new)mainandv*tags, plus pull requests, filtered to the paths the image depends on; alsoworkflow_dispatch. GitHub does not apply path filters to tag pushes.docker/build-push-action@v6withload: true,linux/amd64,cache-from/to: type=gha(mode=min), metadata labels, and version andgit describerevision build arguments.refs/tags/v*. It logs in to ghcr.io withGITHUB_TOKEN(job permissionscontents: read,packages: write), thendocker tags anddocker pushes the exact tested image under the metadata tags: version,major.minor,latestandsha-….Docs
docs/docker.md(new) covers:servewith the port rules: loopback default,-p 127.0.0.1:…, and the same port on both sides (set with-e PORT=…, which the health check follows;--portbypasses it) or--allow-origin;checkon a mounted design;verifyof a bundle;docs/architecture.mdgains one row for the Dockerfile.Tests run
npm run buildnpm testnode --test dist/test/http.test.js--port/PORThealth-check note and all-interfaces origin-policy testsnode --test dist/test/pipeline.test.jsnot_establishedin the container even with a validrefinement.json, and a cache hit that recomputesrust.refinementafterrefinement.jsonis removed. That last assertion fails if the old copy-all-claims code is restored.CARGO_TARGET_DIR=<worktree>/target cargo test --workspace -j2python3 -m unittest discover -s python/tests -t pythonpython3 -m py_compile scripts/docker-smoke.pylake buildinlean/Build completed successfully (2018 jobs), no Lean changes (run before the review fixes, which touch no Lean)Native stage checks. I ran each stage's build commands natively:
cargo build --release --locked --bin cryptificate-engine,lake build, andnpm ciplus the three builds in a directory holding only what thewebstage copies.Emulated runtime layout. I assembled the exact runtime file tree under a scratch directory, from the paths the Dockerfile copies, and ran it with a clean environment (
env -i) set to the image'sENVvalues:check examples/designs/aes.jsonproves the four design claims (Lean 5.6 s).check … --program aes-wrong-wire.jsonrefutes the circuit in Lean and natively, withCARGO_NET_OFFLINE=true.check … --program aes-known-shared-sum.jsonproves equivalence, and native correctness passes on 9214 cases.rust.refinementisnot_established, with the image note.verify examples/bundles/aes-wrong-wire/aes-wrong-wire.tar.gzexits 0 with all re-checked claims matching.experiment … --profile quickcompletes in a network namespace with no network (unshare -n), through search, equivalence, native correctness and three benchmark sessions.serve, with the healthcheck command copied from the Dockerfile, returns 0.Smoke script. I ran
scripts/docker-smoke.pyend to end against that layout through a stand-in for thedockercommand, and all steps passed. A deliberately broken stand-in, where the defaultserveis reachable, makes step 5 fail as intended. The stand-in cannot reproduce Docker networking or port publishing, so step 5's reachability check is fully exercised only in CI.Review fixes, checked end to end without Docker.
cryptificate check examples/designs/aes.json --program examples/programs/aes-wrong-wire.jsonwith real Lean, the release engine and a state directory holding a validrefinement.json.CRYPTIFICATE_CONTAINER, it reportsrust.refinementproved(live run).CRYPTIFICATE_CONTAINER=1and the same state directory, it reportsnot_establishedwith the image note, on a proof-cache hit of that first run.dockerthat runs the built service on the host with the image'sENVand evaluates the Dockerfile'sHEALTHCHECKcommand with the container'sPORT.serve --host 0.0.0.0 --port 4175, the service answers200on 4175 while the health check reportsunhealthy.-e PORT=4175, the health check reportshealthy.-eoptions, step 7 fails.YAML and shell. The workflow parses as YAML, and the tag-push loop passes
bash -nand a dry run.Scope and limits
linux/amd64is built and tested. The arm64 elan checksum is pinned, but no arm64 build has been attempted.refinement/: Lean v4.35.0 and a second Mathlib). In the image,rust.refinementisnot_established, and the docs say so.scripts/setup.sh: the pinned toolchain and Mathlib's compiled library fromlake exe cache get.--userare not supported, and outputs written to mounts belong to uid 1000.experimentin a container describe the container on that host, including any Docker CPU limits.-e PORT=…. Withserve --portalone, the service works, but the health check polls the old port and Docker reports the container unhealthy.serveprints a note saying so. Smoke step 7 covers both cases. The stand-in run above exercised it, but real Docker networking for step 7 is exercised only in CI.Generated by Claude Code