code wiki / _hdl_build / nx_natstat_redteam_gate.nx

nx_natstat_redteam_gate.nx source

↩ module page · 80 lines · 4400 B

1// nx_natstat_redteam_gate.nx -- STANDING PROOF the photoreal grader is not gameable by noise. Locks in the 2// 2026-07-23 hardening: ns_assess alone rates PURE NOISE ~SEMI-REAL (MSCN maxes on noise); ns_assess2 gates by 3// coherence so noise -> CLAY while a coherent image is UNCHANGED. Self-contained + deterministic (LCG noise, 4// ramp gradient) so it can't rot. MUTATION: remove the coherence gate -> T4 RED; crush coherent too -> T5 RED. 5// license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_natstat.nx" 8const K_65536: i64 = 65536 9 10func rg_hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func rg_pn(v: i64) -> i64 { 12 let b: *u8=sys_mmap(32); var x: i64=v; var ng: i64=0 13 if x<0 { ng=1; x=0-x } 14 var i: i64=31 15 if x==0 { b[i]=48 as u8; i=i-1 } 16 while x>0 { b[i]=(48+x%10) as u8; x=x/10; i=i-1 } 17 if ng==1 { b[i]=45 as u8; i=i-1 } 18 sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 19} 20 21func main() -> i64 { 22 let W: i64 = 256 23 let H: i64 = 256 24 let np: i64 = W*H 25 let noise: *i64 = sys_mmap(np*8) as *i64 26 let grad: *i64 = sys_mmap(np*8) as *i64 27 // deterministic white noise (LCG) 28 var s: i64 = 2463534242 29 var i: i64 = 0 30 while i < np { 31 s = (s*1103515245 + 12345) & 2147483647 32 let r: i64 = (s>>7) & 255 33 s = (s*1103515245 + 12345) & 2147483647 34 let g: i64 = (s>>7) & 255 35 s = (s*1103515245 + 12345) & 2147483647 36 let b: i64 = (s>>7) & 255 37 noise[i] = r + g*256 + b*K_65536 38 i = i + 1 39 } 40 // coherent horizontal ramp (neighbours correlated, low detail) 41 var y: i64 = 0 42 while y < H { 43 var x: i64 = 0 44 while x < W { let v: i64 = x*255/W; grad[y*W+x] = v + v*256 + v*K_65536; x = x+1 } 45 y = y + 1 46 } 47 let sc: i64 = np*8 + 64 48 let b1: *i64 = sys_mmap(sc) as *i64 49 let b2: *i64 = sys_mmap(sc) as *i64 50 let out: *i64 = sys_mmap(64) as *i64 51 52 let coh_noise: i64 = ns_coherence(noise, W, H) 53 let coh_grad: i64 = ns_coherence(grad, W, H) 54 let base_noise: i64 = ns_assess(noise, W, H, b1, b2, out) 55 let hard_noise: i64 = ns_assess2(noise, W, H, b1, b2, out) 56 let base_grad: i64 = ns_assess(grad, W, H, b1, b2, out) 57 let hard_grad: i64 = ns_assess2(grad, W, H, b1, b2, out) 58 59 rg_hw("=== nx_natstat_redteam_gate -- the photoreal grader is not noise-gameable ===\n" as *u8) 60 rg_hw(" coh(noise)=" as *u8); rg_pn(coh_noise); rg_hw(" coh(grad)=" as *u8); rg_pn(coh_grad); rg_hw("\n" as *u8) 61 rg_hw(" noise: old=" as *u8); rg_pn(base_noise); rg_hw(" hardened=" as *u8); rg_pn(hard_noise); rg_hw("\n" as *u8) 62 rg_hw(" grad : old=" as *u8); rg_pn(base_grad); rg_hw(" hardened=" as *u8); rg_pn(hard_grad); rg_hw("\n" as *u8) 63 64 var fails: i64 = 0 65 // T1 noise is incoherent 66 if coh_noise < 300 { rg_hw(" T1 noise incoherent (coh<300): PASS\n" as *u8) } else { rg_hw(" T1: FAIL\n" as *u8); fails=fails+1 } 67 // T2 gradient is coherent 68 if coh_grad > 800 { rg_hw(" T2 gradient coherent (coh>800): PASS\n" as *u8) } else { rg_hw(" T2: FAIL\n" as *u8); fails=fails+1 } 69 // T3 the coherence axis SEPARATES incoherent from coherent by a wide margin (the discriminator works) 70 if coh_grad - coh_noise >= 700 { rg_hw(" T3 coherence separates noise vs coherent (margin>=700): PASS\n" as *u8) } else { rg_hw(" T3: FAIL -- axis does not discriminate\n" as *u8); fails=fails+1 } 71 // T4 THE GATE BITES: hardening REDUCES an incoherent image AND lands it in CLAY (<180) 72 // (real-world exploit magnitude -- JPEG-blocked noise 475 SEMI-REAL -> 0 CLAY -- is proven by the nx_grade battery on real files) 73 if hard_noise < base_noise { if hard_noise < 180 { rg_hw(" T4 hardening bites incoherent -> CLAY: PASS\n" as *u8) } else { rg_hw(" T4: FAIL -- not CLAY\n" as *u8); fails=fails+1 } } else { rg_hw(" T4: FAIL -- hardening did not reduce noise (gate removed?)\n" as *u8); fails=fails+1 } 74 // T5 ANTI-VACUITY: a COHERENT image is UNCHANGED by hardening (gate only bites incoherence) 75 if hard_grad == base_grad { rg_hw(" T5 anti-vacuity: coherent image UNCHANGED: PASS\n" as *u8) } else { rg_hw(" T5: FAIL -- hardening crushes coherent images too\n" as *u8); fails=fails+1 } 76 77 if fails == 0 { rg_hw("VERDICT=GREEN 5/5\n" as *u8); return 0 } 78 rg_hw("VERDICT=RED fails=" as *u8); rg_pn(fails); rg_hw("\n" as *u8) 79 return 1 80}