|
| 1 | +# Gap Analysis: What's Missing for Real Formal Verification |
| 2 | + |
| 3 | +## The Goal |
| 4 | + |
| 5 | +**Prove Rust programs correct** by: |
| 6 | +1. Translating Rust → pure Lean via Aeneas |
| 7 | +2. Writing Lean proofs about the generated code |
| 8 | +3. Lean typechecker verifies the proofs → Rust code is proven correct |
| 9 | + |
| 10 | +## Gap 1: No Real Proofs |
| 11 | + |
| 12 | +**Current:** All theorems are `axiom` — unproven assertions. Lean accepts them but verifies nothing. |
| 13 | + |
| 14 | +**Needed:** Real proofs using Aeneas tactics (`step`/`progress`, `scalar_tac`, `simp_all`). |
| 15 | + |
| 16 | +**How to close:** Write proofs following the ICFP tutorial patterns: |
| 17 | +```lean |
| 18 | +-- Current (BROKEN — proves nothing): |
| 19 | +axiom clamp_in_bounds (x lo hi : Std.I32) (h : lo ≤ hi) : |
| 20 | + ∃ r, clamp x lo hi = ok r ∧ lo ≤ r ∧ r ≤ hi |
| 21 | +
|
| 22 | +-- Needed (REAL — Lean verifies this): |
| 23 | +@[pspec] |
| 24 | +theorem clamp_in_bounds (x lo hi : Std.I32) (h : lo ≤ hi) : |
| 25 | + ∃ r, clamp x lo hi = ok r ∧ lo ≤ r ∧ r ≤ hi := by |
| 26 | + rw [clamp] |
| 27 | + split <;> split <;> simp_all <;> constructor <;> scalar_tac |
| 28 | +``` |
| 29 | + |
| 30 | +**Effort:** Medium per theorem. Start with tutorials 01-03 (simplest), then 04-06. |
| 31 | + |
| 32 | +## Gap 2: Proof Files Use Fake Prelude Instead of Real Aeneas Library |
| 33 | + |
| 34 | +**Current:** Each tutorial has a standalone `Aeneas.lean` with simplified types (`U32` as bare `Nat` wrapper). Proof files import this fake prelude. |
| 35 | + |
| 36 | +**Needed:** Lakefiles that `require aeneas from git` and proof files that import the real generated code. |
| 37 | + |
| 38 | +**How to close:** |
| 39 | +1. Change each tutorial's `lakefile.lean` to depend on the real Aeneas library |
| 40 | +2. Replace hand-written `Funs.lean` with the real generated code from `lean/generated/` |
| 41 | +3. Rewrite proof files to work against real Aeneas types |
| 42 | + |
| 43 | +**Effort:** Small per tutorial (lakefile change + file reorganization). The proofs themselves are Gap 1. |
| 44 | + |
| 45 | +## Gap 3: Proof Files Don't Reference the Real Generated Code |
| 46 | + |
| 47 | +**Current:** Hand-written `Funs.lean` files approximate what Aeneas generates. The real output is in `lean/generated/` but unused. |
| 48 | + |
| 49 | +**Needed:** Proof files that `import` the real generated code and prove properties about the real generated functions. |
| 50 | + |
| 51 | +**How to close:** For each tutorial: |
| 52 | +``` |
| 53 | +lean/ |
| 54 | +├── lakefile.lean # requires aeneas from git |
| 55 | +├── lean-toolchain # matches Aeneas's toolchain |
| 56 | +├── HelloProof.lean # REAL Aeneas output (was in generated/) |
| 57 | +└── HelloProof/ |
| 58 | + └── Proofs.lean # Hand-written proofs importing HelloProof |
| 59 | +``` |
| 60 | + |
| 61 | +## Gap 4: CI Doesn't Verify Proofs Against Real Aeneas |
| 62 | + |
| 63 | +**Current:** Lean CI builds against standalone prelude. Axioms always pass. |
| 64 | + |
| 65 | +**Needed:** Lean CI builds against real Aeneas library. Real proofs must typecheck. |
| 66 | + |
| 67 | +**How to close:** |
| 68 | +1. Change lakefiles to use real Aeneas dependency |
| 69 | +2. CI installs elan + runs `lake build` (Aeneas library is cached) |
| 70 | +3. Build time: ~5 min first run, ~30s cached |
| 71 | + |
| 72 | +**Effort:** Small (lakefile changes + CI cache configuration). |
| 73 | + |
| 74 | +## Gap 5: Some Rust Code Can't Be Translated by Aeneas |
| 75 | + |
| 76 | +**Current:** Tutorials 04, 07, 08, 09, 10, 11 have Aeneas translation errors. |
| 77 | + |
| 78 | +| Tutorial | Error | Root Cause | |
| 79 | +|----------|-------|------------| |
| 80 | +| 04 | `type_var_id` | Generic `run_machine<M: StateMachine>` | |
| 81 | +| 07 | `Unreachable` | `vec![]` macro in `AppModel::new`, modular focus cycling | |
| 82 | +| 08 | `shallow-init-box` | `Conversation::new` with `vec![msg]` | |
| 83 | +| 09 | `break to outer loop` | Nested loop in `validate_tool_call` | |
| 84 | +| 10 | Missing `filter`/`collect` | Iterator combinators | |
| 85 | +| 11 | `nested borrows` | Borrow in `render_conversation` | |
| 86 | + |
| 87 | +**Needed:** Refactor Rust code to avoid unsupported patterns. |
| 88 | + |
| 89 | +**How to close:** |
| 90 | +- Replace `vec![x]` with `Vec::new()` + `push(x)` (Aeneas doesn't support `vec![]` macro) |
| 91 | +- Replace `break` in nested loops with flag variable |
| 92 | +- Replace iterator chains with explicit `while` loops |
| 93 | +- Simplify generic trait usage |
| 94 | +- Avoid nested borrows |
| 95 | + |
| 96 | +**Effort:** Medium. Each fix is small but needs retesting with Aeneas. |
| 97 | + |
| 98 | +## Gap 6: Tutorial 07 Completely Fails Translation |
| 99 | + |
| 100 | +**Current:** Tutorial 07 (TUI Core) fails Aeneas translation entirely. |
| 101 | + |
| 102 | +**Needed:** Rewrite to avoid `Unreachable` patterns. |
| 103 | + |
| 104 | +**How to close:** Rewrite `AppModel::new` to build widget list incrementally instead of using `vec![]`. Rewrite `focus_next`/`focus_prev` to avoid patterns that cause `Unreachable`. |
| 105 | + |
| 106 | +**Effort:** Medium. |
| 107 | + |
| 108 | +## Priority Order |
| 109 | + |
| 110 | +1. **Gap 2 + Gap 3** — Switch to real Aeneas library and real generated code (structural change) |
| 111 | +2. **Gap 1** — Write real proofs for tutorial 01 first (easiest, proof of concept) |
| 112 | +3. **Gap 5** — Fix Rust code for tutorials with translation errors |
| 113 | +4. **Gap 4** — Update CI to build against real Aeneas |
| 114 | +5. **Gap 1 continued** — Write real proofs for remaining tutorials |
| 115 | +6. **Gap 6** — Fix tutorial 07 |
0 commit comments