Lesson 03 · Developers

Machine-checked proofs: what they establish and what they don't

about 12 minutes

This lesson is for engineers who need to evaluate, or eventually make, a formal verification claim. It covers how proof assistants establish trust, what refinement proofs connect, how the specification gap shows up in practice (with a small Lean example you can run), what seL4’s proof stack does and does not cover, and what empirical studies of verified systems say about where bugs survive. By the end you should be able to read a verification claim and name its property, its scope, its trusted computing base and its residual risks.

Vocabulary

  • A specification is a precise, formal statement of intended behaviour. It may be abstract (what, not how) or executable.
  • Functional correctness means the implementation’s behaviours are exactly those the specification allows. For seL4 the project phrases it as the C code behaving “precisely as specified in the seL4 specification and nothing more” [3].
  • Refinement is the relation used to show this: every behaviour of the concrete system is a behaviour permitted by the abstract one. Proofs are often layered: abstract specification refined by an executable specification, refined by C, refined by binary.
  • A proof assistant (Isabelle/HOL, Coq, Lean, HOL4) is a program in which proofs are constructed interactively and checked mechanically.
  • The trusted computing base (TCB) of a claim is everything that must be correct for the claim to hold but is not itself verified: the checker’s kernel, the logic, models of hardware, unverified code, build tools.

Why machine checking is trustworthy

Proof assistants in the LCF tradition, which includes Isabelle/HOL, are designed to route every inference through a small kernel, so that bugs in tactics, automation or user code should at worst fail to produce a proof rather than produce a false theorem. The seL4 project notes that Isabelle/HOL is engineered to minimise the code that must be trusted, and supports external checking by a separate small tool [4]. Lean 4’s designers likewise describe “a relatively small trusted kernel” and an API that lets users export developments and “implement their own reference checkers” [9].

The seL4 team’s summary is the right mental model: “humans are good at creating proofs, computers are very good at checking them”. They add the corollary: “If you are worried about the proof, be worried about the assumptions” [4].

The specification gap, in fifteen lines

The proof checker guarantees that the theorem you stated is true. It does not guarantee that you stated the theorem you meant. This Lean 4 file compiles (tested on Lean 4.35):

def Sorted : List Nat → Prop
  | [] => True
  | [_] => True
  | a :: b :: rest => a ≤ b ∧ Sorted (b :: rest)

-- Specification v1: "the output is sorted".
def SortSpecV1 (f : List Nat → List Nat) : Prop :=
  ∀ xs, Sorted (f xs)

-- An implementation that is obviously wrong...
def badSort (_ : List Nat) : List Nat := []

-- ...and a machine-checked proof that it meets the specification.
theorem badSort_meets_v1 : SortSpecV1 badSort := by
  intro xs
  simp [badSort, Sorted]

-- Specification v2 adds the missing requirement: same elements, same counts.
def SortSpecV2 (f : List Nat → List Nat) : Prop :=
  ∀ xs, Sorted (f xs) ∧ ∀ n, (f xs).count n = xs.count n

theorem badSort_fails_v2 : ¬ SortSpecV2 badSort := by
  intro h
  have := (h [0]).2 0
  simp [badSort] at this

badSort_meets_v1 is a perfectly valid, machine-checked theorem about a useless function. Real specification gaps are subtler, but they have this shape: a property that everyone assumed was implied and nobody wrote down. The seL4 SOSP paper is direct about it. A cynic might say an implementation proof “only shows that the implementation has precisely the same bugs that the specification contains”, and “this is true: the proof does not guarantee that the specification describes the behaviour the user expects” [1]. The mitigation is that the abstract specification is much smaller (about one third the size of the C code) and expressed in simpler concepts, so it can be reviewed and its high-level properties can themselves be proved [1].

That last move matters. seL4 does not stop at “C refines spec”. It proves properties about the spec, such as integrity and confidentiality, which then carry down to the code by refinement [2]. A user can then rely on “the kernel enforces isolation” rather than on reading the whole specification.

seL4: what the proof stack covers

The original 2009 proof covered a kernel of about 8,700 lines of C and 600 lines of assembler, with roughly 200,000 lines of Isabelle proof script [1]. The ACM TOCS paper (2014) describes the extended stack: a verified IPC fast path, a proof that the kernel binary correctly implements the C semantics, access-control (integrity and authority confinement) enforcement, information-flow noninterference, a sound worst-case execution time analysis, and an automatic initialiser connecting kernel enforcement to user-level system configuration [2]. The proof is maintained in the public l4v repository and checked continuously [11].

