The 4 Production Capstones
Move beyond toy exercises into four real-world verification domains: cloud IAM authorization, distributed split-brain lease storage, optimizing bytecode compilation, and proof-carrying AI supervision + polyglot differential fuzzing.
Each capstone ships with a starter specification in ProveIt/Capstones/, architectural notes in capstones/*/README.md, and a 100% zero-sorry verified solution in Solutions/Capstones/. Every standalone preview below compiles directly in live.lean-lang.org.
ProveIt/Capstones/CedarLite.lean
CedarLite — Cloud IAM Policy Engine & Optimizer
Inspired by AWS's Lean-verified Cedar authorization engine. Model principals, actions, resources, and `permit`/`forbid` policy sets, then build a policy constant-folder/dead-rule eliminator and prove three non-negotiable security theorems.
Core Theorems & Engineering Guarantees
- Default-Deny: An empty policy set denies every `(Principal, Action, Resource)` request.
- Forbid-Overrides-Permit: If ANY matching `forbid` rule fires, `authorize` returns `.deny` regardless of how many `permit` rules match.
- Optimizer Equivalence: `authorize (optimizePolicies ps) req = authorize ps req` for all requests.
Self-Contained Verified Preview (Lean 4.36.0)
-- Capstone 1 Preview: CedarLite Authorization & Forbid-Overrides-Permit
inductive Effect | permit | forbid deriving Repr, DecidableEq
inductive Decision | allow | deny deriving Repr, DecidableEq
structure Request where
principal : Nat
action : Nat
resource : Nat
deriving DecidableEq
structure Rule where
effect : Effect
targetPrincipal : Option Nat -- none = wildcard *
targetAction : Option Nat
def matchesRule (r : Rule) (req : Request) : Bool :=
(match r.targetPrincipal with | none => true | some p => p == req.principal) &&
(match r.targetAction with | none => true | some a => a == req.action)
def authorize (rules : List Rule) (req : Request) : Decision :=
let active := rules.filter (fun r => matchesRule r req)
if active.any (fun r => r.effect == .forbid) then .deny
else if active.any (fun r => r.effect == .permit) then .allow
else .deny
theorem default_deny (req : Request) : authorize [] req = .deny := rfl
theorem explicit_forbid_wins (r : Rule) (rest : List Rule) (req : Request)
(h_forbid : r.effect = .forbid) (h_match : matchesRule r req = true) :
authorize (r :: rest) req = .deny := by
unfold authorize
simp only [List.filter, h_match, ↓reduceIte, List.any_cons, h_forbid, BEq.rfl, Bool.true_or]
ProveIt/Capstones/FencingKV.lean
FencingKV — Split-Brain Leases & Tombstone Compaction
Full Two-Gear TLA+-in-Lean distributed verification: use Gear 1 BFS to reproduce a GC-pause split-brain write on unfenced storage, then prove Gear 2 unbounded inductive epoch monotonicity AND tombstone-compaction refinement.
Core Theorems & Engineering Guarantees
- Gear 1 Falsification: Unfenced delayed leader writes corrupt newer epoch commits in 4 steps.
- Gear 2 Monotonic Fencing: `msg.epoch < node.fencedEpoch` is rejected across all unbounded `epoch : Nat`.
- Stuttering Compaction: Garbage-collecting shadowed writes and tombstones preserves logical key reads.
Self-Contained Verified Preview (Lean 4.36.0)
-- Capstone 2 Preview: FencingKV Monotonic Token Guard
structure StorageNode where
fencedEpoch : Nat
val : Nat
deriving Repr, DecidableEq
def writeFenced (node : StorageNode) (msgEpoch msgVal : Nat) : StorageNode :=
if msgEpoch ≥ node.fencedEpoch then
{ fencedEpoch := msgEpoch, val := msgVal }
else node
theorem fenced_epoch_monotonic (node : StorageNode) (ep v : Nat) :
node.fencedEpoch ≤ (writeFenced node ep v).fencedEpoch := by
unfold writeFenced
split <;> omega
theorem stale_epoch_ignored (node : StorageNode) (ep v : Nat)
(h_stale : ep < node.fencedEpoch) :
writeFenced node ep v = node := by
unfold writeFenced
have h_not : ¬(ep ≥ node.fencedEpoch) := by omega
simp only [h_not, ↓reduceIte]
ProveIt/Capstones/StackVM.lean
StackVM — Verified Optimizing Compiler & Bytecode VM
Compile an expression AST with variables, arithmetic, and conditionals into flat stack-machine bytecode, write an algebraic constant-folding optimizer, and prove end-to-end semantic preservation for arbitrary code continuations.
Core Theorems & Engineering Guarantees
- Optimizer Soundness: `eval env (optimize e) = eval env e`.
- Continuation-Safe Stack Preservation: `exec env (compile e ++ codeRest) stk = exec env codeRest (eval env e :: stk)`.
- Zero Stack-Underflow Guarantee: Compiled programs never trap on an empty operand stack.
Self-Contained Verified Preview (Lean 4.36.0)
-- Capstone 3 Preview: StackVM Compiler Continuation Preservation
inductive Expr
| lit (n : Nat)
| var (x : Nat)
| add (a b : Expr)
def eval (env : Nat → Nat) : Expr → Nat
| .lit n => n
| .var x => env x
| .add a b => eval env a + eval env b
inductive Instr | push (n : Nat) | load (x : Nat) | iadd
def compile : Expr → List Instr
| .lit n => [.push n]
| .var x => [.load x]
| .add a b => compile a ++ compile b ++ [.iadd]
def exec (env : Nat → Nat) : List Instr → List Nat → Option (List Nat)
| [], stk => some stk
| .push n :: rest, stk => exec env rest (n :: stk)
| .load x :: rest, stk => exec env rest (env x :: stk)
| .iadd :: rest, b :: a :: stk => exec env rest ((a + b) :: stk)
| .iadd :: _, _ => none
theorem compile_correct (env : Nat → Nat) (e : Expr) (rest : List Instr) (stk : List Nat) :
exec env (compile e ++ rest) stk = exec env rest (eval env e :: stk) := by
induction e generalizing rest stk with
| lit n => rfl
| var x => rfl
| add a b iha ihb =>
simp only [compile, List.append_assoc, iha, ihb, eval]
rfl
ProveIt/Capstones/VeriGate.lean
VeriGate & Oracle — AI Proof-Carrying Gate & Differential Fuzzer
Build the supervision harness that lets autonomous coding agents write fast implementations without compromising soundness: lock `Spec` hashes, audit axioms/attributes against `RedTeam/` exploits, and differential-fuzz external services.
Core Theorems & Engineering Guarantees
- Two-Tier Axiom Policy: Strict Tier 0 (`propext`, `Quot.sound`, `Classical.choice`) + explicit Tier 1 (`bv_decide` without raw `native_decide`).
- Attribute & Spec-Drift Firewall: Blocks `sorryAx`, custom `axiom`, `@[implemented_by]`, `@[extern]`, `@[csimp]`, and `Spec.lean` edits.
- Polyglot Differential Oracle (`lake exe oracle`): Streams ground-truth outputs to test Rust, Go, TS, and Python services.
Self-Contained Verified Preview (Lean 4.36.0)
-- Capstone 4 Preview: Pure Axiom-Policy Classifier Model
inductive TrustTier | strictKernel | bvLrat deriving DecidableEq
structure AuditInput where
axiomsUsed : List String
hasRawNativeDec : Bool
hasRuntimeSwap : Bool -- @[implemented_by] / @[extern] / @[csimp]
specHashMatches : Bool
hasNonVacuity : Bool
def allowedAxiom (tier : TrustTier) (ax : String) : Bool :=
ax == "propext" || ax == "Quot.sound" || ax == "Classical.choice" ||
(tier == .bvLrat && (ax == "Lean.ofReduceBool" || ax == "Lean.trustCompiler"))
def verigatePass (tier : TrustTier) (inp : AuditInput) : Bool :=
inp.specHashMatches &&
inp.hasNonVacuity &&
!inp.hasRuntimeSwap &&
!inp.hasRawNativeDec &&
inp.axiomsUsed.all (allowedAxiom tier)
theorem sorry_always_rejected (tier : TrustTier) (inp : AuditInput)
(h : "sorryAx" ∈ inp.axiomsUsed) : verigatePass tier inp = false := by
unfold verigatePass
have hall : inp.axiomsUsed.all (allowedAxiom tier) = false := by
rw [List.all_eq_false]
refine ⟨"sorryAx", h, ?_⟩
cases tier <;> decide
simp only [hall, Bool.and_false]