|
| 1 | +// SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | += Rust/SPARK Stance — verisimdb |
| 3 | +:toc: macro |
| 4 | +:toclevels: 2 |
| 5 | + |
| 6 | +toc::[] |
| 7 | + |
| 8 | +== Summary |
| 9 | + |
| 10 | +VeriSimDB is a safety-critical cross-modal entity engine ("octad model": |
| 11 | +each entity exists across 8 modalities). Its application logic is written |
| 12 | +in Rust (workspace crates under `rust-core/` — `verisim-octad`, |
| 13 | +`verisim-graph`, `verisim-planner`, `verisim-drift`, `verisim-nif`, |
| 14 | +etc.). Per the estate language policy |
| 15 | +(`standards/rhodium-standard-repositories/spec/LANGUAGE-POLICY.adoc` |
| 16 | +§Terminology), *"Rust" means "Rust/SPARK"*: Rust is the primary |
| 17 | +implementation language now, but the project is *designed to admit |
| 18 | +SPARK/Ada verification modules* across a stable, Idris2-typed boundary, |
| 19 | +with Zig as the FFI layer. Rust here is never the ABI/API/FFI layer. |
| 20 | + |
| 21 | +This document is the project's compliance stance against that policy. |
| 22 | +Prior to this audit (2026-05-18) the seam (`src/abi/*.idr` + `ffi/zig/`) |
| 23 | +was present but carried *no stance doc* — a silent-regress risk flagged |
| 24 | +by the estate audit (status was "DESIGNED-ONLY"). This document records |
| 25 | +the seam honestly and brings the project to documented structural |
| 26 | +compliance. |
| 27 | + |
| 28 | +== What is correctness-critical here |
| 29 | + |
| 30 | +VeriSimDB is a database/verisimilitude engine, not a ledger. The |
| 31 | +correctness-critical surface is the cross-modal entity store, its drift |
| 32 | +detection, and the C ABI that exposes it to consumers. |
| 33 | + |
| 34 | +[cols="1,3",options="header"] |
| 35 | +|=== |
| 36 | +| Critical surface | Where |
| 37 | + |
| 38 | +| Result-code round-trip (no FFI status corruption) |
| 39 | +| `src/abi/Types.idr` — `vresultToInt` / `vresultFromInt`, `DecEq VResult` |
| 40 | + |
| 41 | +| Entity lifecycle / modality read-write safety |
| 42 | +| `src/abi/Foreign.idr` — `entityCreate`, `entityGet`, `entityDelete`, |
| 43 | + `modalityWrite`, `modalityRead` |
| 44 | + |
| 45 | +| C ABI struct layout fidelity |
| 46 | +| `src/abi/Layout.idr` — field offsets / sizes vs the Rust `#[repr(C)]` |
| 47 | + structs |
| 48 | + |
| 49 | +| Octad cross-modal consistency, drift thresholds |
| 50 | +| Rust workspace: `rust-core/verisim-octad`, `verisim-drift`, |
| 51 | + `verisim-graph` |
| 52 | +|=== |
| 53 | + |
| 54 | +== The seam |
| 55 | + |
| 56 | +[cols="1,3",options="header"] |
| 57 | +|=== |
| 58 | +| File | Role |
| 59 | + |
| 60 | +| `src/abi/Types.idr` |
| 61 | +| Idris2 boundary types — total models of `VResult`, `EntityId`, |
| 62 | + `EntityHandle`, modality masks. `%default total`. Constructor and |
| 63 | + integer-code order is ABI-significant and matches the Rust enums; |
| 64 | + `vresultFromInt . vresultToInt` is the round-trip obligation and |
| 65 | + `DecEq VResult` is discharged. |
| 66 | + |
| 67 | +| `src/abi/Layout.idr` |
| 68 | +| C-ABI struct layout — offsets/sizes that must match the Rust |
| 69 | + `#[repr(C)]` definitions consumed via `libverisimdb`. |
| 70 | + |
| 71 | +| `src/abi/Foreign.idr` |
| 72 | +| Zig/C-FFI boundary: every `%foreign "C:verisimdb_*, libverisimdb"` |
| 73 | + entry point, with safe Idris2 wrappers that decode raw `Bits32` |
| 74 | + returns back into `VResult` (defaulting to `VError` on out-of-range, |
| 75 | + i.e. fail-closed). |
| 76 | +|=== |
| 77 | + |
| 78 | +All three modules carry `%default total` and contain *zero* proof |
| 79 | +escapes (no `believe_me`, `assert_total`, `postulate`, `idris_crash`). |
| 80 | +They are checkable in principle with `idris2 --check src/abi/Types.idr` |
| 81 | +etc. The Idris2 toolchain is *not yet wired into CI*; wiring it is the |
| 82 | +primary tracked follow-up. |
| 83 | + |
| 84 | +`debugger/src/abi/` carries a parallel copy of the same three modules |
| 85 | +for the debugger component; the same total/no-escape property holds |
| 86 | +there. |
| 87 | + |
| 88 | +== SPARK/Ada admission path |
| 89 | + |
| 90 | +The boundary is the Idris2 seam above. A future SPARK/Ada |
| 91 | +re-implementation of any correctness-critical store/drift component sits |
| 92 | +on the far side of the `Foreign` C-ABI contract without changing it: it |
| 93 | +must honour the `VResult` code discipline and the `Layout` struct |
| 94 | +contract. No SPARK code exists yet; the seam exists so it *can* be added |
| 95 | +without redesign, which is exactly what §Terminology requires of a |
| 96 | +"designed to admit SPARK/Ada" Rust project. |
| 97 | + |
| 98 | +== Honest gaps |
| 99 | + |
| 100 | +* The Idris2 seam states the FFI *shape* contract (result-code |
| 101 | + round-trip, layout, total wrappers). It does *not* yet carry |
| 102 | + type-level statements of the deeper octad-consistency or |
| 103 | + drift-threshold invariants enforced (only) in the Rust workspace; |
| 104 | + those are owed, not proven. |
| 105 | +* `ffi/zig/src/main.zig` still contains unfilled `{{PROJECT}}` RSR |
| 106 | + template placeholders — the Zig implementation layer is scaffolding, |
| 107 | + not a finished faithful implementation of the `Foreign.idr` contract. |
| 108 | + This is a real gap on the FFI side, not merely a missing proof. |
| 109 | +* Idris2 is not in CI (`.tool-versions` carries no `idris2` entry), so |
| 110 | + the seam's totality is asserted, not gate-enforced. |
| 111 | +* The companion data repo `verisimdb-data` deliberately *removed* its |
| 112 | + template ABI Idris2 files (see its `PROOF-NEEDS.md`) to avoid a false |
| 113 | + formal-verification impression; that repo is data, not verified code, |
| 114 | + and makes no verification claims. |
| 115 | + |
| 116 | +== References |
| 117 | + |
| 118 | +* `standards/rhodium-standard-repositories/spec/LANGUAGE-POLICY.adoc` |
| 119 | + §Terminology, §"Rust is never the ABI" |
| 120 | +* Estate exemplar stance: `proof-of-work/RUST-SPARK-STANCE.adoc` |
| 121 | +* This repo's seam: `src/abi/{Types,Layout,Foreign}.idr` |
| 122 | +* Tracking: hyperpolymath/standards#124 |
0 commit comments