aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / docs / btwave / CONTRACT.md
| 1 | # btwave: Balanced-Ternary Harmonic Waveguide and Give-Before-Take Compute Engine (Contract P0) |
| 2 | |
| 3 | `native/btwave/` is a 100% pure seeded OM-2 (`om2`) compute, transport, admission, and verification |
| 4 | stack compiled directly to static Linux AArch64 machine code by the 3-stage seeded Omega compiler |
| 5 | (`omc`). It contains zero C, C++, Rust, Python, or shell implementation or harness code. |
| 6 | |
| 7 | ## Scope and Lineage |
| 8 | |
| 9 | | Item | Pin / Value | |
| 10 | | --- | --- | |
| 11 | | Source modules | `native/btwave/trit.om`, `native/btwave/ledger.om`, `native/btwave/wave_ipc.om`, `native/btwave/main.om` | |
| 12 | | Pure OM-2 gate runner | `native/btwave/gate.om` (concatenated after `native/btwave/trit.om`) | |
| 13 | | Root bootstrap seed | `omega-mv` `seed/rung0/seed0.hex` sha256 `baaf081fe6055a768485c5d25d7435681ce00b04cfa80b26c48169f78944e14d` | |
| 14 | | Seeded compiler source | `omega-mv` `713c9c079c2d97b58a2832495ddc7a374d462758` `seed/omc/omc.om` sha256 `c86159627820cf5741be0a2a4c05df0efb78f5c91a652b986fec5d745baa62ed` | |
| 15 | | Pinned `omc` binary | 3-stage fixpoint `seed/out/omc` sha256 `f4fa7951816bbd09c5eaaae6692852a70c3c305164b365027c5b683dec7d63e9` | |
| 16 | | Product source stream | `cat trit.om ledger.om wave_ipc.om main.om` sha256 `29de9fda42b04b1bf51b459a0bc4612fdcfa7f93d192d0f6ad3bdd9454191689` | |
| 17 | | Product ELF binary | sha256 `583209bf9bcf8dda9a3a976e2e45e4d19ac6cdd28a0b2dbe7e1147deb9d975a2` (`79,472 B` `MEASURED`, 3x deterministic) | |
| 18 | | Wolfram trace digest | `b0c6399a7ae894148e8e1678a272add68385bdf67d6221044ded82216fb73575` (`evidence/BTWAVE-P0/expected-trace.out`) | |
| 19 | |
| 20 | ## Non-Binary Balanced-Ternary Algebra (`native/btwave/trit.om`) |
| 21 | |
| 22 | 1. **SWAR 32-Trit Packed Representation (`Trit32`)**: |
| 23 | - Packs `32` balanced trits in `{-1, 0, +1}` into one `ulong` (`64 bits`, `2.0 bits/trit` `MODELED`): |
| 24 | upper `32 bits` hold positive carrier mask `pos32`, lower `32 bits` hold negative carrier mask |
| 25 | `neg32`. |
| 26 | - Declared as `abstract Trit32 ulong ops rotr rotl`. Constructor `Trit32mk` enforces the |
| 27 | postcondition `((w >> 32) & (w & 0xffffffff)) == 0`; any overlapping `(1, 1)` carrier pair |
| 28 | immediately triggers OM-2 contract trap `10` (process exit `110` `MEASURED`). |
| 29 | - **1-op negation (`t32neg`)**: `rotr a 32` swaps `pos32` and `neg32` across all `32` lanes in a |
| 30 | single AArch64 `ROR` instruction (`1 op` `MODELED`, zero carries, zero sign-extension bias). |
| 31 | - **Zero-multiply wave product (`t32mul`)**: computes all `32` balanced-ternary lane products in |
| 32 | parallel via bitwise `AND`/`OR`/`ROR` (`0` hardware integer multiplies `MODELED`). |
| 33 | - **Branchless inner product (`t32dot`)**: evaluates `pop32(pos32) - pop32(neg32)` in `[-32, +32]` |
| 34 | using shift-mask SWAR popcount (`0` branches, `0` multiplies `MODELED`). |
| 35 | |
| 36 | 2. **Multi-Scale Balanced-Ternary Codec (`M = 6`) and `16/16` Hypercube Witness (`M = 3`)**: |
| 37 | - `bt6enc` / `bt6dec` map the symmetric integer lattice `[-364, +364]` bijectively onto `3^6 = 729` |
| 38 | states (`729/729` exact round-trips `MODELED` and `MEASURED`). |
| 39 | - **Dark Consensus (`bt6enc(0) = 0`)**: zero maps to `pos32 = 0, neg32 = 0` (`0` active carriers |
| 40 | out of `32` `MODELED` and `MEASURED`), eliminating quiescent binary DC bias. |
| 41 | - **Hypercube reconstruction (`hc3enc` / `hc3dec`)**: embeds all `16` corners of `{0, 1}^4` into |
| 42 | `M = 3` balanced trits (`3^3 = 27 > 16` states `MODELED`), achieving `16/16` exact corner |
| 43 | reconstruction (`MEASURED` and proved in Lean 4) whereas any `4` central binary hyperplanes in |
| 44 | `R^3` realize at most `14 < 16` strict sign orthants (`MODELED`, proved in |
| 45 | `nl1_four_central_hyperplanes_r3_at_most_14`). |
| 46 | |
| 47 | 3. **Sylvester Walsh-Hadamard `H16` Wave Spreading (`h16enc` / `h16dec`)**: |
| 48 | - Encodes `5-bit` symbol `sym in 0..31` (4-bit Hadamard row index + 1-bit polarity) across `16` |
| 49 | orthogonal ternary carriers with minimum Hamming distance `d_H = 8 trits` (`MODELED`, proved in |
| 50 | Lean 4 and verified exhaustively in Wolfram). |
| 51 | - Corrects `100%` of `0, 1, 2, 3`-carrier sign flips or erasures (`32/32`, `512/512`, `360/360`, |
| 52 | and `1120/1120` `MEASURED`) and fail-closed returns `-1` on `>= 4`-carrier midpoint ties |
| 53 | (`70/70` `MEASURED`). |
| 54 | |
| 55 | ## Give-Before-Take Reciprocal Ledger (`native/btwave/ledger.om`) |
| 56 | |
| 57 | - **Compile-time capability separation**: `abstract CreditJ ulong` (earned compute credit) and |
| 58 | `abstract GrantJ ulong` (authorized compute extraction) have no implicit conversion. Swapping |
| 59 | `CreditJ`, `GrantJ`, `Trit32`, or `WaveDup` at any call site is refused at compile time by `omc` |
| 60 | with exit status `7` (`4/4` type-swap mutants refused `MEASURED`). |
| 61 | - **Mirrored waveguide frame tag**: `abstract WaveDup ulong` with `holds WaveDup dup32` traps `10` |
| 62 | (exit `110` `MEASURED`) if upper and lower 32-bit halves diverge. |
| 63 | - **Chained FIPS 180-4 SHA-256 work receipts**: every admitted Give and Take stores a new 32-byte |
| 64 | `Lchain` digest over `chain32 || epoch_le8 || units_le8 || response_tc_le8` (`56 B` message). |
| 65 | `rcpt_eq` compares 32 bytes under ARM64 `dit 1` + `scrub 64`. Inside `ldg_give` that compare is |
| 66 | against a copy of the digest just computed, flipped only when mode is 3. The IPC host is the |
| 67 | path that compares a received frame to a recomputed receipt (`host_give_round` / `rx_rcpt_ok`, |
| 68 | returning `-44` on mismatch). Before that compare, `host_give_round` requires the returned job |
| 69 | wave to equal `job_wave(sym)` for the symbol it sent, returning `-46` otherwise, so Node B cannot |
| 70 | earn credit for a wrong decode that carries a self-consistent receipt. |
| 71 | - **Reciprocity invariant**: `extracted <= contributed` holds initially (`0 <= 0`) and across every |
| 72 | admitted or refused event; zero-contribution peers cannot extract (`-9`), overdrafts are refused |
| 73 | (`-10`). A refusal leaves `epoch`, `contributed`, `extracted`, and `Lchain` unchanged. `Lresp` |
| 74 | is cleared to `0` at the start of `ldg_step`, including on refusal (`MEASURED` in |
| 75 | `expected-trace.out`: case 1 stores response `-120`, case 2 refusal stores `0`, while `epoch`, |
| 76 | `contributed`, `extracted`, and `Lchain` stay put). Lean 4 proves `extracted <= contributed` for |
| 77 | a numeric `(epoch, contributed, extracted)` state and admission flag; that model does not include |
| 78 | `Lresp` or the codec (`MEASURED` across 16 trace cases + 23 mutants). |
| 79 | |
| 80 | | Status | Meaning | Guard location | |
| 81 | | --- | --- | --- | |
| 82 | | `0` | Admitted (`GIVE` credits work; `TAKE` grants compute within credit) | `ldg_give` / `ldg_take` | |
| 83 | | `-1` | Invalid opcode (`op != 1` and `op != 2`) | `ldg_step` | |
| 84 | | `-2` | Non-sequential or negative epoch (`req_epoch != epoch + 1`) | `ldg_step` | |
| 85 | | `-3` | Invalid `GIVE` work bounds (`work == 0`, `work > 1000`, `take != 0`, or bad symbol) | `ldg_step` / `ldg_give` | |
| 86 | | `-4` | `H16` wave decode refusal (`>= 4` carrier corruptions / midpoint tie) | `ldg_give` | |
| 87 | | `-5` | Incomplete active carrier power (`t32pow(job_wave) != 32`) | `ldg_give` | |
| 88 | | `-6` | Scale out of admitted range (`sc == 0` or `|sc| > 65536`) | `scale_bad` | |
| 89 | | `-7` | Caller set mode 3, so the computed receipt copy differs by one byte. `ldg_give` does not read an external receipt. The IPC host compares the child frame to a receipt it recomputes (`host_give_round`); a mismatch there returns `-44`, not `-7`. | `ldg_give` when `mode == 3`; IPC check is `rx_rcpt_ok` (returns `-44`) | |
| 90 | | `-8` | Invalid `TAKE` grant bounds (`take == 0`, `take > 1000`, or `work != 0`) | `ldg_take` | |
| 91 | | `-9` | Parasitic `TAKE` before any verified `GIVE` (`contributed == 0`) | `ldg_take` (`cred_pos`) | |
| 92 | | `-10` | Reciprocity overdraft (`extracted + take > contributed`) | `ldg_take` (`recip_ok`) | |
| 93 | | `-11` | Caller set mode 5. `host_take_round` sets that mode when the first 8 bytes of the frame chain differ from `ldg_chid`. This is not a 32-byte compare inside `ldg_take`. | `ldg_take` when `mode == 5` | |
| 94 | | `-12` | Not reachable from `ldg_step`. The function rebuilds a mirrored tag from the epoch and checks that tag against itself. A non-mirrored `WaveDup` traps 10 (exit 110) in the constructor (`trap-dup`), which is not status `-12`. | no return path | |
| 95 | |
| 96 | ## Duplex Cross-Core Waveguide (`native/btwave/wave_ipc.om`) |
| 97 | |
| 98 | - Forks a child worker (`fork`) connected over two unidirectional Linux `pipefds` carrying fixed |
| 99 | `80-byte` raw binary/ternary frames (`0 B` JSON/Protobuf overhead `MODELED`). |
| 100 | - Pins host Node A to Arm Cortex-X925 core `16` and child Node B to Arm Cortex-X925 core `17` on |
| 101 | NVIDIA GB10 (`3900 MHz` max clock, cores `3, 7, 15` strictly excluded via `pin_core` `requires` |
| 102 | contract) and verifies placement via `cpunow`. |
| 103 | - Executes `8` full-duplex waveguide rounds (`4` noisy `H16` Give jobs with 2 injected carrier flips |
| 104 | decoded on core `17`; the host credits `60` units per round only after checking the returned job |
| 105 | wave against `job_wave(sym)` and the receipt, earning `240` credit units; `1` overdraft Take of |
| 106 | `300` units refused with `-10`; and `3` admitted Take rounds extracting `180 <= 240` units), |
| 107 | completing in `168,610 ns` (`0.169 ms` `MEASURED` via `monons` on Cortex-X925 cores `16` and `17`, |
| 108 | `evidence/BTWAVE-P0/ipc.stdout`; `elapsed_ns` varies per run). |
| 109 | - On any host refusal (`-41` to `-46`, `-51` to `-53`, wrong overdraft or take status), `ipc_run` |
| 110 | closes the host pipe ends before `waitpid` (`ipc_shut`), Node B reads end-of-file and exits, and |
| 111 | `btwave ipc` exits with the host code (`65`, `66`, or `67`) instead of blocking. |
| 112 | |
| 113 | ## Pure OM-2 Gate and Mutant Harness (`native/btwave/gate.om`) |
| 114 | |
| 115 | Build and run from the repository root on Linux AArch64 (passing a scratch copy of |
| 116 | `evidence/BTWAVE-P0` so committed `receipt.tsv` and `ipc.stdout` stay untouched; `gate.om` opens |
| 117 | `native/btwave/*.om` relative to the working directory and fails at step `5` otherwise). The |
| 118 | block uses a private `mktemp -d` directory and ends with the gate's own exit status (table below), |
| 119 | so a scripted run fails when the gate fails: |
| 120 | |
| 121 | ```sh |
| 122 | T=$(mktemp -d) |
| 123 | cat native/btwave/trit.om native/btwave/gate.om | "$OMC" > "$T/gate" |
| 124 | chmod +x "$T/gate" |
| 125 | cp -r evidence/BTWAVE-P0 "$T/ev" |
| 126 | "$T/gate" "$OMC" "$T/ev"; rc=$? |
| 127 | rm -rf "$T" |
| 128 | (exit "$rc") |
| 129 | ``` |
| 130 | |
| 131 | | Gate exit | Meaning | |
| 132 | | --- | --- | |
| 133 | | `0` | `BTWAVE PASS`: compiler pin verified, 3x deterministic build + Wolfram trace match, cross-core IPC pass, negative controls pass, `23/23` mutants killed (including `m23-ipc-peer-wrong-job`, which must make `btwave ipc` exit `65` with empty stdout), `4/4` type swaps refused (`omc` error `7`) | |
| 134 | | `1` | Gate check or mutant kill failed (prints step code to stderr) | |
| 135 | | `2` | Usage error | |
| 136 | | `77` | `BTWAVE NOT_RUN`: `<omc_path>` SHA-256 does not match pinned `seed/out/omc` | |
| 137 | |
| 138 | ## Not Run or Not Claimed |
| 139 | |
| 140 | - **GB10 Blackwell GPU execution**: `NOT_RUN`. All measurements in `BTWAVE-P0` execute on Arm |
| 141 | Cortex-X925 CPU cores `16-18` (and Lean 4 verification on Cortex-A725 cores `0-1`). |
| 142 | - **Multi-host socket / RDMA transport**: `NOT_RUN`. P0 waveguide transport exercises cross-core |
| 143 | multi-process `pipefds` on a single Linux AArch64 host. |
| 144 | - **LLM / LoRA weight training or AEGIS capability authority**: `NOT_RUN`. `btwave` provides the |
| 145 | non-binary balanced-ternary algebra, harmonic codec, and reciprocal ledger P0 engine only. |