Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-train/blob/main/docs/btwave/CONTRACT.md # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-train / docs / btwave / CONTRACT.md` 145 lines ยท 11086 bytes Raw Blame History Source # btwave: Balanced-Ternary Harmonic Waveguide and Give-Before-Take Compute Engine (Contract P0) `native/btwave/` is a 100% pure seeded OM-2 (`om2`) compute, transport, admission, and verification stack compiled directly to static Linux AArch64 machine code by the 3-stage seeded Omega compiler (`omc`). It contains zero C, C++, Rust, Python, or shell implementation or harness code. ## Scope and Lineage Item Pin / Value Source modules `native/btwave/trit.om`, `native/btwave/ledger.om`, `native/btwave/wave_ipc.om`, `native/btwave/main.om` Pure OM-2 gate runner `native/btwave/gate.om` (concatenated after `native/btwave/trit.om`) Root bootstrap seed `omega-mv` `seed/rung0/seed0.hex` sha256 `baaf081fe6055a768485c5d25d7435681ce00b04cfa80b26c48169f78944e14d` Seeded compiler source `omega-mv` `713c9c079c2d97b58a2832495ddc7a374d462758` `seed/omc/omc.om` sha256 `c86159627820cf5741be0a2a4c05df0efb78f5c91a652b986fec5d745baa62ed` Pinned `omc` binary 3-stage fixpoint `seed/out/omc` sha256 `f4fa7951816bbd09c5eaaae6692852a70c3c305164b365027c5b683dec7d63e9` Product source stream `cat trit.om ledger.om wave_ipc.om main.om` sha256 `29de9fda42b04b1bf51b459a0bc4612fdcfa7f93d192d0f6ad3bdd9454191689` Product ELF binary sha256 `583209bf9bcf8dda9a3a976e2e45e4d19ac6cdd28a0b2dbe7e1147deb9d975a2` (`79,472 B` `MEASURED`, 3x deterministic) Wolfram trace digest `b0c6399a7ae894148e8e1678a272add68385bdf67d6221044ded82216fb73575` (`evidence/BTWAVE-P0/expected-trace.out`) ## Non-Binary Balanced-Ternary Algebra (`native/btwave/trit.om`) - SWAR 32-Trit Packed Representation (`Trit32`): - Packs `32` balanced trits in `{-1, 0, +1}` into one `ulong` (`64 bits`, `2.0 bits/trit` `MODELED`): upper `32 bits` hold positive carrier mask `pos32`, lower `32 bits` hold negative carrier mask `neg32`. - Declared as `abstract Trit32 ulong ops rotr rotl`. Constructor `Trit32mk` enforces the postcondition `((w >> 32) & (w & 0xffffffff)) == 0`; any overlapping `(1, 1)` carrier pair immediately triggers OM-2 contract trap `10` (process exit `110` `MEASURED`). - 1-op negation (`t32neg`): `rotr a 32` swaps `pos32` and `neg32` across all `32` lanes in a single AArch64 `ROR` instruction (`1 op` `MODELED`, zero carries, zero sign-extension bias). - Zero-multiply wave product (`t32mul`): computes all `32` balanced-ternary lane products in parallel via bitwise `AND`/`OR`/`ROR` (`0` hardware integer multiplies `MODELED`). - Branchless inner product (`t32dot`): evaluates `pop32(pos32) - pop32(neg32)` in `[-32, +32]` using shift-mask SWAR popcount (`0` branches, `0` multiplies `MODELED`). - Multi-Scale Balanced-Ternary Codec (`M = 6`) and `16/16` Hypercube Witness (`M = 3`): - `bt6enc` / `bt6dec` map the symmetric integer lattice `[-364, +364]` bijectively onto `3^6 = 729` states (`729/729` exact round-trips `MODELED` and `MEASURED`). - Dark Consensus (`bt6enc(0) = 0`): zero maps to `pos32 = 0, neg32 = 0` (`0` active carriers out of `32` `MODELED` and `MEASURED`), eliminating quiescent binary DC bias. - Hypercube reconstruction (`hc3enc` / `hc3dec`): embeds all `16` corners of `{0, 1}^4` into `M = 3` balanced trits (`3^3 = 27 > 16` states `MODELED`), achieving `16/16` exact corner reconstruction (`MEASURED` and proved in Lean 4) whereas any `4` central binary hyperplanes in `R^3` realize at most `14 < 16` strict sign orthants (`MODELED`, proved in `nl1_four_central_hyperplanes_r3_at_most_14`). - Sylvester Walsh-Hadamard `H16` Wave Spreading (`h16enc` / `h16dec`): - Encodes `5-bit` symbol `sym in 0..31` (4-bit Hadamard row index + 1-bit polarity) across `16` orthogonal ternary carriers with minimum Hamming distance `d_H = 8 trits` (`MODELED`, proved in Lean 4 and verified exhaustively in Wolfram). - Corrects `100%` of `0, 1, 2, 3`-carrier sign flips or erasures (`32/32`, `512/512`, `360/360`, and `1120/1120` `MEASURED`) and fail-closed returns `-1` on `>= 4`-carrier midpoint ties (`70/70` `MEASURED`). ## Give-Before-Take Reciprocal Ledger (`native/btwave/ledger.om`) - Compile-time capability separation: `abstract CreditJ ulong` (earned compute credit) and `abstract GrantJ ulong` (authorized compute extraction) have no implicit conversion. Swapping `CreditJ`, `GrantJ`, `Trit32`, or `WaveDup` at any call site is refused at compile time by `omc` with exit status `7` (`4/4` type-swap mutants refused `MEASURED`). - Mirrored waveguide frame tag: `abstract WaveDup ulong` with `holds WaveDup dup32` traps `10` (exit `110` `MEASURED`) if upper and lower 32-bit halves diverge. - Chained FIPS 180-4 SHA-256 work receipts: every admitted Give and Take stores a new 32-byte `Lchain` digest over `chain32 || epoch_le8 || units_le8 || response_tc_le8` (`56 B` message). `rcpt_eq` compares 32 bytes under ARM64 `dit 1` + `scrub 64`. Inside `ldg_give` that compare is against a copy of the digest just computed, flipped only when mode is 3. The IPC host is the path that compares a received frame to a recomputed receipt (`host_give_round` / `rx_rcpt_ok`, returning `-44` on mismatch). Before that compare, `host_give_round` requires the returned job wave to equal `job_wave(sym)` for the symbol it sent, returning `-46` otherwise, so Node B cannot earn credit for a wrong decode that carries a self-consistent receipt. - Reciprocity invariant: `extracted <= contributed` holds initially (`0 <= 0`) and across every admitted or refused event; zero-contribution peers cannot extract (`-9`), overdrafts are refused (`-10`). A refusal leaves `epoch`, `contributed`, `extracted`, and `Lchain` unchanged. `Lresp` is cleared to `0` at the start of `ldg_step`, including on refusal (`MEASURED` in `expected-trace.out`: case 1 stores response `-120`, case 2 refusal stores `0`, while `epoch`, `contributed`, `extracted`, and `Lchain` stay put). Lean 4 proves `extracted <= contributed` for a numeric `(epoch, contributed, extracted)` state and admission flag; that model does not include `Lresp` or the codec (`MEASURED` across 16 trace cases + 23 mutants). Status Meaning Guard location `0` Admitted (`GIVE` credits work; `TAKE` grants compute within credit) `ldg_give` / `ldg_take` `-1` Invalid opcode (`op != 1` and `op != 2`) `ldg_step` `-2` Non-sequential or negative epoch (`req_epoch != epoch + 1`) `ldg_step` `-3` Invalid `GIVE` work bounds (`work == 0`, `work > 1000`, `take != 0`, or bad symbol) `ldg_step` / `ldg_give` `-4` `H16` wave decode refusal (`>= 4` carrier corruptions / midpoint tie) `ldg_give` `-5` Incomplete active carrier power (`t32pow(job_wave) != 32`) `ldg_give` `-6` Scale out of admitted range (`sc == 0` or `|sc| > 65536`) `scale_bad` `-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`) `-8` Invalid `TAKE` grant bounds (`take == 0`, `take > 1000`, or `work != 0`) `ldg_take` `-9` Parasitic `TAKE` before any verified `GIVE` (`contributed == 0`) `ldg_take` (`cred_pos`) `-10` Reciprocity overdraft (`extracted + take > contributed`) `ldg_take` (`recip_ok`) `-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` `-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 ## Duplex Cross-Core Waveguide (`native/btwave/wave_ipc.om`) - Forks a child worker (`fork`) connected over two unidirectional Linux `pipefds` carrying fixed `80-byte` raw binary/ternary frames (`0 B` JSON/Protobuf overhead `MODELED`). - Pins host Node A to Arm Cortex-X925 core `16` and child Node B to Arm Cortex-X925 core `17` on NVIDIA GB10 (`3900 MHz` max clock, cores `3, 7, 15` strictly excluded via `pin_core` `requires` contract) and verifies placement via `cpunow`. - Executes `8` full-duplex waveguide rounds (`4` noisy `H16` Give jobs with 2 injected carrier flips decoded on core `17`; the host credits `60` units per round only after checking the returned job wave against `job_wave(sym)` and the receipt, earning `240` credit units; `1` overdraft Take of `300` units refused with `-10`; and `3` admitted Take rounds extracting `180 <= 240` units), completing in `168,610 ns` (`0.169 ms` `MEASURED` via `monons` on Cortex-X925 cores `16` and `17`, `evidence/BTWAVE-P0/ipc.stdout`; `elapsed_ns` varies per run). - On any host refusal (`-41` to `-46`, `-51` to `-53`, wrong overdraft or take status), `ipc_run` closes the host pipe ends before `waitpid` (`ipc_shut`), Node B reads end-of-file and exits, and `btwave ipc` exits with the host code (`65`, `66`, or `67`) instead of blocking. ## Pure OM-2 Gate and Mutant Harness (`native/btwave/gate.om`) Build and run from the repository root on Linux AArch64 (passing a scratch copy of `evidence/BTWAVE-P0` so committed `receipt.tsv` and `ipc.stdout` stay untouched; `gate.om` opens `native/btwave/*.om` relative to the working directory and fails at step `5` otherwise). The block uses a private `mktemp -d` directory and ends with the gate's own exit status (table below), so a scripted run fails when the gate fails: ``` T=$(mktemp -d) cat native/btwave/trit.om native/btwave/gate.om | "$OMC" > "$T/gate" chmod +x "$T/gate" cp -r evidence/BTWAVE-P0 "$T/ev" "$T/gate" "$OMC" "$T/ev"; rc=$? rm -rf "$T" (exit "$rc") ``` Gate exit Meaning `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`) `1` Gate check or mutant kill failed (prints step code to stderr) `2` Usage error `77` `BTWAVE NOT_RUN`: `` SHA-256 does not match pinned `seed/out/omc` ## Not Run or Not Claimed - GB10 Blackwell GPU execution: `NOT_RUN`. All measurements in `BTWAVE-P0` execute on Arm Cortex-X925 CPU cores `16-18` (and Lean 4 verification on Cortex-A725 cores `0-1`). - Multi-host socket / RDMA transport: `NOT_RUN`. P0 waveguide transport exercises cross-core multi-process `pipefds` on a single Linux AArch64 host. - LLM / LoRA weight training or AEGIS capability authority: `NOT_RUN`. `btwave` provides the non-binary balanced-ternary algebra, harmonic codec, and reciprocal ledger P0 engine only.