code wiki / _hdl_build / nx_video_embed_bundle_gate.nx

nx_video_embed_bundle_gate.nx source

↩ module page · 80 lines · 4454 B

1import "nx_gate_base.nx" 2// nx_video_embed_bundle_gate.nx -- proves the sovereign wasm core carried INSIDE the embed bundle 3// (nishi-video.js, base64-inline) round-trips BYTE-IDENTICAL to the gated, fuzz-proven core 4// (web_assets/nx_video_client.wasm). If GREEN, the <nishi-video> Web Component runs the EXACT same 5// sovereign core the vm-gate + fuzz-gate proved -- no corruption from the base64 transport. 6// Also asserts the component wiring markers are present (custom element, absolute WSS, FEC rx). 7// expect_exit: 0 license_tier: ORIGINAL 8import "nx_syscalls.nx" 9import "nx_base64.nx" 10import "nx_gate_verdict.nx" 11 12func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 13" as *u8); return ok } 14func gn(v: i64) -> i64 { 15 let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 16 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} 17 var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 18func contains(hay: *u8, n: i64, needle: *u8) -> i64 { 19 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 20 var i: i64=0 21 while i+nl<=n { var j: i64=0; var ok: i64=1; while j<nl { if hay[i+j]!=needle[j]{ok=0;j=nl} else {j=j+1} } if ok==1{return 1} i=i+1 } 22 return 0 } 23// find NUL-terminated needle in hay[0..n); returns offset AFTER the needle, or -1 24func find_after(hay: *u8, n: i64, needle: *u8) -> i64 { 25 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 26 var i: i64=0 27 while i+nl<=n { var j: i64=0; var ok: i64=1; while j<nl { if hay[i+j]!=needle[j]{ok=0;j=nl} else {j=j+1} } if ok==1{return i+nl} i=i+1 } 28 return 0 - 1 } 29 30func main() -> i64 { 31 gw("=== nx_video_embed_bundle_gate: sovereign core in nishi-video.js round-trips byte-exact ===\n" as *u8) 32 let jbox: *i64 = sys_mmap(16) as *i64; jbox[0]=0 33 let js: *u8 = sys_read_file("web_assets/nishi-video.js" as *u8, jbox) 34 if (js as i64)==0 { gw("no nishi-video.js (run nx_video_embed_bundle)\n" as *u8); return 1 } 35 let jn: i64 = jbox[0] 36 // extract the base64 between WASM_B64=" and the next " 37 let start: i64 = find_after(js, jn, "WASM_B64=\"" as *u8) 38 if start < 0 { gw("no WASM_B64 in bundle -> RED\n" as *u8); return 1 } 39 var end: i64 = start 40 var goe: i64 = 1 41 while goe==1 { if end<jn { if (js[end] as i64)==34 { goe=0 } else { end=end+1 } } else { goe=0 } } 42 let blen: i64 = end - start 43 gw(" base64 length in bundle = " as *u8); gn(blen); gw("\n" as *u8) 44 // decode 45 let dec: *u8 = sys_mmap(blen + 64) 46 let dn: i64 = b64_decode(((js as i64)+start) as *u8, blen, dec) 47 // read the canonical core 48 let wbox: *i64 = sys_mmap(16) as *i64; wbox[0]=0 49 let wasm: *u8 = sys_read_file("web_assets/nx_video_client.wasm" as *u8, wbox) 50 if (wasm as i64)==0 { gw("no nx_video_client.wasm\n" as *u8); return 1 } 51 let wlen: i64 = wbox[0] 52 gw(" decoded=" as *u8); gn(dn); gw("B canonical core=" as *u8); gn(wlen); gw("B\n" as *u8) 53 var exact: i64 = 0 54 if dn == wlen { 55 exact = 1 56 var i: i64 = 0 57 while i < wlen { if dec[i] != wasm[i] { exact = 0; i = wlen } else { i = i + 1 } } 58 } 59 // component wiring markers 60 let m1: i64 = contains(js, jn, "customElements.define(\"nishi-video\"" as *u8) 61 let m2: i64 = contains(js, jn, "wss://" as *u8) 62 let m3: i64 = contains(js, jn, "vc_fecrx_add" as *u8) 63 let m4: i64 = contains(js, jn, "attachShadow" as *u8) 64 gw(" wasm-byte-identical=" as *u8); gn(exact); gw(" custom-element=" as *u8); gn(m1); gw(" abs-wss=" as *u8); gn(m2); gw(" fec-rx=" as *u8); gn(m3); gw(" shadow-dom=" as *u8); gn(m4); gw("\n" as *u8) 65 var green: i64 = 1 66 if exact != 1 { green = 0 } 67 if m1 != 1 { green = 0 } 68 if m2 != 1 { green = 0 } 69 if m3 != 1 { green = 0 } 70 if m4 != 1 { green = 0 } 71 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 72 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 73 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 74 let ctr__dry: *i64 = gv_ctr() 75 ctr__dry[0] = green 76 ctr__dry[1] = 1 77 let rc__dry: i64 = gv_verdict("VIDEO-EMBED-BUNDLE-GATE" as *u8, ctr__dry, "the bundle carries the EXACT fuzz-proven core; native Web Component, no iframe" as *u8) 78 sys_exit(rc__dry) 79 return rc__dry 80}