code wiki / (root) / nx_adversarial_sov_gate.nx

nx_adversarial_sov_gate.nx source

↩ module page · 96 lines · 6284 B

1// nx_adversarial_sov_gate.nx -- proves the ADVERSARIAL-SUITE store flip (nx_adversarial_sov) is byte-exact + 2// has teeth. GREEN (exit 0) only when: migrate seeds knowledge/store/adversarial byte-exact from the .conf 3// (ver==tot, tot>0), the store round-trips (ag_count==tot), the reader reconstructs every gate (ag_read_all 4// yields tot newline rows with the known anchor gate first), AND the neg-controls hold (no phantom row past the 5// end; the byte comparison discriminates right-vs-wrong). Run standalone (CWD=nxc2). license_tier: ORIGINAL 6import "nx_adversarial_sov.nx" 7import "nx_syscalls.nx" 8import "nx_gate_verdict.nx" 9 10func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func gn(v: i64) -> i64 { 12 let t: *u8=sys_mmap(24); var m: i64=v; var k: i64=0 13 if m==0 { t[0]=48 as u8; k=1 } 14 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 15 let o: *u8=sys_mmap(24); var i: i64=0; while i<k { o[i]=t[k-1-i]; i=i+1 } sys_write(1,o,k); return 0 16} 17// gred() REMOVED with the D001 migration: every one of its call sites became a gv_check. Leaving it 18// would be a defined-and-never-called function -- precisely what nx_unwired exists to name -- and worse, 19// a print-and-exit verdict helper sitting in a migrated gate is an invitation to reintroduce the very 20// fail-fast shape the migration removed. 21 22// does the NUL-terminated store gate `a` equal the NUL-terminated expected `b`? 23func gstreq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } 24 25// LOCAL eq, named local on purpose: nx_gate_verdict does not provide one, and a gv_-prefixed helper 26// would tell every future reader it came from the base class when it did not. 27func ag_eq(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 } 28 29// MIGRATED ONTO THE BASE CLASS (D001) BY HAND, 2026-08-15. /api/promote refused this gate for rolling its 30// own verdict, and the record is explicit that the allow_own_verdict escape SHIPS AN UNREADABLE GATE: 31// nx_gate_green cannot judge it and it writes no harness.jrnl frame, so flake and erosion stay invisible. 32// The record is equally explicit that the ASSISTED migration collapses N teeth into ONE boolean 33// (ctr[0]=green; ctr[1]=1) -- the exact defect gv_ctr exists to prevent -- so this is the hand migration. 34// 35// THE REAL GAIN IS NOT THE VERDICT LINE, IT IS THAT THE TEETH STOP HIDING EACH OTHER. Every check used to 36// be gred(), which PRINTS AND EXITS: a T1 failure meant T2, T3 and both neg-controls never ran, and the 37// reader saw one message and no idea whether anything else was broken. gv_check accumulates, so one run 38// now reports the whole vector. A cascade is possible (if nothing migrated, the phantom-row control is 39// asked about row 0) -- that is visible rather than hidden, because each tooth is named and a reader can 40// see T1 failed first and fix that. 41// The two controls keep neg-control- names so the fleet census can SEE them: a control nobody can find 42// is a control nobody maintains. 43func main() -> i64 { 44 let ctr: *i64 = gv_ctr() 45 gv_head("nx_adversarial_sov_gate: prove the adversarial-suite store flip (byte-exact + teeth)" as *u8) 46 47 // T1 -- migrate seeds the store byte-exact from the .conf migrate-source 48 let totp: *i64 = sys_mmap(16) as *i64 49 let verp: *i64 = sys_mmap(16) as *i64 50 ag_migrate(totp, verp) 51 let tot: i64 = totp[0] 52 let ver: i64 = verp[0] 53 gp(" T1 migrate: tot=" as *u8); gn(tot); gp(" verified=" as *u8); gn(ver); gp("\n" as *u8) 54 var t1a: i64 = 0 55 if tot > 0 { t1a = 1 } 56 gv_check("migrate produced rows at all (empty conf or store fails closed)", t1a, ctr) 57 // ANTI-VACUITY, caught by RUNNING the migration rather than reading it. With tot=0 every comparison 58 // below is 0 == 0 and PASSES on the empty set: the first run of this migrated gate reported 59 // byte-verify, round-trip and reader-fidelity all GREEN over a store containing nothing at all. 60 // A TOOTH THAT PASSES ON THE EMPTY SET IS NOT A TOOTH -- the count belongs in the CONDITION, not 61 // merely in the printout beside it. An axis that cannot see must abstain, and a vacuous PASS is not 62 // abstaining, it is acquitting. So the dependent teeth are asserted ONLY when there is something to 63 // assert about, and otherwise register as an unmet precondition. 64 if t1a == 1 { 65 gv_check("every migrated row byte-verifies against its conf source", ag_eq(ver, tot), ctr) 66 } else { 67 gv_need("a non-empty migrate source -- with tot=0 the row-count teeth are 0==0 and would pass over an empty store" as *u8, 0, ctr) 68 } 69 70 // T2 -- the store round-trips: ag_count sees exactly the migrated rows 71 let cnt: i64 = ag_count() 72 gp(" T2 ag_count=" as *u8); gn(cnt); gp("\n" as *u8) 73 if t1a == 1 { gv_check("the store round-trips: ag_count equals the migrated total, no row lost or gained", ag_eq(cnt, tot), ctr) } 74 75 // T3 -- the reader reconstructs every gate: ag_read_all yields tot newline rows, anchor gate first 76 let buf: *u8 = sys_mmap(65536) 77 let rlen: i64 = ag_read_all(buf, 65536) 78 var lines: i64 = 0; var i: i64 = 0 79 while i < rlen { if buf[i]==(10 as u8) { lines=lines+1 } i=i+1 } 80 gp(" T3 ag_read_all bytes=" as *u8); gn(rlen); gp(" lines=" as *u8); gn(lines); gp("\n" as *u8) 81 let g0: *u8 = sys_mmap(256) 82 ag_gate(0, g0, 256) 83 if t1a == 1 { 84 gv_check("the reader reconstructs every gate: one row out per row in", ag_eq(lines, tot), ctr) 85 gv_check("row 0 is still the anchor gate nx_regress_bank (order and content have not drifted)", gstreq(g0, "nx_regress_bank" as *u8), ctr) 86 } 87 88 // T4 -- neg-controls: no phantom row past the end + the byte comparison discriminates (has teeth) 89 let past: *u8 = sys_mmap(256) 90 gv_check("neg-control-no-phantom-row-past-the-end: ag_gate(tot) refuses", ag_eq(ag_gate(tot, past, 256), 0 - 1), ctr) 91 gv_check("neg-control-the-comparison-has-teeth: a wrong gate name does NOT match", ag_eq(gstreq(g0, "nx_NOT_A_REAL_GATE" as *u8), 0), ctr) 92 93 let rc: i64 = gv_verdict("ADVERSARIAL-SOV-GATE" as *u8, ctr, "gates migrated byte-exact to knowledge/store/adversarial; reader and neg-controls hold" as *u8) 94 sys_exit(rc) 95 return rc 96}