code wiki / _hdl_build / nx_vcodec_drift_gate.nx

nx_vcodec_drift_gate.nx source

↩ module page · 61 lines · 4024 B

1import "nx_gate_base.nx" 2// nx_vcodec_drift_gate.nx -- proves the SOVEREIGN drift matcher (vc_drift_* in nx_video_codec_wasm.nx), 3// the four-pillar SPOT verdict moved out of app.v2.js. Announce -> verify by CONTENT KEY, with a 4// 2-consecutive-miss confirmation. This is the brain a browser tab AND a native NishiOS video app share. 5// license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_video_codec_wasm.nx" 8 9func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 10" as *u8); return ok } 11func gn(v: i64) -> i64 { 12 let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 13 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} 14 var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 15 16func main() -> i64 { 17 gw("=== nx_vcodec_drift_gate: sovereign SPOT drift verdict (content-key match + 2-miss confirm) ===\n" as *u8) 18 let st: *i64 = sys_mmap(8 * 128) as *i64 19 let pass: *i64 = sys_mmap(16) as *i64 20 let tot: *i64 = sys_mmap(16) as *i64 21 vc_drift_reset(st) 22 23 // T1: announce H for (n=200,qp=28,fl=0,w=320,h=256); a receiver that reproduces H exactly -> match (0), no drift. 24 vc_drift_push(st, 123456, 200, 28, 0, 320, 256) 25 let r1: i64 = vc_drift_verify(st, 123456, 200, 28, 0, 320, 256) 26 gw(" T1 exact-match verdict=" as *u8); gn(r1); gw(" drift=" as *u8); gn(vc_drift_count(st)); gw("\n" as *u8) 27 tot[0]=tot[0]+1; if r1==0 { if vc_drift_count(st)==0 { pass[0]=pass[0]+1 } } 28 29 // T2: a WRONG-key announcement must NOT be consumed by a different frame -> verify with no pending key = 0. 30 vc_drift_push(st, 999, 111, 10, 8, 128, 96) 31 let r2: i64 = vc_drift_verify(st, 555, 200, 28, 0, 320, 256) // no (n=200...) pending now (consumed in T1) 32 gw(" T2 no-pending-key verdict=" as *u8); gn(r2); gw("\n" as *u8) 33 tot[0]=tot[0]+1; if r2==0 { pass[0]=pass[0]+1 } 34 35 // T3: two CONSECUTIVE mismatches on matching keys -> 1 then 2 (CONFIRMED), drift count increments once. 36 let d0: i64 = vc_drift_count(st) 37 vc_drift_push(st, 111111, 300, 24, 8, 256, 192) 38 let a: i64 = vc_drift_verify(st, 222222, 300, 24, 8, 256, 192) // mismatch #1 -> 1 39 vc_drift_push(st, 333333, 300, 24, 8, 256, 192) 40 let b: i64 = vc_drift_verify(st, 444444, 300, 24, 8, 256, 192) // mismatch #2 -> 2 CONFIRMED 41 gw(" T3 miss1=" as *u8); gn(a); gw(" miss2=" as *u8); gn(b); gw(" drift+=" as *u8); gn(vc_drift_count(st)-d0); gw("\n" as *u8) 42 tot[0]=tot[0]+1; if a==1 { if b==2 { if vc_drift_count(st)-d0==1 { pass[0]=pass[0]+1 } } } 43 44 // T4: a MATCH in the middle RESETS the miss run so a later single mismatch is only unconfirmed (1), not 2. 45 vc_drift_reset(st) 46 vc_drift_push(st, 7, 50, 12, 0, 160, 128); vc_drift_verify(st, 8, 50, 12, 0, 160, 128) // miss -> run=1 47 vc_drift_push(st, 9, 50, 12, 0, 160, 128); let m: i64 = vc_drift_verify(st, 9, 50, 12, 0, 160, 128) // MATCH -> run reset 48 vc_drift_push(st, 10, 50, 12, 0, 160, 128); let s: i64 = vc_drift_verify(st, 11, 50, 12, 0, 160, 128) // miss -> run=1 (not 2) 49 gw(" T4 match=" as *u8); gn(m); gw(" post-reset-miss=" as *u8); gn(s); gw(" drift=" as *u8); gn(vc_drift_count(st)); gw("\n" as *u8) 50 tot[0]=tot[0]+1; if m==0 { if s==1 { if vc_drift_count(st)==0 { pass[0]=pass[0]+1 } } } 51 52 // T5: content-key DISCRIMINATION -- an announcement for a DIFFERENT qp must not match this frame. 53 vc_drift_reset(st) 54 vc_drift_push(st, 42, 77, 20, 0, 320, 256) 55 let r5: i64 = vc_drift_verify(st, 99, 77, 33, 0, 320, 256) // same n,w,h but qp 33 != 20 -> no match -> 0 56 gw(" T5 wrong-qp-no-match verdict=" as *u8); gn(r5); gw("\n" as *u8) 57 tot[0]=tot[0]+1; if r5==0 { pass[0]=pass[0]+1 } 58 59 gw("DRIFT: " as *u8); gn(pass[0]); gw("/" as *u8); gn(tot[0]) 60 if pass[0]==tot[0] { gw(" GREEN -- sovereign SPOT verdict matches the JS matcher it replaces\n" as *u8); return 0 } 61 gw(" RED\n" as *u8); return 1 }