nx_sha256_wasm.nx -- SHA-256 (FIPS 180-4) self-contained for WAT target.
Per NISHI_ANTI_AUTHORITARIAN_DOCTRINE §6, browser crypto primitives
(crypto.subtle.*) are untrusted -- the substrate must ship its own
SHA-256 that runs in the browser via WASM, not call out to the
browser engine's implementation.
This file deliberately imports NOTHING. The full nx_sha256.nx pulls
in nx_syscalls (for sys_mmap) which transitively drags atomic-op IR
the WAT backend does not yet lower. Here we work in caller-supplied
linear-memory regions and never touch syscalls.
**BLOCKED on nxc2 WAT backend codegen bug (named 2026-05-16):**
The current `wasm.c` only declares `$slot_v<n>` locals for values
produced by OP_ALLOCA (see wasm.c:349-355). Pointer arithmetic via
OP_GEP (every `ctx_ptr[offset]` reads/writes through a GEP-derived
pointer) emits OP_LOAD / OP_STORE addressing through `$slot_v<n>`
without the corresponding declaration. Result: emitted WAT
references undeclared locals; wat2wasm rejects with
"error: undefined local variable $slot_v295".
Fix path (substrate compiler work, queued):
1. WAT backend recognizes the "addr is from non-alloca SSA value"
case and emits real (memory $mem) ops (i64.load/i64.store etc.)
against linear memory, using the GEP-emitted offset directly.
2. Function gets `(memory (export "memory") 16)` declared so the
caller (JS) can access linear memory.
3. Caller passes pointers as i32 offsets into that linear memory;
substrate code does `i32.add` (current emission uses i64).
4. ALTERNATE: have WAT backend pre-scan the function for any
OP_LOAD/STORE addr operand and pre-declare a `$slot_v<n>` for
every such addr value. Cheaper one-line fix but allocates
unnecessary locals for pointer-arithmetic intermediates.
**Until that compiler work lands, the L82 chat-history hash chain
uses crypto.subtle.digest in the browser (sovereignty debt named
in NISHI_ANTI_AUTHORITARIAN_DOCTRINE §6 with this primitive as the
queued replacement).**
dependencies 0 imports · 38 importers
diagram shows first 10 each side; +0 more imports, +28 more importers in the complete lists below.