Layer What is proved Notes
Abstract spec → C Functional correctness Rules out undefined behaviour, buffer overflows, null dereferences in verified code [3]
C → binary Binary correctness, on supported configurations Removes the compiler and linker from the TCB there; uses SONOLAR, Z3, Isabelle/HOL and HOL4 [4]
Spec properties Integrity, availability, confidentiality Hold only “when used correctly”; e.g. integrity needs that isolated components aren’t given write access to each other [3]
System initialisation capDL description is realised at boot Available on some configurations [3]

seL4: what the proof stack assumes or excludes

The project’s assumptions page is a model of how to publish a TCB [4]:

  • Assembly: about 340 lines of ARM assembly for kernel entry, exit and direct hardware access, assumed correct.
  • Hardware: assumed to work as the formal model predicts, untampered and within operating conditions.
  • Hardware management: cache consistency, cache colouring and TLB management are assumed correct and assumed not to affect kernel behaviour when used correctly.
  • Boot code: about 1,200 lines outside the proof; it starts from a correctly loaded, consistent initial state.
  • Virtual memory: verified, but with a part where the team states “you have to trust us that we got all necessary conditions”; not from first principles.
  • DMA: devices with direct memory access are assumed absent or well-behaved; drivers for DMA-capable devices must themselves be verified or wrapped for the proof to carry over.
  • Side channels: the confidentiality proof covers in-kernel storage channels but “does not cover timing channels”.
  • Logic and checker: the consistency of higher-order logic and the correctness of the prover.

Also excluded: unverified configurations. The proofs page notes that defects have been found in unverified configurations such as multicore SMP and x64 VT-x, and that “even in verified configurations we have detected small defects in every class of unverified code in the kernel in that time — hardware assumptions, compiler assumptions, unverified boot code”, while no functional correctness defects have been found in verified code since 2009 [3]. That pattern, zero defects inside the proof and non-zero just outside it, is the empirical signature of a well-scoped verification.

Where bugs survive in verified systems

At the edges of the verified slice. CompCert’s theorem is semantic preservation: compiled code behaves as the source semantics prescribes, so properties proved of the source carry to the executable [5]. Yang et al.’s Csmith work found that CompCert’s verified middle end was free of the wrong-code bugs seen in every other compiler they tested, but found silent wrong-code bugs in its then-unverified front end, and a case where “CompCert’s PPC semantics failed to specify a constraint on the width of this immediate value”, a 16-bit displacement field [6]. That second bug is a modelling gap: the formal semantics of the target was less restrictive than the real machine. Their summary: verification “typically focuses on a narrow slice of a stack of tools, and the parts outside the slice remain in the trusted computing base” [6].

At interfaces. Fonseca et al. examined three verified distributed systems (IronFleet, Verdi, Chapar) and found 16 bugs, caused by “mismatched assumptions” about unverified code, libraries, resources, verification infrastructure and the specification. The bugs occurred “at the interface between verified and other components, namely in the specification, shim layer, and auxiliary tools”, components that “typically consist of only a few hundred lines” [7]. They built a testing toolkit aimed at those interfaces, which detected 13 of the 16.

In the build chain. Thompson’s 1984 lecture showed a compiler can be modified to insert a backdoor into programs it compiles, including future copies of itself, with no trace in any source code: “You can’t trust code that you did not totally create yourself” [8]. Source-level proofs inherit this risk; binary-level validation, as in seL4’s supported configurations, is how you remove it [4].

Lighter-weight formal methods

Full functional correctness proofs are expensive; most teams use formal methods on designs or policies instead. Both are valuable, with different guarantees.

Model checking designs. AWS engineers reported using TLA+ on 10 large, complex systems, finding subtle design bugs “we are sure we would not have found by other means” [10]. They are clear about the limit. To the question “How do we know that the executable code correctly implements the verified design?” the answer, in their words, is: “we don’t” [10]. A model-checked design reduces design risk; it is not a proof about deployed code.

Reasoning about policies. AWS’s Zelkova encodes the semantics of access-control policies into SMT and uses a solver to compare policy behaviours and verify properties of them [12]. This is directly relevant to agent permissions: a solver can prove that a policy as written never allows an action. It cannot prove that the policy captures what the organisation intended. The specification gap simply moves up a level.

Applying this to agent systems

No one can currently prove that a language model behaves according to a specification, because there is no specification of the model’s behaviour to prove against. What can be specified and verified are the deterministic components around it: a policy evaluator, a capability system, a sandbox, a token issuer. A credible claim in this space would read something like: “the policy engine is proved to return Never whenever any matching rule says Never, against this published semantics, under these listed assumptions.” It would not read “the agent is verified”.

Reviewing a verification claim

