code wiki / _hdl_build / nx_wat_sov_align_gate.nx
nx_wat_sov_align_gate.nx source
↩ module page · 61 lines · 3632 B
1// nx_wat_sov_align_gate.nx -- ONE-TIME alignment oracle check, then WABT is DROPPED from the video
2// core's wasm lane (operator 2026-07-02: "stop using shell ... use the nishi ecosystem"). Byte-compares
3// the SOVEREIGN nx_wat_compiler output (/tmp/vc_sov.wasm, built from web_assets/nx_video_client.staged.wat)
4// against the WABT-produced web_assets/nx_video_client.staged.wasm. GREEN = byte-identical on the
5// core's REAL 711KB wat -> the pipeline is nxc2 --target wat -> nx_wat_compiler.elf (sovereign),
6// WABT retired to a dropped oracle per nx_wat_compiler's own doctrine. NEG-control: a 1-byte
7// difference must read MISMATCH. Log -> knowledge/status/wat_sov_align.log. expect_exit: 0
8// license_tier: ORIGINAL
9import "nx_syscalls.nx"
10import "nx_gate_verdict.nx"
11
12func aw(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
13func awn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(fd,bb,k); return 0 }
14
15func main() -> i64 {
16 aw(1, "=== nx_wat_sov_align_gate: sovereign wat-compiler vs WABT on the video core ===\n")
17 let ba: *i64 = sys_mmap(16) as *i64
18 let bb2: *i64 = sys_mmap(16) as *i64
19 let a: *u8 = sys_read_file("/tmp/vc_sov.wasm" as *u8, ba)
20 let b: *u8 = sys_read_file("web_assets/nx_video_client.staged.wasm" as *u8, bb2)
21 if (a as i64)==0 { aw(1, "no /tmp/vc_sov.wasm -- run: ./_offc/nx_wat_compiler.elf web_assets/nx_video_client.staged.wat /tmp/vc_sov.wasm\n"); return 1 }
22 if (b as i64)==0 { aw(1, "no staged.wasm oracle\n"); return 1 }
23 aw(1, " sovereign="); awn(1, ba[0]); aw(1, "B oracle="); awn(1, bb2[0]); aw(1, "B\n")
24 var same: i64 = 1
25 var firstdiff: i64 = 0 - 1
26 if ba[0] != bb2[0] { same = 0 }
27 if same == 1 {
28 var i: i64 = 0
29 while i < ba[0] { if a[i] != b[i] { same = 0; firstdiff = i; i = ba[0] } else { i = i + 1 } }
30 }
31 // NEG-control: flip one byte of a copy -> the comparator must catch it
32 var neg: i64 = 0
33 if (a as i64) != 0 {
34 let c: *u8 = sys_mmap(ba[0] + 16)
35 var j: i64 = 0
36 while j < ba[0] { c[j] = a[j]; j = j + 1 }
37 c[ba[0]/2] = ((c[ba[0]/2] as i64) ^ 1) as u8
38 var s2: i64 = 1
39 j = 0
40 while j < ba[0] { if c[j] != a[j] { s2 = 0; j = ba[0] } else { j = j + 1 } }
41 if s2 == 0 { neg = 1 }
42 }
43 aw(1, " byte-identical="); awn(1, same); aw(1, " first_diff="); awn(1, firstdiff); aw(1, " neg-control="); awn(1, neg); aw(1, "\n")
44 var ok: i64 = 0
45 if same == 1 { if neg == 1 { ok = 1 } }
46 let lf: i64 = sys_openat_append("knowledge/status/wat_sov_align.log" as *u8, 420)
47 if lf >= 0 {
48 aw(lf, "WATSOVALIGN bytes="); awn(lf, ba[0]); aw(lf, " identical="); awn(lf, same); aw(lf, " negctl="); awn(lf, neg)
49 if ok==1 { aw(lf, " verdict=GREEN\n") } else { aw(lf, " verdict=RED\n") }
50 sys_close(lf)
51 }
52 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
53 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
54 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
55 let ctr__dry: *i64 = gv_ctr()
56 ctr__dry[0] = ok
57 ctr__dry[1] = 1
58 let rc__dry: i64 = gv_verdict("WAT-SOV-ALIGN-GATE" as *u8, ctr__dry, "WABT retired from this lane; the wasm build is sovereign end-to-end" as *u8)
59 sys_exit(rc__dry)
60 return rc__dry
61}