code wiki / _hdl_build / nx_mineworld_wasm_vet.nx

nx_mineworld_wasm_vet.nx source

↩ module page · 284 lines · 16222 B

1// nx_mineworld_wasm_vet.nx -- VET THE SHIPPED WASM BYTES (operator law: evidence before "it works"). Native 2// gates prove the x86 build; the browser runs the WAT-backend build -- a DIFFERENT compiler path. This organ 3// executes web_assets/nx_mineworld.wasm on the SOVEREIGN wasm VM (nx_wasm_vm) and compares, step for step, 4// against the native twin: the whole integer game path (start/tick camera state, terrain_at at negative coords, 5// aim-dig edits, net_push frame bytes). render() is f32 (outside the integer VM's opcode set -- noted, not 6// hidden). A trap or divergence here = the exact thing that ships as a silent light-blue box in the browser. 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_f32_hw.nx" 10import "nx_wasm_mineworld.nx" 11import "nx_wasm_vm.nx" 12const K_MAGIC_9000: i64 = 9000 13const K_MAGIC_999999: i64 = 999999 14const K_MAGIC_895752: i64 = 895752 15const K_MAGIC_891160: i64 = 891160 16const K_MAGIC_891624: i64 = 891624 17const K_MAGIC_547560: i64 = 547560 18const K_MAGIC_786432: i64 = 786432 19const K_MAGIC_787136: i64 = 787136 20const K_MAGIC_393216: i64 = 393216 21const K_MAGIC_1073741824: i64 = 1073741824 22const K_MAGIC_896872: i64 = 896872 23const K_MAGIC_20000: i64 = 20000 24 25func hw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 26func pn(v: i64) -> i64 { 27 let b: *u8 = sys_mmap(32) as *u8 28 var x: i64 = v 29 var neg: i64 = 0 30 if x < 0 { neg = 1; x = 0 - x } 31 var i: i64 = 31 32 if x == 0 { b[i] = 48 as u8; i = i - 1 } 33 while x > 0 { b[i] = (48 + x % 10) as u8; x = x / 10; i = i - 1 } 34 if neg == 1 { b[i] = 45 as u8; i = i - 1 } 35 sys_write(1, (b as i64 + i + 1) as *u8, 31 - i) 36 return 0 37} 38 39func main() -> i64 { 40 var fails: i64 = 0 41 let lenp: *i64 = sys_mmap(16) as *i64 42 let wb: *u8 = sys_read_file("web_assets/nx_mineworld.wasm" as *u8, lenp) 43 if (wb as i64) == 0 { hw("VET RED: cannot read web_assets/nx_mineworld.wasm\n" as *u8); return 1 } 44 let mod: *WasmMod = wm_new(wb, lenp[0]) 45 if wm_parse(mod) != 0 { hw("VET RED: wasm parse failed\n" as *u8); return 1 } 46 hw("V1 parse OK bytes=" as *u8); pn(lenp[0]) 47 48 // exports present? 49 var missing: i64 = 0 50 if wm_find_export(mod, "start" as *u8) < 0 { missing = missing + 1; hw(" MISSING:start" as *u8) } 51 if wm_find_export(mod, "tick" as *u8) < 0 { missing = missing + 1; hw(" MISSING:tick" as *u8) } 52 if wm_find_export(mod, "render_cam" as *u8) < 0 { missing = missing + 1; hw(" MISSING:render_cam" as *u8) } 53 if wm_find_export(mod, "dig" as *u8) < 0 { missing = missing + 1; hw(" MISSING:dig" as *u8) } 54 if wm_find_export(mod, "net_push" as *u8) < 0 { missing = missing + 1; hw(" MISSING:net_push" as *u8) } 55 if missing == 0 { hw(" exports OK\n" as *u8) } else { hw("\nV1 FAIL missing exports\n" as *u8); fails = fails + 1 } 56 57 // native twin 58 let nb: i64 = sys_mmap(mem_bytes()) as i64 59 start_at(nb) 60 // ---- BOTTOM-UP function bisect on the VM (every fn is exported): the last printed PASS localizes a crash ---- 61 hw("B1 mw_h2: " as *u8) 62 let b1v: i64 = wm_run(mod, "mw_h2" as *u8, 5, 7, 999, 0, 0, 3) 63 pn(b1v); hw(" native " as *u8); pn(mw_h2(5, 7, 999)); hw("\n" as *u8) 64 if b1v != mw_h2(5, 7, 999) { hw("B1 DIVERGED\n" as *u8); fails = fails + 1 } 65 hw("B2 mw_sin4096(-9000): " as *u8) 66 let b2v: i64 = wm_run(mod, "mw_sin4096" as *u8, 0 - K_MAGIC_9000, 0, 0, 0, 0, 1) 67 pn(b2v); hw(" native " as *u8); pn(mw_sin4096(0 - K_MAGIC_9000)); hw("\n" as *u8) 68 if b2v != mw_sin4096(0 - K_MAGIC_9000) { hw("B2 DIVERGED\n" as *u8); fails = fails + 1 } 69 hw("B3 terrain_h0(30,30): " as *u8) 70 let b3v: i64 = wm_run(mod, "terrain_h0" as *u8, 30, 30, 0, 0, 0, 2) 71 pn(b3v); hw(" native " as *u8); pn(terrain_h0(30, 30)); hw("\n" as *u8) 72 if b3v != terrain_h0(30, 30) { hw("B3 DIVERGED\n" as *u8); fails = fails + 1 } 73 hw("B4a edit_count (pure load): " as *u8) 74 let b4a: i64 = wm_run(mod, "edit_count" as *u8, 0, 0, 0, 0, 0, 0) 75 pn(b4a); hw("\n" as *u8) 76 hw("B4b peers_clear (simplest loop): " as *u8) 77 let b4b: i64 = wm_run(mod, "peers_clear" as *u8, 0, 0, 0, 0, 0, 0) 78 pn(b4b); hw("\n" as *u8) 79 hw("B4c mw_key(30,5,30): " as *u8) 80 let b4c: i64 = wm_run(mod, "mw_key" as *u8, 30, 5, 30, 0, 0, 3) 81 pn(b4c); hw(" native " as *u8); pn(mw_key(30, 5, 30)); hw("\n" as *u8) 82 if b4c != mw_key(30, 5, 30) { hw("B4c DIVERGED\n" as *u8); fails = fails + 1 } 83 hw("B4d mw_ehash: " as *u8) 84 let b4d: i64 = wm_run(mod, "mw_ehash" as *u8, mw_key(30, 5, 30), 0, 0, 0, 0, 1) 85 pn(b4d); hw(" native " as *u8); pn(mw_ehash(mw_key(30, 5, 30))); hw("\n" as *u8) 86 if b4d != mw_ehash(mw_key(30, 5, 30)) { hw("B4d DIVERGED\n" as *u8); fails = fails + 1 } 87 hw("B4 mw_eget empty: " as *u8) 88 let b4v: i64 = wm_run(mod, "mw_eget" as *u8, 0, 30, 5, 30, 0, 4) 89 pn(b4v); hw("\n" as *u8) 90 hw("B5 cave3(30,3,30): " as *u8) 91 let b5v: i64 = wm_run(mod, "cave3" as *u8, 30, 3, 30, 0, 0, 3) 92 pn(b5v); hw(" native " as *u8); pn(cave3(30, 3, 30)); hw("\n" as *u8) 93 hw("B6 col_pack: " as *u8) 94 let b6v: i64 = wm_run(mod, "col_pack" as *u8, 0, 30, 30, 0, 0, 3) 95 pn(b6v); hw(" native " as *u8); pn(col_pack(nb, 30, 30) - 0); hw(" (vm base=0 vs native base -- packed h/bio/tree must match)\n" as *u8) 96 hw("B7 kind_c(30,3,30): " as *u8) 97 let b7v: i64 = wm_run(mod, "kind_c" as *u8, 0, 30, 3, 30, 0, 4) 98 pn(b7v); hw(" native " as *u8); pn(kind_c(nb, 30, 3, 30)); hw("\n" as *u8) 99 hw("B8 surface_y(30,30): " as *u8) 100 let b8v: i64 = wm_run(mod, "surface_y" as *u8, 0, 30, 30, 0, 0, 3) 101 pn(b8v); hw(" native " as *u8); pn(surface_y(nb, 30, 30)); hw("\n" as *u8) 102 hw("B9 start: " as *u8) 103 let r0: i64 = wm_run(mod, "start" as *u8, 0, 0, 0, 0, 0, 0) 104 if r0 == 0 - K_MAGIC_999999 { hw("MISSING\n" as *u8); fails = fails + 1 } else { pn(r0); hw(" ok\n" as *u8) } 105 106 // identical input script both sides: walk, turn, strafe-jump 107 var i: i64 = 0 108 while i < 10 { tick_at(nb, 1, 0, 0); wm_run(mod, "tick" as *u8, 1, 0, 0, 0, 0, 3); i = i + 1 } 109 tick_at(nb, 0, 245, 0 - 30) 110 wm_run(mod, "tick" as *u8, 0, 245, 0 - 30, 0, 0, 3) 111 i = 0 112 while i < 6 { tick_at(nb, 9 + 16, 2, 1); wm_run(mod, "tick" as *u8, 9 + 16, 2, 1, 0, 0, 3); i = i + 1 } 113 let nc: *i64 = cam_ptr(nb) 114 var camdiff: i64 = 0 115 var k: i64 = 0 116 while k < 9 { 117 let vmv: i64 = wm_ld64(mod.mem, K_MAGIC_895752 + k * 8) 118 if vmv != nc[k] { 119 camdiff = camdiff + 1 120 hw("V2 slot " as *u8); pn(k); hw(": vm=" as *u8); pn(vmv); hw(" native=" as *u8); pn(nc[k]); hw("\n" as *u8) 121 } 122 k = k + 1 123 } 124 if camdiff == 0 { hw("V2 PASS 22-tick input script -> camera state IDENTICAL vm vs native (9/9 slots)\n" as *u8) } 125 else { hw("V2 FAIL camera diverged slots=" as *u8); pn(camdiff); hw("\n" as *u8); fails = fails + 1 } 126 127 // terrain at positive + negative coords 128 let ta1n: i64 = surface_y(nb, 30, 38) 129 let ta1v: i64 = wm_run(mod, "terrain_at" as *u8, 30, 38, 0, 0, 0, 2) 130 let ta2n: i64 = surface_y(nb, 0 - 50, 0 - 77) 131 let ta2v: i64 = wm_run(mod, "terrain_at" as *u8, 0 - 50, 0 - 77, 0, 0, 0, 2) 132 if ta1n == ta1v { if ta2n == ta2v { 133 hw("V3 PASS terrain_at agrees (30,38)=" as *u8); pn(ta1v); hw(" (-50,-77)=" as *u8); pn(ta2v); hw("\n" as *u8) 134 } } 135 if ta1n != ta1v { hw("V3 FAIL terrain_at(30,38) vm=" as *u8); pn(ta1v); hw(" native=" as *u8); pn(ta1n); hw("\n" as *u8); fails = fails + 1 } 136 if ta2n != ta2v { hw("V3 FAIL terrain_at(-50,-77) vm=" as *u8); pn(ta2v); hw(" native=" as *u8); pn(ta2n); hw("\n" as *u8); fails = fails + 1 } 137 138 // aim-ray dig from camera state (POSITIVE mdy = mouse-back = pitch DOWN, standard; same on both sides) 139 tick_at(nb, 0, 0, 600) 140 wm_run(mod, "tick" as *u8, 0, 0, 600, 0, 0, 3) 141 dig_at(nb) 142 wm_run(mod, "dig" as *u8, 0, 0, 0, 0, 0, 0) 143 let ecn: i64 = edit_count_at(nb) 144 let ecv: i64 = wm_ld64(mod.mem, K_MAGIC_891160) 145 if ecn == ecv { if ecn == 1 { hw("V4 PASS aim-dig edits agree (count=1 both)\n" as *u8) } } 146 if ecn != ecv { hw("V4 FAIL edit_count vm=" as *u8); pn(ecv); hw(" native=" as *u8); pn(ecn); hw("\n" as *u8); fails = fails + 1 } 147 if ecn != 1 { if ecn == ecv { hw("V4 FAIL both digs missed (count=" as *u8); pn(ecn); hw(")\n" as *u8); fails = fails + 1 } } 148 149 // net frame bytes (let-bound pointer -- the inline cast-index idiom miscompiles, caught 2026-07-02) 150 let nlen: i64 = net_push_at(nb) 151 let vlen: i64 = wm_run(mod, "net_push" as *u8, 0, 0, 0, 0, 0, 0) 152 let nout: *u8 = (nb + K_MAGIC_891624) as *u8 153 var bdiff: i64 = 0 154 var j: i64 = 0 155 while j < 28 { 156 let nby: i64 = nout[j] as i64 157 let vby: i64 = mod.mem[K_MAGIC_891624 + j] as i64 158 if nby != vby { bdiff = bdiff + 1 } 159 j = j + 1 160 } 161 if nlen == vlen { if bdiff == 0 { hw("V5 PASS net_push frame BYTE-IDENTICAL vm vs native (28B)\n" as *u8) } } 162 if nlen != vlen { hw("V5 FAIL net len vm=" as *u8); pn(vlen); hw(" native=" as *u8); pn(nlen); hw("\n" as *u8); fails = fails + 1 } 163 if bdiff != 0 { 164 hw("V5 FAIL net frame bytes differ=" as *u8); pn(bdiff) 165 hw(" native[0..2]=" as *u8) 166 var q: i64 = 0 167 while q < 3 { pn(nout[q] as i64); hw("," as *u8); q = q + 1 } 168 hw(" vm[0..2]=" as *u8) 169 q = 0 170 while q < 3 { pn(mod.mem[K_MAGIC_547560 + q] as i64); hw("," as *u8); q = q + 1 } 171 hw("\n" as *u8) 172 fails = fails + 1 173 } 174 175 // F-ladder: fast f32 UNIT probes on the shipped bytes (bit-pattern equality; localizes any f32 divergence 176 // in milliseconds before the slow interpreted V6). f32_sub/f32_neg are the EMITTER-COMPOSED paths. 177 var fF: i64 = 0 178 if wm_run(mod, "f32_of" as *u8, 0 - 7, 0, 0, 0, 0, 1) != f32_of(0 - 7) { fF = fF + 1; hw("F1 f32_of(-7) DIVERGED\n" as *u8) } 179 let fa: i64 = f32_of(3) 180 let fb: i64 = f32_of(4) 181 if wm_run(mod, "f32_add" as *u8, fa, fb, 0, 0, 0, 2) != f32_add(fa, fb) { fF = fF + 1; hw("F2 f32_add DIVERGED\n" as *u8) } 182 if wm_run(mod, "f32_mul" as *u8, fa, fb, 0, 0, 0, 2) != f32_mul(fa, fb) { fF = fF + 1; hw("F3 f32_mul DIVERGED\n" as *u8) } 183 if wm_run(mod, "f32_div" as *u8, f32_of(927), f32_of(1000), 0, 0, 0, 2) != f32_div(f32_of(927), f32_of(1000)) { fF = fF + 1; hw("F4 f32_div DIVERGED\n" as *u8) } 184 if wm_run(mod, "f32_int" as *u8, f32_mul(f32_of(300), f32_div(f32_of(1), f32_of(4))), 0, 0, 0, 0, 1) != 75 { fF = fF + 1; hw("F5 f32_int DIVERGED\n" as *u8) } 185 if wm_run(mod, "f32_sub" as *u8, fa, fb, 0, 0, 0, 2) != f32_sub(fa, fb) { fF = fF + 1; hw("F6 f32_sub (composed neg+add) DIVERGED\n" as *u8) } 186 if wm_run(mod, "f32_neg" as *u8, f32_of(5), 0, 0, 0, 0, 1) != f32_neg(f32_of(5)) { fF = fF + 1; hw("F7 f32_neg DIVERGED\n" as *u8) } 187 // F8 build_R at the spawn pose: compare all 16 matrix slots in memory 188 build_R(nb, 1000, 0, 927, 0 - 375) 189 wm_run(mod, "build_R" as *u8, 0, 1000, 0, 927, 0 - 375, 5) 190 let nR: *i64 = (nb + K_MAGIC_786432) as *i64 191 var f8: i64 = 0 192 var mi: i64 = 0 193 while mi < 16 { if wm_ld64(mod.mem, K_MAGIC_786432 + mi * 8) != nR[mi] { f8 = f8 + 1 } mi = mi + 1 } 194 if f8 != 0 { fF = fF + 1; hw("F8 build_R matrix DIVERGED slots=" as *u8); pn(f8); hw("\n" as *u8) } 195 // F9 project one world point (7 args -> direct wm_call): compare the O_PJ result slots 196 let camf: i64 = f32_div(f32_of(30 * 256 + 128), f32_of(256)) 197 let camy9: i64 = f32_div(f32_of((terrain_h0(30, 30) + 8) * 256), f32_of(256)) 198 project(nb, camf, camy9, camf, 30, 5, 38) 199 let a9: *i64 = sys_mmap(8 * 8) as *i64 200 a9[0] = 0; a9[1] = camf; a9[2] = camy9; a9[3] = camf; a9[4] = 30; a9[5] = 5; a9[6] = 38 201 let fidx9: i64 = wm_find_export(mod, "project" as *u8) 202 wm_call(mod, fidx9, a9, 7) 203 let nPJ: *i64 = (nb + K_MAGIC_787136) as *i64 204 var f9: i64 = 0 205 var pi9: i64 = 0 206 while pi9 < 4 { if wm_ld64(mod.mem, K_MAGIC_787136 + pi9 * 8) != nPJ[pi9] { f9 = f9 + 1 } pi9 = pi9 + 1 } 207 if f9 != 0 { fF = fF + 1; hw("F9 project DIVERGED slots=" as *u8); pn(f9); hw("\n" as *u8) } 208 if fF == 0 { hw("F1-F9 PASS f32 unit ladder BIT-IDENTICAL (of/add/mul/div/int/sub/neg/build_R/project)\n" as *u8) } 209 else { fails = fails + fF } 210 211 // F10 -- the 16-PARAMETER boundary call (fill_zt, uv-packed): the WAT emitter DROPS args beyond 16 212 // (found 2026-07-02: 19-param fill_zt got 16 operands at its call site -> VM stack underflow, and the 213 // browser REJECTS the module at validation = the /mineworld light-blue box). fill_zt now packs uv pairs 214 // to sit at EXACTLY 16 params -- this probe proves the boundary works on the shipped bytes. 215 // fill_zt(base, x0,y0,d0,uv0, x1,y1,d1,uv1, x2,y2,d2,uv2, kind, fk, bright) 216 // init the z-buffer to ZFAR in the probe region on BOTH sides (fresh zb=0 rejects every pixel -> a 217 // vacuous "identical nothing"; positive evidence needs the depth test to accept) 218 let nzb: *i64 = (nb + K_MAGIC_393216) as *i64 219 var zi10: i64 = 0 220 while zi10 < 14 * ww() { 221 nzb[zi10] = K_MAGIC_1073741824 222 wm_st64(mod.mem, K_MAGIC_393216 + zi10 * 8, K_MAGIC_1073741824) 223 zi10 = zi10 + 1 224 } 225 fill_zt(nb, 5, 5, 100, 0, 12, 5, 100, 255 * 256, 5, 12, 100, 255, 3, 0, 255) 226 let a10: *i64 = sys_mmap(32 * 8) as *i64 227 a10[0] = 0 228 a10[1] = 5; a10[2] = 5; a10[3] = 100; a10[4] = 0 229 a10[5] = 12; a10[6] = 5; a10[7] = 100; a10[8] = 255 * 256 230 a10[9] = 5; a10[10] = 12; a10[11] = 100; a10[12] = 255 231 a10[13] = 3; a10[14] = 0; a10[15] = 255 232 let fidx10: i64 = wm_find_export(mod, "fill_zt" as *u8) 233 if fidx10 < 0 { hw("F10 SKIP fill_zt not exported\n" as *u8) } 234 else { 235 wm_call(mod, fidx10, a10, 16) 236 let nfb10: *i64 = (nb + fb_off()) as *i64 237 var f10: i64 = 0 238 var painted: i64 = 0 239 var py10: i64 = 4 240 while py10 <= 13 { 241 var px10: i64 = 4 242 while px10 <= 13 { 243 let ii: i64 = py10 * ww() + px10 244 let nv: i64 = nfb10[ii] 245 if wm_ld64(mod.mem, fb_off() + ii * 8) != nv { f10 = f10 + 1 } 246 if nv != 0 { painted = painted + 1 } 247 px10 = px10 + 1 248 } 249 py10 = py10 + 1 250 } 251 if f10 == 0 { if painted > 5 { 252 hw("F10 PASS 18-param fill_zt: triangle pixels IDENTICAL (painted=" as *u8); pn(painted); hw(")\n" as *u8) 253 } } 254 if f10 != 0 { hw("F10 FAIL 18-param fill_zt diverged px=" as *u8); pn(f10); hw("\n" as *u8); fails = fails + 1 } 255 if painted <= 5 { hw("F10 WEAK painted=" as *u8); pn(painted); hw(" (native didn't paint? check)\n" as *u8) } 256 } 257 258 // V6 -- THE FULL RENDER: same camera state both sides, the shipped wasm's frame vs the native frame, 259 // every pixel (the VM gained the 7 f32 opcodes 2026-07-02; this closes the last unexecuted layer). 260 hw("V6 rendering (interpreted -- slow)...\n" as *u8) 261 render_cam_at(nb) 262 wm_run(mod, "render_cam" as *u8, 0, 0, 0, 0, 0, 0) 263 let nfb: *i64 = (nb + fb_off()) as *i64 264 var fdiff: i64 = 0 265 var pi: i64 = 0 266 while pi < ww() * hh() { 267 let vpx: i64 = wm_ld64(mod.mem, fb_off() + pi * 8) 268 if vpx != nfb[pi] { fdiff = fdiff + 1 } 269 pi = pi + 1 270 } 271 // terrain presence = the renderer's own drawn-pixel counters (sky is a gradient; const-compare is dead) 272 let ndp: i64 = drawn_px_at(nb) 273 let vdp: i64 = wm_ld64(mod.mem, K_MAGIC_896872) 274 if fdiff == 0 { if ndp == vdp { if ndp > K_MAGIC_20000 { 275 hw("V6 PASS render_cam: SHIPPED-WASM frame BYTE-IDENTICAL to native (" as *u8); pn(ww() * hh()) 276 hw(" px), drawn-px agree=" as *u8); pn(vdp); hw("\n" as *u8) 277 } } } 278 if fdiff != 0 { hw("V6 FAIL frames differ px=" as *u8); pn(fdiff); hw("\n" as *u8); fails = fails + 1 } 279 if ndp != vdp { hw("V6 FAIL drawn-px diverge vm=" as *u8); pn(vdp); hw(" native=" as *u8); pn(ndp); hw("\n" as *u8); fails = fails + 1 } 280 if ndp <= K_MAGIC_20000 { if ndp == vdp { hw("V6 FAIL mostly sky drawn-px=" as *u8); pn(ndp); hw("\n" as *u8); fails = fails + 1 } } 281 if fails == 0 { hw("VET GREEN: the SHIPPED wasm -- integer path AND the f32 RENDER -- executes IDENTICALLY to native\n" as *u8) } 282 else { hw("VET RED fails=" as *u8); pn(fails); hw("\n" as *u8) } 283 return fails 284}