Ask Good answer looks like Red flag
Property Named theorem: functional correctness, noninterference, absence of a stated bug class “Mathematically secure”
Scope Named components, versions and configurations “The product”
Specification Published, reviewable, with proved high-level properties Unpublished or “proprietary”
TCB Explicit assumption list (hardware, assembly, boot, compiler, libraries, models) None given
Depth Binary-level, or source-level with compiler named in the TCB Silent on compilation
Maintenance Proofs checked in CI against each release Proof of an old version
Checkability Proof artefacts available to rerun Trust us
Complementary testing Testing focused on interfaces and assumptions “Verified, so no testing needed”

Key takeaways

A machine-checked proof turns “we tested a lot” into a theorem that holds under explicit assumptions. A refinement proof can connect an implementation to its specification. Because a small kernel checks each step, the residual doubt concentrates in the specification and the assumptions rather than in the reasoning. The specification gap is real and easy to demonstrate: a proof assistant will happily certify a useless implementation against an incomplete specification, which is why serious projects prove high-level properties about the specification itself. seL4 shows what a well-scoped claim looks like in practice, with refinement down to binary on some configurations, security theorems that hold only under stated configuration conditions, and a published assumption list covering assembly, boot code, hardware, DMA and timing channels. Empirical studies of CompCert and verified distributed systems agree that bugs in verified systems cluster at the boundaries of the proof, so verification should be paired with testing aimed at interfaces, models and environmental assumptions.

Sources and further reading

  1. Klein, G., Elphinstone, K., Heiser, G., Andronick, J., Cock, D., Derrin, P., Elkaduwe, D., Engelhardt, K., Kolanski, R., Norrish, M., Sewell, T., Tuch, H., & Winwood, S. (2009). seL4: Formal Verification of an OS Kernel. SOSP ’09, 207–220. https://doi.org/10.1145/1629575.1629596 (open copy: https://www.sigops.org/s/conferences/sosp/2009/papers/klein-sosp09.pdf)
  2. Klein, G., Andronick, J., Elphinstone, K., Murray, T., Sewell, T., Kolanski, R., & Heiser, G. (2014). Comprehensive Formal Verification of an OS Microkernel. ACM Transactions on Computer Systems, 32(1), 2:1–2:70. https://doi.org/10.1145/2560537 (open copy: https://sel4.systems/Research/pdfs/comprehensive-formal-verification-os-microkernel.pdf)
  3. seL4 Project. (n.d.). seL4 Proofs. https://sel4.systems/Verification/proofs.html
  4. seL4 Project. (n.d.). What the Proofs Assume. https://sel4.systems/Verification/assumptions.html
  5. Leroy, X. (2009). Formal verification of a realistic compiler. Communications of the ACM, 52(7), 107–115. https://doi.org/10.1145/1538788.1538814 (open copy: https://xavierleroy.org/publi/compcert-CACM.pdf)
  6. Yang, X., Chen, Y., Eide, E., & Regehr, J. (2011). Finding and Understanding Bugs in C Compilers. PLDI ’11, 283–294. https://doi.org/10.1145/1993498.1993532 (open copy: https://users.cs.utah.edu/~regehr/papers/pldi11-preprint.pdf)
  7. Fonseca, P., Zhang, K., Wang, X., & Krishnamurthy, A. (2017). An Empirical Study on the Correctness of Formally Verified Distributed Systems. EuroSys ’17, 328–343. https://doi.org/10.1145/3064176.3064183 (open copy: https://homes.cs.washington.edu/~pfonseca/papers/eurosys2017-dsbugs.pdf)
  8. Thompson, K. (1984). Reflections on Trusting Trust. Communications of the ACM, 27(8), 761–763. https://doi.org/10.1145/358198.358210 (open copy: https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf)
  9. de Moura, L., & Ullrich, S. (2021). The Lean 4 Theorem Prover and Programming Language (System Description). CADE 28, LNCS 12699. Springer. https://doi.org/10.1007/978-3-030-79876-5_37
  10. Newcombe, C., Rath, T., Zhang, F., Munteanu, B., Brooker, M., & Deardeuff, M. (2015). How Amazon Web Services Uses Formal Methods. Communications of the ACM, 58(4), 66–73. https://doi.org/10.1145/2699417 (quotes from the 2014 report version: https://lamport.azurewebsites.net/tla/formal-methods-amazon.pdf)
  11. seL4 Project. (n.d.). l4v: seL4 specifications and proofs (GitHub repository). https://github.com/seL4/l4v
  12. Backes, J., Bolignano, P., Cook, B., Dodge, C., Gacek, A., Luckow, K., Rungta, N., Tkachuk, O., & Varming, C. (2018). Semantic-based Automated Reasoning for AWS Access Policies using SMT. Formal Methods in Computer Aided Design (FMCAD 2018). https://doi.org/10.23919/FMCAD.2018.8602994 (Amazon Science page: https://www.amazon.science/publications/semantic-based-automated-reasoning-for-aws-access-policies-using-smt)