code wiki / _hdl_build / nx_kanon_gate.nx

nx_kanon_gate.nx source

↩ module page · 75 lines · 3535 B

1// nx_kanon_gate.nx -- GATE (runnable) proving the k-anonymity floor primitive (nx_kanon). The 2// foundation under ADS-018 + W-AN-CHARTER-002 / W-CLI-C6. K is read FROM THE SOVEREIGN STORE 3// (adcfg:kanon_k -- pure Nishi, no conf file). Controls are parametrized by the configured K, and 4// the load-bearing control proves the VIOLATION DETECTOR fires (anti-false-green): 5// 6// release: count==K and count>K and count==0 are releasable; count==K-1 and count==1 suppressed 7// apply : over [K, K-1, 0, K+5] exactly ONE cell (K-1) is suppressed; released set has 0 leaks 8// DETECT : a wrongly-"released" set containing K-1 makes kn_count_below FIRE (==1) -> proves the 9// checker catches a leak; stuck-at-0 would RED-fail this control. 10// 11// Evidence -> knowledge/status/kanon_gate.log (KANON authored=organ cells_below_k=0 ... verdict=GREEN). 12// license_tier: ORIGINAL 13import "nx_ad_store.nx" 14import "nx_kanon.nx" 15import "nx_syscalls.nx" 16import "nx_gate_verdict.nx" 17 18const KG_LOG: *u8 = "knowledge/status/kanon_gate.log" 19 20func kg_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 21func kg_wn(fd: i64, v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(fd, bb, k); return 0 } 22 23func kg_emit(fd: i64, k: i64, sup: i64, below: i64, fired: i64, ok: i64) -> i64 { 24 kg_w(fd, "KANON authored=organ source=store k=" as *u8); kg_wn(fd, k) 25 kg_w(fd, " apply_suppressed=" as *u8); kg_wn(fd, sup) 26 kg_w(fd, " cells_below_k=" as *u8); kg_wn(fd, below) 27 kg_w(fd, " detector_fired=" as *u8); kg_wn(fd, fired) 28 if ok == 1 { kg_w(fd, " verdict=GREEN\n" as *u8) } else { kg_w(fd, " verdict=RED\n" as *u8) } 29 return 0 30} 31 32func main() -> i64 { 33 let k: i64 = ads_kanon_k() 34 35 let r_at: i64 = kn_release(k, k) 36 let r_above: i64 = kn_release(k + 5, k) 37 let r_zero: i64 = kn_release(0, k) 38 let s_below: i64 = kn_release(k - 1, k) 39 let s_one: i64 = kn_release(1, k) 40 41 let raw: *i64 = sys_mmap(64) as *i64 42 let out: *i64 = sys_mmap(64) as *i64 43 raw[0] = k; raw[1] = k - 1; raw[2] = 0; raw[3] = k + 5 44 let sup: i64 = kn_apply(raw, 4, k, out) 45 let below: i64 = kn_count_below(out, 4, k) 46 47 let leak: *i64 = sys_mmap(32) as *i64 48 leak[0] = k + 1; leak[1] = k - 1 49 let fired: i64 = kn_count_below(leak, 2, k) 50 51 var ok: i64 = 1 52 if k < 2 { ok = 0 } 53 if r_at != 1 { ok = 0 } 54 if r_above != 1 { ok = 0 } 55 if r_zero != 1 { ok = 0 } 56 if s_below != 0 { ok = 0 } 57 if s_one != 0 { ok = 0 } 58 if sup != 1 { ok = 0 } 59 if below != 0 { ok = 0 } 60 if fired != 1 { ok = 0 } 61 62 kg_emit(1, k, sup, below, fired, ok) 63 let lf: i64 = sys_openat_append(KG_LOG, 420) 64 if lf >= 0 { kg_emit(lf, k, sup, below, fired, ok); sys_close(lf) } 65 66 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 67 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 68 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 69 let ctr__dry: *i64 = gv_ctr() 70 ctr__dry[0] = ok 71 ctr__dry[1] = 1 72 let rc__dry: i64 = gv_verdict("KANON-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 73 sys_exit(rc__dry) 74 return rc__dry 75}