code wiki / _hdl_build / nx_video_embed_bundle_gate.nx
nx_video_embed_bundle_gate.nx source
↩ module page · 73 lines · 4078 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"
10
11func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
12" as *u8); return ok }
13func gn(v: i64) -> i64 {
14 let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m}
15 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}
16 var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
17func contains(hay: *u8, n: i64, needle: *u8) -> i64 {
18 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1}
19 var i: i64=0
20 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 }
21 return 0 }
22// find NUL-terminated needle in hay[0..n); returns offset AFTER the needle, or -1
23func find_after(hay: *u8, n: i64, needle: *u8) -> i64 {
24 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1}
25 var i: i64=0
26 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 }
27 return 0 - 1 }
28
29func main() -> i64 {
30 gw("=== nx_video_embed_bundle_gate: sovereign core in nishi-video.js round-trips byte-exact ===\n" as *u8)
31 let jbox: *i64 = sys_mmap(16) as *i64; jbox[0]=0
32 let js: *u8 = sys_read_file("web_assets/nishi-video.js" as *u8, jbox)
33 if (js as i64)==0 { gw("no nishi-video.js (run nx_video_embed_bundle)\n" as *u8); return 1 }
34 let jn: i64 = jbox[0]
35 // extract the base64 between WASM_B64=" and the next "
36 let start: i64 = find_after(js, jn, "WASM_B64=\"" as *u8)
37 if start < 0 { gw("no WASM_B64 in bundle -> RED\n" as *u8); return 1 }
38 var end: i64 = start
39 var goe: i64 = 1
40 while goe==1 { if end<jn { if (js[end] as i64)==34 { goe=0 } else { end=end+1 } } else { goe=0 } }
41 let blen: i64 = end - start
42 gw(" base64 length in bundle = " as *u8); gn(blen); gw("\n" as *u8)
43 // decode
44 let dec: *u8 = sys_mmap(blen + 64)
45 let dn: i64 = b64_decode(((js as i64)+start) as *u8, blen, dec)
46 // read the canonical core
47 let wbox: *i64 = sys_mmap(16) as *i64; wbox[0]=0
48 let wasm: *u8 = sys_read_file("web_assets/nx_video_client.wasm" as *u8, wbox)
49 if (wasm as i64)==0 { gw("no nx_video_client.wasm\n" as *u8); return 1 }
50 let wlen: i64 = wbox[0]
51 gw(" decoded=" as *u8); gn(dn); gw("B canonical core=" as *u8); gn(wlen); gw("B\n" as *u8)
52 var exact: i64 = 0
53 if dn == wlen {
54 exact = 1
55 var i: i64 = 0
56 while i < wlen { if dec[i] != wasm[i] { exact = 0; i = wlen } else { i = i + 1 } }
57 }
58 // component wiring markers
59 let m1: i64 = contains(js, jn, "customElements.define(\"nishi-video\"" as *u8)
60 let m2: i64 = contains(js, jn, "wss://" as *u8)
61 let m3: i64 = contains(js, jn, "vc_fecrx_add" as *u8)
62 let m4: i64 = contains(js, jn, "attachShadow" as *u8)
63 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)
64 var green: i64 = 1
65 if exact != 1 { green = 0 }
66 if m1 != 1 { green = 0 }
67 if m2 != 1 { green = 0 }
68 if m3 != 1 { green = 0 }
69 if m4 != 1 { green = 0 }
70 if green==1 { gw("EMBED-BUNDLE-GATE verdict=GREEN -- the bundle carries the EXACT fuzz-proven core; native Web Component, no iframe\n" as *u8); return 0 }
71 gw("EMBED-BUNDLE-GATE verdict=RED\n" as *u8)
72 return 1
73}