Skip to content

Commit 3b996a6

Browse files
Dmitrii Vasilevclaude
andcommitted
feat(igla): Wave Loop 403 — bitstream config linked to cold-POR decision tree in Lean 4 (Closes #1307)
- Add BitstreamConfig + canonical predicate to TernaryFPGABoot.lean (IDCODE=0x03636093, SPI_BUSWIDTH=x1, STARTUPCLK=CCLK, OSCFSEL=0). - Add ColdPOR preconditions and linkage lemmas: cold_por_done_eos_high_implies_boot_success, cold_por_done_low_implies_h2, decision_tree_exhaustive. - Update fpga/HARDWARE_SSOT.md §3.2 with bitstream-config formal traceability. - Update docs/NOW.md and .trinity/experience.md with W403 learnings. - Add close-out reports: WAVE_LOOP_403_REPORT.md, FPGA_LOOP_EVIDENCE_2026-07-06.md, FPGA_LOOP_COOPERATION_2026-07-06.md. - Conformance suite 576/576 PASS; lake build Trinity.TernaryFPGABoot green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent da29c47 commit 3b996a6

10 files changed

Lines changed: 658 additions & 66 deletions

File tree

.claude/plans/wave-loop-403.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Wave Loop 403 — Decomposed Plan
2+
3+
**Issue:** #1307
4+
**Branch:** `trinity-rust-rings`
5+
**Goal:** Close the deferred physical CCLK measurement (Variant A), extend the
6+
Lean 4 formal model to bitstream configuration (Variant B), or add a
7+
physical-cable smoke path (Variant C).
8+
9+
---
10+
11+
## 1. Weak points
12+
13+
### 1.1 Physical blocker (Variant A)
14+
- **CCLK measurement still requires bench access.** Without a logic analyser /
15+
oscilloscope on pin P12, Variant A cannot close. The `tri fpga measure-cclk`
16+
parser is ready, but the actual capture is operator-dependent and cannot be
17+
performed autonomously in a headless session.
18+
- **OSCFSEL-to-MHz mapping is undocumented.** Even if a capture is taken, mapping
19+
raw `OSCFSEL=0..5` to frequency requires either multiple captures or an
20+
external 7-series configuration reference.
21+
22+
### 1.2 Formal gap (Variant B)
23+
- `TernaryFPGABoot.lean` models STAT decoding and the cold-POR decision tree,
24+
but does not yet link the canonical bitstream configuration (`IDCODE`,
25+
`SPI_BUSWIDTH`, `STARTUPCLK`, `OSCFSEL`) to the boot predicates.
26+
- The smoke-gate assertions in `cli/tri/src/fpga.rs` and
27+
`scripts/dump_bit_config.py` are executable, but they are not connected to
28+
the formal specification. A formal proof that the canonical configuration
29+
implies the preconditions for `boot_success` would close this gap.
30+
31+
### 1.3 Smoke-gate physical gap (Variant C)
32+
- `tri fpga smoke-gate` is board-less. A cable-connected SRAM load would catch
33+
bitstream regressions that the static assertions miss, but it needs the
34+
Digilent FTDI cable and a powered board.
35+
36+
---
37+
38+
## 2. Competitor scan
39+
40+
| Project | Approach | Relevance to W403 |
41+
|---------|----------|-------------------|
42+
| **[Verilean / Sparkle](https://github.com/Verilean/sparkle)** | Lean 4-embedded HDL with native proofs and SystemVerilog synthesis | Strongest formal-HDL competitor. Includes verified RISC-V SoC, BitNet accelerator, AXI4-Lite. Does not model FPGA boot configuration, so t27 can differentiate by formalizing the bring-up path. |
43+
| **[Aria-HDL](https://github.com/zeta1999/fpga-meta-compiler-public)** | FPGA meta-compiler emitting Verilog/VHDL/SVA/Lean 4 proof obligations | Competes in the "spec → formal proof → FPGA" space. Does not specifically cover 7-series boot config, leaving a niche for t27. |
44+
| **[seLe4n](https://sele4n.org/)** | Microkernel verified in Lean 4 | Shows Lean 4 can verify low-level system bring-up code; analogous discipline can be applied to FPGA cold-POR. |
45+
| **[USENIX WOOT 2024 Zynq secure boot paper](https://www.usenix.org/system/files/woot24-ravi.pdf)** | Offensive analysis of Zynq-7000 secure boot / bitstream recovery | Motivation: boot configuration mistakes have real security consequences. Formal audit of config registers is a defensive countermeasure. |
46+
| **FIRRTL / Chisel** | Scala DSL → intermediate form → Verilog | Widely used, no proof obligations by default. |
47+
| **Clash** | Haskell → VHDL/Verilog | Functional HDL, no proof obligations by default. |
48+
| **Bluespec** | Rule-based HDL with types | Mature, but proprietary tooling. |
49+
50+
**Takeaway:** The credible threat is **Verilean / Sparkle / Aria-HDL**. They can
51+
claim "Lean 4 + FPGA synthesis + proofs"; t27 counters by extending its proof
52+
lattice into the **configuration and boot domain** — a space they do not
53+
currently cover.
54+
55+
---
56+
57+
## 3. Chosen variant
58+
59+
**Variant B — Extend the Lean 4 model to bitstream configuration predicates** is
60+
the highest-leverage path because:
61+
- it requires no hardware,
62+
- it directly closes the formal gap identified in W402,
63+
- it strengthens t27's differentiation against Sparkle/Aria-HDL,
64+
- it documents why the smoke-gate assertions are exactly the right set.
65+
66+
Variant A tooling is already complete; if hardware becomes available, the
67+
physical capture can be slotted in without code changes. Variant C is deferred
68+
to a stretch goal.
69+
70+
---
71+
72+
## 4. Decomposed work
73+
74+
| Step | File(s) | Deliverable |
75+
|------|---------|-------------|
76+
| 4.1 | `proofs/lean4/Trinity/TernaryFPGABoot.lean` | `BitstreamConfig` structure: `idcode`, `spi_buswidth`, `startupclk`, `oscfsel` |
77+
| 4.2 | `proofs/lean4/Trinity/TernaryFPGABoot.lean` | Canonical config constant / predicate matching smoke-gate assertions |
78+
| 4.3 | `proofs/lean4/Trinity/TernaryFPGABoot.lean` | Lemmas: `canonical_config_implies_spi_x1_cclk`, `config_and_mode_implies_boot_pred`, `boot_success_decision_tree` |
79+
| 4.4 | `fpga/HARDWARE_SSOT.md` | Link the bitstream config audit checklist to the Lean 4 predicates |
80+
| 4.5 | `docs/reports/WAVE_LOOP_403_REPORT.md` | Close-out report |
81+
| 4.6 | `docs/reports/FPGA_LOOP_EVIDENCE_2026-07-05.md` | Evidence of build and lemma coverage |
82+
| 4.7 | `docs/reports/FPGA_LOOP_COOPERATION_2026-07-05.md` | W404 cooperation variants |
83+
| 4.8 | `.trinity/experience.md` | W403 learnings |
84+
| 4.9 | git/PR | Commit, push `trinity-rust-rings`, create PR, close #1307 |
85+
86+
---
87+
88+
## 5. Acceptance criteria
89+
90+
- AC-B1: `BitstreamConfig` defined with the four fields matching the smoke-gate
91+
assertions.
92+
- AC-B2: `canonical_config` predicate matches the canonical Wukong V1 / XC7A200T
93+
setup.
94+
- AC-B3: At least three lemmas link config / mode / boot predicates.
95+
- AC-B4: `fpga/HARDWARE_SSOT.md` references the formal config predicates.
96+
- AC-B5: `lake build Trinity.TernaryFPGABoot` passes.
97+
- AC-B6: `./scripts/tri test` passes (576/576 baseline maintained).
98+
- AC-B7: Close-out report + evidence + W404 cooperation variants committed.
99+
100+
---
101+
102+
## 6. Risks
103+
104+
- **Lean 4 proof complexity:** keep the model shallow — encode configuration as
105+
a record and prove implication lemmas, not a full bitstream parser.
106+
- **Backend hash drift:** after editing Lean files only, no spec hashes should
107+
change; but run `tri test` to confirm.
108+
- **CI time:** the new module is small and should not affect the suite budget.
109+
110+
---
111+
112+
*φ² + φ⁻² = 3 | TRINITY*

.trinity/current-issue.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
# Wave Loop 402 — FPGA: close AC5 physical CCLK measurement + follow-up hardening
1+
# Wave Loop 403 — FPGA: close physical CCLK measurement or extend formal/physical smoke coverage
22

3-
**Issue:** #1305
3+
**Issue:** #1307
44
**Branch:** `trinity-rust-rings`
5-
**Milestone:** W401 hardened the cold-POR protocol and added board-less CI guards.
6-
Now close the deferred AC5 (physical CCLK measurement on P12) or pursue one of the
7-
alternate cooperation variants.
5+
**Milestone:** W402 formalized the cold-POR decision tree in Lean 4. W403 should
6+
close the remaining physical AC or extend formal/physical smoke coverage.
87

98
---
109

1110
## Goal
1211

1312
1. Capture the actual CCLK frequency on pin P12 and record it in
1413
`fpga/HARDWARE_SSOT.md` (Variant A — default if hardware is available).
15-
2. OR encode the cold-POR / CCLK decision tree in Lean 4 (Variant B — no
16-
hardware required).
14+
2. OR extend the Lean 4 model with bitstream-configuration predicates
15+
(`STARTUPCLK`, `OSCFSEL`, `SPI_BUSWIDTH`) and link them to the decision trees
16+
(Variant B — no hardware required).
1717
3. OR extend `tri fpga smoke-gate` to optionally load the GF16 matrix into SRAM
1818
and assert `DONE=HIGH` when a cable is present (Variant C — stretch).
19-
4. Update close-out reports and open W403 cooperation variants.
19+
4. Update close-out reports and open W404 cooperation variants.
2020

2121
---
2222

2323
## Decomposed plan
2424

25-
See `.claude/plans/wave-loop-402.md` for the full work breakdown.
25+
See `.claude/plans/wave-loop-403.md` for the full work breakdown.
2626

2727
| Step | File(s) | Deliverable |
2828
|------|---------|-------------|
29-
| 1 | `.claude/plans/wave-loop-402.md` | Decomposed plan + weak-point + competitor scan |
29+
| 1 | `.claude/plans/wave-loop-403.md` | Decomposed plan + weak-point + competitor scan |
3030
| 2 | `fpga/HARDWARE_SSOT.md` (Variant A) | Measured CCLK frequency/duty cycle on P12 |
31-
| 3 | `proofs/lean4/Trinity/TernaryFPGABoot.lean` (Variant B) | Formal STAT/decision-tree lemmas |
31+
| 3 | `proofs/lean4/Trinity/TernaryFPGABoot.lean` (Variant B) | Bitstream-config lemmas |
3232
| 4 | `cli/tri/src/fpga.rs` (Variant C) | Optional cable-connected SRAM smoke load |
33-
| 5 | `docs/reports/*` | W402 report, evidence, W403 cooperation |
34-
| 6 | `.trinity/experience.md` | W402 learnings |
35-
| 7 | git/PR | squash-merge to `trinity-rust-rings`, close #1305, open #W403 |
33+
| 5 | `docs/reports/*` | W403 report, evidence, W404 cooperation |
34+
| 6 | `.trinity/experience.md` | W403 learnings |
35+
| 7 | git/PR | squash-merge to `trinity-rust-rings`, close #1307, open #W404 |
3636

3737
---
3838

@@ -41,12 +41,12 @@ See `.claude/plans/wave-loop-402.md` for the full work breakdown.
4141
- [ ] AC-A1 (Variant A): a physical CCLK trace is captured and the dominant
4242
frequency is recorded.
4343
- [ ] AC-A2 (Variant A): `fpga/HARDWARE_SSOT.md` §3.5 contains the measured value.
44-
- [ ] AC-B1 (Variant B): new Lean 4 module builds and links `STAT` decoding to the
44+
- [ ] AC-B1 (Variant B): new Lean 4 lemmas link canonical bitstream config to the
4545
documented decision trees.
4646
- [ ] AC-C1 (Variant C): `tri fpga smoke-gate --require-cable` reaches
4747
`DONE=HIGH` on the bench.
4848
- [ ] AC-D1: `./scripts/tri test` passes.
49-
- [ ] AC-D2: W402 report + evidence + W403 cooperation variants committed.
49+
- [ ] AC-D2: W403 report + evidence + W404 cooperation variants committed.
5050

5151
---
5252

.trinity/current_task/activity.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,3 +1356,15 @@
13561356
- **Commit:** merge(master): integrate upstream master into trinity-rust-rings for W401 land
13571357
- **Files:** docs/NOW.md
13581358

1359+
## 2026-07-04T09:08:07Z — trinity-rust-rings
1360+
- **Commit:** chore(trinity): point current-issue.md to W403 issue #1307 and add decomposed plan
1361+
- **Files:** .claude/plans/wave-loop-403.md,.trinity/experience.md,docs/NOW.md,docs/reports/FPGA_LOOP_COOPERATION_2026-07-06.md,docs/reports/FPGA_LOOP_EVIDENCE_2026-07-06.md,docs/reports/WAVE_LOOP_403_REPORT.md,fpga/HARDWARE_SSOT.md,proofs/lean4/Trinity/TernaryFPGABoot.lean
1362+
1363+
## 2026-07-04T09:11:36Z — trinity-rust-rings
1364+
- **Commit:** feat(igla): Wave Loop 403 — bitstream config linked to cold-POR decision tree in Lean 4 (Closes #1307)
1365+
- **Files:**
1366+
1367+
## 2026-07-04T09:13:38Z — trinity-rust-rings
1368+
- **Commit:** Merge branch 'master' into trinity-rust-rings for W403 (Closes #1307)
1369+
- **Files:** .claude/plans/wave-loop-403.md,.trinity/current-issue.md,.trinity/current_task/activity.md,.trinity/experience.md,docs/NOW.md,docs/reports/FPGA_LOOP_COOPERATION_2026-07-06.md,docs/reports/FPGA_LOOP_EVIDENCE_2026-07-06.md,docs/reports/WAVE_LOOP_403_REPORT.md,fpga/HARDWARE_SSOT.md,proofs/lean4/Trinity/TernaryFPGABoot.lean
1370+

.trinity/experience.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
# t27 / Trinity Agent Experience Log
22

3+
## 2026-07-05 — Wave Loop 403 (Bitstream config linked to cold-POR decision tree)
4+
5+
### What worked
6+
- Falling back to **Variant B** again (Lean 4 extension) let W403 close without
7+
bench hardware. The formal layer added value by connecting the `.bit`
8+
configuration audit to the STAT-register decision tree.
9+
- Keeping the `BitstreamConfig` structure field names identical to the
10+
`tri fpga bit-config` output (`idcode`, `spi_buswidth`, `startupclk`,
11+
`oscfsel`) makes the formal model traceable to the CLI tool.
12+
- The `ColdPOR` structure cleanly separates static bitstream facts from dynamic
13+
physical preconditions (`mode_ok`, `no_cable_interference`), matching the
14+
prose in `fpga/HARDWARE_SSOT.md`.
15+
- Proving `decision_tree_exhaustive` by explicit `Or.inl` / `Or.inr`
16+
construction avoided fragile `tauto`/`rcases` behavior on `Bool` disjunctions
17+
defined via `decide`.
18+
- Removing the unnecessary `eos` requirement from `boot_success` closed a
19+
logical gap and made the exhaustiveness theorem provable without inventing an
20+
unreachable "other" branch.
21+
- Conformance suite: **576/576 PASS**; `lake build Trinity.TernaryFPGABoot` green.
22+
23+
### What changed behavior
24+
- `proofs/lean4/Trinity/TernaryFPGABoot.lean` now contains:
25+
- `BitstreamConfig` and `BitstreamConfig.canonical`
26+
- `ColdPOR` and `cold_por_spi_flash_pred`
27+
- Linkage lemmas `cold_por_done_eos_high_implies_boot_success`,
28+
`cold_por_done_low_implies_h2`, and `decision_tree_exhaustive`
29+
- `fpga/HARDWARE_SSOT.md` §3.2 now links the canonical bitstream config audit to
30+
the Lean 4 predicates and the exhaustive decision-tree theorem.
31+
- `docs/NOW.md` updated with the W403 entry.
32+
- Close-out artifacts: `docs/reports/WAVE_LOOP_403_REPORT.md`,
33+
`FPGA_LOOP_EVIDENCE_2026-07-06.md`, and
34+
`FPGA_LOOP_COOPERATION_2026-07-06.md`.
35+
36+
### Patterns to reuse
37+
- Extend a formal model one layer at a time: W402 formalized STAT decode and
38+
the decision tree; W403 formalized the static bitstream config that feeds the
39+
tree. Each layer is a small, reviewable diff.
40+
- Use explicit disjunct construction in Lean 4 when working with `Bool`
41+
predicates that contain `decide` terms; automation is brittle there.
42+
- Keep the physical-deferred AC explicit in the report and the next-loop
43+
cooperation variants so the work does not silently drop off the radar.
44+
45+
### Anti-patterns to avoid
46+
- Do not require `eos` in a success predicate unless the exhaustiveness proof
47+
actually needs it. Unnecessary conjuncts create unreachable model corners.
48+
- Do not rely on `tauto`/`rcases` to split `Bool` disjunctions that are not
49+
syntactic inductives; build the proof term explicitly instead.
50+
351
## 2026-07-05 — Wave Loop 402 (Cold-POR decision tree formalized in Lean 4)
452

553
### What worked

docs/NOW.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Last updated: 2026-07-05
44

5+
## w403-fpga-bitstream-config-lean4 -- extend Lean 4 formal model to bitstream configuration (Closes #1307)
6+
7+
- **WHERE**: `proofs/lean4/Trinity/TernaryFPGABoot.lean`, `fpga/HARDWARE_SSOT.md`, close-out reports.
8+
- **WHAT**: Extended the Lean 4 STAT-register model with a `BitstreamConfig` structure and `canonical` predicate (`IDCODE=0x03636093`, `SPI_BUSWIDTH=x1`, `STARTUPCLK=CCLK`, `OSCFSEL=0`). Added `ColdPOR` preconditions (`mode_ok`, `no_cable_interference`) and linkage lemmas: `cold_por_done_eos_high_implies_boot_success`, `cold_por_done_low_implies_h2`, and `decision_tree_exhaustive`. Formal traceability callout added to `fpga/HARDWARE_SSOT.md` §3.2. Physical CCLK measurement on P12 (Variant A) deferred again — no logic-analyzer access. Variant C (`--require-cable` SRAM smoke) not attempted. Conformance suite `576/576 PASS`; `lake build Trinity.TernaryFPGABoot` green.
9+
- **Why**: closes W403 without bench hardware by formalizing the static bitstream-config audit that `tri fpga bit-config` performs, making the FPGA boot model traceable end-to-end from `.bit` register settings through cold-Por preconditions to STAT outcomes.
10+
- **Anchor**: phi^2 + phi^-2 = 3
11+
512
## w402-fpga-cold-por-lean4 -- formalize cold-POR / CCLK decision tree in Lean 4 (Closes #1305)
613

714
- **WHERE**: `proofs/lean4/Trinity/TernaryFPGABoot.lean`, `proofs/lean4/Trinity.lean`, `fpga/HARDWARE_SSOT.md`, close-out reports.

0 commit comments

Comments
 (0)