|
| 1 | +# Wave Loop 402 — Decomposed Plan |
| 2 | + |
| 3 | +**Issue:** #1305 |
| 4 | +**Branch:** `trinity-rust-rings` |
| 5 | +**Goal:** Close the deferred W401 AC5 (physical CCLK measurement) or pursue the |
| 6 | +highest-leverage no-hardware alternative: a Lean 4 formalization of the cold-POR |
| 7 | +/ CCLK decision tree. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## 1. Weak points |
| 12 | + |
| 13 | +### 1.1 Physical blocker (Variant A) |
| 14 | +- **AC5 requires a logic analyser / oscilloscope on pin P12.** Without bench |
| 15 | + access the actual CCLK frequency cannot be recorded. The `tri fpga |
| 16 | + measure-cclk --csv` parser is already robust, but the measurement itself is |
| 17 | + operator-dependent. |
| 18 | +- **OSCFSEL-to-MHz mapping remains undocumented.** Even if a capture is taken, |
| 19 | + mapping raw `OSCFSEL=0..5` to frequency requires one capture per variant or an |
| 20 | + external 7-series configuration reference. |
| 21 | + |
| 22 | +### 1.2 Formal gap (Variant B) |
| 23 | +- The W400/W401 decision trees live only in prose (`fpga/HARDWARE_SSOT.md`). |
| 24 | + They are not linked to the same formal infrastructure that underpins the |
| 25 | + ternary MAC proof lattice (`proofs/lean4/Trinity/TernaryMac.lean`). |
| 26 | +- Competitor formal-HDL projects (Sparkle HDL, Verilean, Sail-to-Verilog) can |
| 27 | + claim traceability; t27 currently has no formal FPGA-boot specification. |
| 28 | + |
| 29 | +### 1.3 Smoke-gate physical gap (Variant C) |
| 30 | +- `tri fpga smoke-gate` is board-less. A cable-connected load would catch |
| 31 | + bitstream regressions that the static assertions miss, but it needs the |
| 32 | + Digilent FTDI cable and a powered board. |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## 2. Competitor scan |
| 37 | + |
| 38 | +| Project | Approach | Relevance to W402 | |
| 39 | +|---------|----------|-------------------| |
| 40 | +| **Sparkle HDL** | Rust-embedded DSL → formal semantics | Credible formal competitor in the RTL-design space; t27's defense is the spec-first `.t27` + Lean 4 proof stack. | |
| 41 | +| **Verilean** | Lean 4 → verified RTL | Direct competitor for "Lean 4 HDL"; W402 Variant B closes a small slice of that gap for FPGA boot diagnostics. | |
| 42 | +| **Sail / RISC-V Sail** | ISA-level formal → emulator / RTL | Not HDL-focused, but demonstrates formal traceability from spec to silicon. | |
| 43 | +| **Kami (MIT)** | Coq → Bluespec-like hardware | Shows theorem-prover-verified hardware is publishable; t27 uses Lean 4 instead. | |
| 44 | +| **FIRRTL / Chisel** | Scala DSL → intermediate form → Verilog | Widely used but not formally verified; t27 differentiates on proof. | |
| 45 | +| **Clash** | Haskell → VHDL/Verilog | Functional HDL, no proof obligations by default. | |
| 46 | +| **Bluespec** | Rule-based HDL with types | Mature, but proprietary tooling; t27's open-source Lean stack is the contrast. | |
| 47 | + |
| 48 | +**Takeaway:** The credible threat is **Verilean / Lean 4 HDL**. Adding a Lean 4 |
| 49 | +FPGA-boot specification gives t27 a formal story in the same design space and |
| 50 | +leverages the existing `TernaryMac` proof infrastructure. |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## 3. Chosen variant |
| 55 | + |
| 56 | +**Variant B — Formalize the cold-POR / CCLK decision tree in Lean 4** is the |
| 57 | +highest-leverage path because: |
| 58 | +- it requires no hardware, |
| 59 | +- it reuses the existing Lean 4 build (`proofs/lean4/Trinity`), |
| 60 | +- it directly addresses the competitor gap (Verilean / Sparkle), |
| 61 | +- it documents the W400 empirical result as a formal specification. |
| 62 | + |
| 63 | +Variant A tooling is already complete; if hardware becomes available during the |
| 64 | +loop, the physical capture can be slotted in without code changes. Variant C is |
| 65 | +deferred to a stretch goal. |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## 4. Decomposed work |
| 70 | + |
| 71 | +| Step | File(s) | Deliverable | |
| 72 | +|------|---------|-------------| |
| 73 | +| 4.1 | `proofs/lean4/Trinity/TernaryFPGABoot.lean` | Definitions: `StatRegister`, `Mode`, `Done`, `Eos`, `CrcError`, `IdError` | |
| 74 | +| 4.2 | `proofs/lean4/Trinity/TernaryFPGABoot.lean` | Helper lemmas decoding `STAT` bits into named predicates | |
| 75 | +| 4.3 | `proofs/lean4/Trinity/TernaryFPGABoot.lean` | Decision-tree lemmas: `boot_success_iff`, `mode_master_spi_x1_iff`, `crc_or_id_error_implies_not_done` | |
| 76 | +| 4.4 | `proofs/lean4/Trinity.lean` | Export the new module | |
| 77 | +| 4.5 | `proofs/lean4/lakefile.toml` / CI | Ensure the module builds in `./scripts/tri test` | |
| 78 | +| 4.6 | `fpga/HARDWARE_SSOT.md` | Link the documented decision trees to the formal lemmas | |
| 79 | +| 4.7 | `docs/reports/WAVE_LOOP_402_REPORT.md` | Close-out report | |
| 80 | +| 4.8 | `docs/reports/FPGA_LOOP_EVIDENCE_2026-07-05.md` | Evidence of Lean build and lemma coverage | |
| 81 | +| 4.9 | `docs/reports/FPGA_LOOP_COOPERATION_2026-07-05.md` | W403 cooperation variants | |
| 82 | +| 4.10 | `.trinity/experience.md` | W402 learnings | |
| 83 | +| 4.11 | git/PR | Commit, push `trinity-rust-rings`, create PR, close #1305 | |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## 5. Acceptance criteria |
| 88 | + |
| 89 | +- AC-B1: `proofs/lean4/Trinity/TernaryFPGABoot.lean` compiles with `lake build`. |
| 90 | +- AC-B2: At least three decision-tree lemmas are stated and proved. |
| 91 | +- AC-B3: `fpga/HARDWARE_SSOT.md` references the formal lemmas. |
| 92 | +- AC-B4: `./scripts/tri test` passes (575/575 baseline maintained). |
| 93 | +- AC-B5: Close-out report + evidence + W403 cooperation variants committed. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## 6. Risks |
| 98 | + |
| 99 | +- **Lean 4 toolchain drift:** the existing `lakefile.toml` may need updates for |
| 100 | + new module inclusion; keep changes minimal. |
| 101 | +- **Proof complexity:** full bit-accurate 7-series STAT decoding is unnecessary; |
| 102 | + focus on the high-level decision predicates used in `fpga/HARDWARE_SSOT.md`. |
| 103 | +- **CI time:** adding a new Lean module must not push `tri test` over budget; |
| 104 | + the module is small. |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +*φ² + φ⁻² = 3 | TRINITY* |
0 commit comments