eBPF-based security platform
proofs: check the Lean 4 proofs again with two kernels
Daniel Borkmann2e26b82edda6
diff --git a/.agents/skills/proofs/SKILL.md b/.agents/skills/proofs/SKILL.mdindex 6c102128..f44e5257 100644--- a/.agents/skills/proofs/SKILL.md+++ b/.agents/skills/proofs/SKILL.md@@ -145,6 +145,13 @@ determining its events.- The lakefile builds every module under `Shirudo/`, imported or not,and makes every warning an error, so a `sorry`, a deprecated name oran unused `simp` argument fails the build.+- `run.sh` then checks every proof again, with Lean's kernel+ (`leanchecker`) and with nanoda, a kernel written apart from Lean,+ which admits only the axioms `nanoda.json` permits: `propext`,+ `Classical.choice` and `Quot.sound`. A `native_decide`, which rests+ on the compiler, or an `axiom` of our own stops nanoda with+ `declaration not found` and the name. Prove with `decide`, `omega`+ or `simp` instead, and keep `nanoda.json`'s list as it is.- A model proves the algorithm, not the C. Link the two with a CBMCproof where one is cheap, as `string-number-model.c` checks`parse_u64()` against `Number.lean` up to 4 bytes anddiff --git a/.agents/skills/security-audit/SKILL.md b/.agents/skills/security-audit/SKILL.mdindex 2f982e84..0de3dc1e 100644--- a/.agents/skills/security-audit/SKILL.md+++ b/.agents/skills/security-audit/SKILL.md@@ -315,8 +315,11 @@ cbmc --function harness -I ../../.. -I ../../../include -I ../../../util \For each Lean 4 model: `Shirudo.lean` imports it, no `axiom`, `sorry`,`native_decide` or `unsafe` stands in it (`#print axioms` on a theorem-a row names shows what it rests on), and each hypothesis of a theorem-is something the C or the deployment makes true. Where the coverage+a row names shows what it rests on; `run.sh` fails on any axiom+`testing/proofs/lean4/nanoda.json` does not permit, so check that its+list still holds only `propext`, `Classical.choice` and `Quot.sound`),+and each hypothesis of a theorem is something the C or the deployment+makes true. Where the coveragepage links the model to the C by a CBMC harness, that harness and itsbound are the link. Where it says review, review again: read the Cbeside the model step for step, with every constant, the order, eachdiff --git a/Documentation/contribute/testing/proofs.rst b/Documentation/contribute/testing/proofs.rstindex 0bfdc8ed..7a405f92 100644--- a/Documentation/contribute/testing/proofs.rst+++ b/Documentation/contribute/testing/proofs.rst@@ -61,7 +61,8 @@ Run the proofsEach CBMC line names a proof, the number of checks CBMC made and thetime it took, and ``proofs: <n> hold`` ends a run in which all of them- held. ``Build completed successfully`` ends the Lean 4 run. The+ held. ``proofs: <n> Lean 4 modules hold, checked again by two+ kernels`` ends the Lean 4 run. Theproofs take hours of CPU, a few of them minutes and gigabytes each,and CI runs them only once a change is on main. Before you send achange, run the ones that cover the code you change, as the next step@@ -204,7 +205,15 @@ Write a Lean 4 proof2. Import the module in :src:`testing/proofs/lean4/Shirudo.lean`. Thebuild checks every module under ``Shirudo/`` whether imported or not,and a ``sorry`` or any other warning fails it, so every theorem is- proved in full.+ proved in full. :src:`testing/proofs/lean4/run.sh` then checks each+ proof again, with Lean's kernel and with nanoda, a second kernel+ written apart from Lean. Neither trusts the tactics that built the+ proof or a build CI restored from its cache, and nanoda admits only+ the axioms :src:`testing/proofs/lean4/nanoda.json` permits:+ ``propext``, ``Classical.choice`` and ``Quot.sound``. A+ ``native_decide``, which rests on the compiler, or an ``axiom`` of+ the model's own stops nanoda with ``declaration not found`` and its+ name; prove the step with ``decide``, ``omega`` or ``simp``.3. Where CBMC can, add a CBMC proof that the C computes what the modelcomputes, for every input up to a bound, asdiff --git a/testing/proofs/lean4/nanoda.json b/testing/proofs/lean4/nanoda.jsonnew file mode 100644index 00000000..fb6b2c05--- /dev/null+++ b/testing/proofs/lean4/nanoda.json@@ -0,0 +1,8 @@+{+ "use_stdin": true,+ "permitted_axioms": ["propext", "Classical.choice", "Quot.sound"],+ "unpermitted_axiom_hard_error": false,+ "nat_extension": true,+ "string_extension": true,+ "print_success_message": false+}diff --git a/testing/proofs/lean4/run.sh b/testing/proofs/lean4/run.shindex 2d047dbe..aa63fb8a 100755--- a/testing/proofs/lean4/run.sh+++ b/testing/proofs/lean4/run.sh@@ -4,7 +4,8 @@## testing/proofs/lean4/run.sh -- check the Lean 4 proofs of the models of# shirudo's algorithms in this directory. A proof left unfinished with-# sorry, or any other warning, fails the build.+# sorry, or any other warning, fails the build; Lean's kernel and nanoda,+# a second kernel, then check every proof again.## testing/proofs/lean4/run.sh@@ -17,3 +18,18 @@ command -v lake >/dev/null 2>&1 || {exit 2}lake build++# The tactics and a restored build cache are not trusted: both checkers+# read what the build wrote. nanoda, written apart from Lean, admits+# only the axioms nanoda.json permits, so a native_decide or an axiom of+# our own fails here. Each module is named, as an export of Shirudo+# alone would leave out one that Shirudo.lean does not import.+modules=$(find Shirudo -name '*.lean' | sed 's|\.lean$||; s|/|.|g' | sort)+bin=$(lean --print-prefix)/bin+export=$(mktemp)+trap 'rm -f "$export"' EXIT+lake env "$bin/leanchecker" Shirudo $modules+lake env "$bin/leanexport" Shirudo $modules >"$export"+"$bin/nanoda_bin" nanoda.json <"$export"+printf 'proofs: %s Lean 4 modules hold, checked again by two kernels\n' \+ "$(printf '%s\n' "$modules" | wc -l)"