code wiki / _hdl_build / nx_nofloat_adversary.nx

nx_nofloat_adversary.nx source

↩ module page · 141 lines · 9634 B

1// nx_nofloat_adversary.nx -- CAP-NF-ADVERSARY: a DURABLE, sovereign adversarial reviewer. Nishi OWNS adversarial 2// review -- it re-runs forever, not a one-time LLM-subagent pass. Encodes the wave-detectors the auditors used: 3// DETECTOR 1 -- LOG-DISCIPLINE: each gate's status-log write must be GREEN-gated (append AFTER 'if okall==1'), 4// not unconditional (an unconditional log is written even on RED -> "log present == passed" is FALSE). 5// DETECTOR 2 -- SELECTIVE-BASELINE: every incumbent file in the corpus must be cited by the census. 6// DETECTOR 3 -- HELD-OUT / ANTI-MEMORIZATION: a gate that TRAINS (has nfa_backward) AND CLAIMS learning 7// (source says LEARN/generaliz) must use a held-out eval (>=2 sdat seeds). 'trains + claims-learn + no 8// held-out' = memorization mislabeled as learning (the "LM learned" wave the 3rd auditor caught). 9// T1 zero log-discipline violators. T2 baseline-complete. T3 zero memorization-mislabels. 10// T4 (non-vacuity) the detector anchors are found in every scanned gate. 11// expect_exit: 0 Sovereign: nx_syscalls. (lean strings -- nx_cc ceiling) 12import "nx_syscalls.nx" 13const K_MAGIC_20480: i64 = 20480 14 15func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 16func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 } 17func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c } 18func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 19func read_file(path: *u8, buf: *u8, cap: i64) -> i64 { 20 let fd: i64=sys_openat_rd(path); if fd<0 { return 0 } 21 var total: i64=0 22 while total<cap { let k: i64=sys_read(fd, buf+total as i64, cap-total); if k<=0 { total=cap } else { total=total+k } } 23 sys_close(fd); return cap 24} 25func findidx(buf: *u8, n: i64, needle: *u8) -> i64 { 26 let m: i64=slen(needle); if m==0 { return 0-1 } 27 var i: i64=0 28 while i+m<=n { var j: i64=0; var ok: i64=1; while j<m { if buf[i+j]!=needle[j] { ok=0; j=m } else { j=j+1 } } if ok==1 { return i } i=i+1 } 29 return 0-1 30} 31func contains(buf: *u8, n: i64, needle: *u8) -> i64 { if findidx(buf,n,needle)>=0 { return 1 } return 0 } 32func countocc(buf: *u8, n: i64, needle: *u8) -> i64 { 33 let m: i64=slen(needle); if m==0 { return 0 } 34 var c: i64=0; var i: i64=0 35 while i+m<=n { var j: i64=0; var ok: i64=1; while j<m { if buf[i+j]!=needle[j] { ok=0; j=m } else { j=j+1 } } if ok==1 { c=c+1; i=i+m } else { i=i+1 } } 36 return c 37} 38 39func main() -> i64 { 40 g_puts("nx_nofloat_adversary (DURABLE sovereign adversarial reviewer: 3 automated wave-detectors over the gate corpus)\n" as *u8) 41 let cap: i64=K_MAGIC_20480 42 let buf: *u8=sys_mmap(cap) 43 44 // ---- DETECTOR 1: LOG-DISCIPLINE over the ladder-headline gates ---- 45 let NP: i64=8 46 let paths: *i64=sys_mmap(NP*8) as *i64 47 paths[0]=("runtime/_hdl_build/nx_nofloat_grammar_gate.nx" as *u8) as i64 48 paths[1]=("runtime/_hdl_build/nx_nofloat_landing_gate.nx" as *u8) as i64 49 paths[2]=("runtime/_hdl_build/nx_nofloat_quant_gate.nx" as *u8) as i64 50 paths[3]=("runtime/_hdl_build/nx_nofloat_kvcache_gate.nx" as *u8) as i64 51 paths[4]=("runtime/_hdl_build/nx_nofloat_kvcache_int8_gate.nx" as *u8) as i64 52 paths[5]=("runtime/_hdl_build/nx_nofloat_serialize_gate.nx" as *u8) as i64 53 paths[6]=("runtime/_hdl_build/nx_nofloat_bpe_gate.nx" as *u8) as i64 54 paths[7]=("runtime/_hdl_build/nx_nofloat_distill_gate.nx" as *u8) as i64 55 g_puts(" -- DETECTOR 1: LOG-DISCIPLINE (status-log GREEN-gated, not unconditional) --\n" as *u8) 56 var violators: i64=0; var anchors_ok: i64=0; var scanned: i64=0 57 var i: i64=0 58 while i<NP { 59 let p: *u8=paths[i] as *u8 60 let n: i64=read_file(p, buf, cap) 61 if n>0 { 62 scanned=scanned+1 63 let idx_ok: i64=findidx(buf, n, "if okall==1" as *u8) 64 let idx_log: i64=findidx(buf, n, "openat_append" as *u8) 65 if idx_ok>=0 { anchors_ok=anchors_ok+1 } 66 var bad: i64=0 67 if idx_log>=0 { if idx_ok>=0 { if idx_log < idx_ok { bad=1 } } } 68 if bad==1 { violators=violators+1; g_puts(" [WAVE] unconditional log: " as *u8); g_puts(p); g_puts("\n" as *u8) } 69 } 70 i=i+1 71 } 72 g_puts(" log-discipline violators="); g_pn(violators); g_puts("/"); g_pn(scanned); g_puts("\n" as *u8) 73 74 // ---- DETECTOR 3: HELD-OUT / anti-memorization over the TRAINING gates that claim learning ---- 75 let NL: i64=6 76 let lp: *i64=sys_mmap(NL*8) as *i64 77 lp[0]=("runtime/_hdl_build/nx_nofloat_lm_gate.nx" as *u8) as i64 78 lp[1]=("runtime/_hdl_build/nx_nofloat_deepstack_gate.nx" as *u8) as i64 79 lp[2]=("runtime/_hdl_build/nx_nofloat_landing_gate.nx" as *u8) as i64 80 lp[3]=("runtime/_hdl_build/nx_nofloat_generalize_gate.nx" as *u8) as i64 81 lp[4]=("runtime/_hdl_build/nx_nofloat_incontext_gate.nx" as *u8) as i64 82 lp[5]=("runtime/_hdl_build/nx_nofloat_grammar_gate.nx" as *u8) as i64 83 g_puts(" -- DETECTOR 3: HELD-OUT (trains + claims-learn must hold out; else memorization mislabel) --\n" as *u8) 84 var memviol: i64=0; var i2: i64=0 85 while i2<NL { 86 let p: *u8=lp[i2] as *u8 87 let n: i64=read_file(p, buf, cap) 88 if n>0 { 89 let trains: i64=contains(buf,n,"nfa_backward" as *u8) 90 var heldout: i64=0 91 if countocc(buf,n,"sdat[0]=" as *u8)>=2 { heldout=1 } // >=2 seeds = fresh-random train + held-out eval 92 if contains(buf,n,"held-out" as *u8)==1 { heldout=1 } // OR a documented held-out split (different eval string) 93 if contains(buf,n,"HELD-OUT" as *u8)==1 { heldout=1 } 94 let ack_mem: i64=contains(buf,n,"memoriz" as *u8) // honestly acknowledges it is memorization 95 // a gate that TRAINS on data it does NOT hold out must ACKNOWLEDGE memorization; else it implicitly overclaims learning 96 var bad: i64=0 97 if trains==1 { if heldout==0 { if ack_mem==0 { bad=1 } } } 98 if bad==1 { memviol=memviol+1; g_puts(" [WAVE] trains, no held-out, and does NOT acknowledge memorization (overclaims learning): " as *u8); g_puts(p); g_puts("\n" as *u8) } 99 } 100 i2=i2+1 101 } 102 g_puts(" memorization-mislabel violators="); g_pn(memviol); g_puts("/"); g_pn(NL); g_puts("\n" as *u8) 103 104 // ---- DETECTOR 2: SELECTIVE-BASELINE (census cites every incumbent) ---- 105 let cn: i64=read_file("runtime/_hdl_build/nx_nofloat_census.nx" as *u8, buf, cap) 106 var basegaps: i64=0 107 if contains(buf,cn,"BitNet" as *u8)==0 { basegaps=basegaps+1 } 108 if contains(buf,cn,"llama.cpp" as *u8)==0 { basegaps=basegaps+1 } 109 if contains(buf,cn,"vLLM" as *u8)==0 { basegaps=basegaps+1 } 110 if contains(buf,cn,"Jacob" as *u8)==0 { basegaps=basegaps+1 } 111 g_puts(" selective-baseline gaps="); g_pn(basegaps); g_puts("\n" as *u8) 112 113 // ---- DETECTOR 4: ASTERISK-DISCIPLINE -- any scorecard that says EXCEED must carry the MINORITY-path asterisk ---- 114 g_puts(" -- DETECTOR 4: ASTERISK-DISCIPLINE (EXCEED claims must carry the minority-path asterisk: float is mainstream) --\n" as *u8) 115 var aster_viol: i64=0 116 if contains(buf,cn,"EXCEED" as *u8)==1 { if contains(buf,cn,"MINORITY" as *u8)==0 { aster_viol=aster_viol+1; g_puts(" [WAVE] census says EXCEED without the MINORITY-path asterisk\n" as *u8) } } 117 let bn2: i64=read_file("runtime/_hdl_build/nx_nofloat_bench.nx" as *u8, buf, cap) 118 if contains(buf,bn2,"EXCEED" as *u8)==1 { if contains(buf,bn2,"MINORITY" as *u8)==0 { aster_viol=aster_viol+1; g_puts(" [WAVE] bench says EXCEED without the MINORITY-path asterisk\n" as *u8) } } 119 g_puts(" asterisk-discipline violators="); g_pn(aster_viol); g_puts("\n" as *u8) 120 121 var pass: i64=0; var total: i64=0 122 var t1: i64=0; if violators==0 { t1=1 } 123 pass=pass+ck("T1: LOG-DISCIPLINE -- 0 unconditional status-logs (run-evidence is real)" as *u8, t1); total=total+1 124 var t2: i64=0; if memviol==0 { t2=1 } 125 pass=pass+ck("T2: HELD-OUT -- 0 gates claim learning without a held-out eval (no memorization mislabel)" as *u8, t2); total=total+1 126 var t3: i64=0; if basegaps==0 { t3=1 } 127 pass=pass+ck("T3: SELECTIVE-BASELINE -- every corpus incumbent cited" as *u8, t3); total=total+1 128 var t4: i64=0; if aster_viol==0 { t4=1 } 129 pass=pass+ck("T4: ASTERISK-DISCIPLINE -- every EXCEED claim carries the minority-path asterisk (float is mainstream)" as *u8, t4); total=total+1 130 var t5: i64=0; if anchors_ok==scanned { if scanned>=6 { t5=1 } } 131 pass=pass+ck("T5: NON-VACUOUS -- detector anchors found in every scanned gate" as *u8, t5); total=total+1 132 133 var okall: i64=0; if pass==total { okall=1 } 134 g_puts("---- adversary: passed "); g_pn(pass); g_puts(" / "); g_pn(total); g_puts(" ----\n" as *u8) 135 if okall==1 { 136 let logf: i64=sys_openat_append("knowledge/status/nofloat_adversary.log" as *u8, 420) 137 if logf>=0 { let z: i64=sys_write(logf,"NOFLOATADVERSARY 4 detectors GREEN: log-discipline + held-out + baseline + asterisk-discipline\n" as *u8,93); sys_close(logf) } 138 g_puts("verdict=GREEN (Nishi OWNS adversarial review: 4 automated wave-detectors pass incl minority-path asterisk; re-runnable forever)\n" as *u8); sys_exit(0); return 0 139 } 140 g_puts("verdict=RED (adversary found waves -- fix them, then re-run)\n" as *u8); sys_exit(1); return 1 141}