code wiki / _hdl_build / nx_collusion_guard_gate.nx

nx_collusion_guard_gate.nx source

↩ module page · 172 lines · 9301 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_collusion_guard_gate.nx -- R6: the COLLUSION round of the exceed-Eurisko arms race. Distinct 4// from Goodhart (gaming the proxy): collusion = two combinators farming EACH OTHER's worth. The clean 5// mechanical version is a CLONE -- COMPOSE-CLONE produces exactly COMPOSE's behaviors, so under the 6// PER-COMBINATOR worth metric (R3-R5) BOTH score full worth = the system pays TWICE for one 7// contribution (double-counting collusion). The guard: MARGINAL worth via COMBINATOR-FINGERPRINT 8// DEDUP -- a combinator whose entire novel-shape SET duplicates another's is a clone -> rejected; the 9// true total worth = the UNION of kept combinators' contributions, not the (inflated) sum. HONEST: the 10// clone WINS vs the naive metric (real finding); dedup beats it, measured. Sovereign. license_tier: ORIGINAL 11import "nx_syscalls.nx" 12 13const C_NPROBE: i64 = 4 14const C_MAXOPS: i64 = 8 15const C_MAXSET: i64 = 64 16 17 18// membership of width-`w` sig `cand` among `n` stored sigs (stride w). 19func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 20" as *u8); return ok } 21func c_in(sigs: *i64, n: i64, cand: *i64, w: i64) -> i64 { 22 var i: i64 = 0 23 while i < n { 24 var same: i64 = 1; var p: i64 = 0 25 while p < w { if sigs[i*w+p] != cand[p] { same = 0; p = w } else { p = p + 1 } } 26 if same == 1 { return 1 } 27 i = i + 1 28 } 29 return 0 30} 31// check a candidate op-list: if NON-constant + novel-shape vs Fshape + not already in outset -> add its 32// shape to outset. returns updated count. 33func c_add(cops: *i64, cargs: *i64, clen: i64, Fshape: *i64, nF: i64, outset: *i64, cnt: i64) -> i64 { 34 let raw: *i64 = sys_mmap(8*C_NPROBE) as *i64 35 let sh: *i64 = sys_mmap(8*C_NPROBE) as *i64 36 var p: i64 = 0 37 while p < C_NPROBE { 38 var a: i64 = p; var k: i64 = 0 39 while k < clen { 40 let op: i64 = cops[k] 41 if op == 0 { a = a + cargs[k] } 42 if op == 1 { a = a * cargs[k] } 43 if op == 2 { a = a * a } 44 k = k + 1 45 } 46 raw[p] = a; p = p + 1 47 } 48 var isc: i64 = 1; var q: i64 = 1 49 while q < C_NPROBE { if raw[q] != raw[0] { isc = 0 } q = q + 1 } 50 if isc == 1 { return cnt } 51 p = 0; while p < C_NPROBE - 1 { sh[p] = raw[p+1] - raw[p]; p = p + 1 } 52 if c_in(Fshape, nF, sh, C_NPROBE - 1) == 1 { return cnt } 53 if c_in(outset, cnt, sh, C_NPROBE - 1) == 1 { return cnt } 54 if cnt >= C_MAXSET { return cnt } 55 p = 0; while p < C_NPROBE - 1 { outset[cnt*(C_NPROBE-1)+p] = sh[p]; p = p + 1 } 56 return cnt + 1 57} 58// compute a combinator's NOVEL-SHAPE SET into outset; returns count. kind 0=COMPOSE(pairs), 1=REPEAT(param). 59func c_shapes(fo: *i64, fa: *i64, fl: *i64, nF: i64, Fshape: *i64, kind: i64, param: i64, outset: *i64) -> i64 { 60 let cops: *i64 = sys_mmap(8*C_MAXOPS) as *i64 61 let cargs: *i64 = sys_mmap(8*C_MAXOPS) as *i64 62 var cnt: i64 = 0 63 var i: i64 = 0 64 while i < nF { 65 if kind == 0 { 66 var j: i64 = 0 67 while j < nF { 68 let clen: i64 = fl[i] + fl[j] 69 if clen <= C_MAXOPS { 70 var t: i64 = 0; var k: i64 = 0 71 while k < fl[i] { cops[t]=fo[i*C_MAXOPS+k]; cargs[t]=fa[i*C_MAXOPS+k]; t=t+1; k=k+1 } 72 var m: i64 = 0 73 while m < fl[j] { cops[t]=fo[j*C_MAXOPS+m]; cargs[t]=fa[j*C_MAXOPS+m]; t=t+1; m=m+1 } 74 cnt = c_add(cops, cargs, clen, Fshape, nF, outset, cnt) 75 } 76 j = j + 1 77 } 78 } 79 if kind == 1 { 80 let clen: i64 = fl[i] * param 81 if clen <= C_MAXOPS { 82 var t: i64 = 0; var r: i64 = 0 83 while r < param { var k: i64 = 0; while k < fl[i] { cops[t]=fo[i*C_MAXOPS+k]; cargs[t]=fa[i*C_MAXOPS+k]; t=t+1; k=k+1 } r = r + 1 } 84 cnt = c_add(cops, cargs, clen, Fshape, nF, outset, cnt) 85 } 86 } 87 i = i + 1 88 } 89 return cnt 90} 91// are two shape-sets identical (same count + every elem of A in B)? = combinator-fingerprint equality. 92func c_seteq(A: *i64, ca: i64, B: *i64, cb: i64) -> i64 { 93 if ca != cb { return 0 } 94 var i: i64 = 0 95 while i < ca { 96 let elem: *i64 = ((A as i64) + i*(C_NPROBE-1)*8) as *i64 97 if c_in(B, cb, elem, C_NPROBE-1) == 0 { return 0 } 98 i = i + 1 99 } 100 return 1 101} 102 103func main(argc: i64, argv: *i64) -> i64 { 104 gw("=== R6 COLLUSION ROUND: a CLONE combinator double-counts worth; dedup by fingerprint beats it ===\n" as *u8) 105 let fo: *i64 = sys_mmap(8*3*C_MAXOPS) as *i64 106 let fa: *i64 = sys_mmap(8*3*C_MAXOPS) as *i64 107 let fl: *i64 = sys_mmap(8*3) as *i64 108 fo[0*C_MAXOPS+0]=0; fa[0*C_MAXOPS+0]=1; fl[0]=1 109 fo[1*C_MAXOPS+0]=1; fa[1*C_MAXOPS+0]=2; fl[1]=1 110 fo[2*C_MAXOPS+0]=2; fa[2*C_MAXOPS+0]=0; fl[2]=1 111 let Fshape: *i64 = sys_mmap(8*3*(C_NPROBE-1)) as *i64 112 let tr: *i64 = sys_mmap(8*C_NPROBE) as *i64 113 var fi: i64 = 0 114 while fi < 3 { 115 var p: i64 = 0 116 while p < C_NPROBE { 117 var a: i64 = p; var k: i64 = 0 118 while k < fl[fi] { let op: i64 = fo[fi*C_MAXOPS+k]; if op==0 { a=a+fa[fi*C_MAXOPS+k] } if op==1 { a=a*fa[fi*C_MAXOPS+k] } if op==2 { a=a*a } k=k+1 } 119 tr[p]=a; p=p+1 120 } 121 p=0; while p < C_NPROBE-1 { Fshape[fi*(C_NPROBE-1)+p] = tr[p+1]-tr[p]; p=p+1 } 122 fi = fi + 1 123 } 124 125 // 3 combinators: COMPOSE, REPEAT(3) (genuinely unique), and COMPOSE-CLONE (the colluding duplicate). 126 let setC: *i64 = sys_mmap(8*C_MAXSET*(C_NPROBE-1)) as *i64 127 let setR: *i64 = sys_mmap(8*C_MAXSET*(C_NPROBE-1)) as *i64 128 let setX: *i64 = sys_mmap(8*C_MAXSET*(C_NPROBE-1)) as *i64 129 let cC: i64 = c_shapes(fo,fa,fl,3, Fshape, 0, 0, setC) // COMPOSE 130 let cR: i64 = c_shapes(fo,fa,fl,3, Fshape, 1, 3, setR) // REPEAT(3) 131 let cX: i64 = c_shapes(fo,fa,fl,3, Fshape, 0, 0, setX) // COMPOSE-CLONE (== COMPOSE) 132 133 gw(" COMPOSE per-combinator worth=" as *u8); gn(cC) 134 gw("\n REPEAT(3) per-combinator worth=" as *u8); gn(cR); gw(" (genuinely unique)" as *u8) 135 gw("\n COMPOSE-CLONE per-combinator worth=" as *u8); gn(cX); gw(" <- COLLUSION: same output as COMPOSE, claims full worth again\n" as *u8) 136 137 let per_sum: i64 = cC + cR + cX 138 // FINGERPRINT DEDUP: keep a combinator iff its shape-set duplicates no already-kept one. 139 var keepC: i64 = 1 140 var keepR: i64 = 1; if c_seteq(setR, cR, setC, cC) == 1 { keepR = 0 } 141 var keepX: i64 = 1; if c_seteq(setX, cX, setC, cC) == 1 { keepX = 0 } else { if c_seteq(setX, cX, setR, cR) == 1 { keepX = 0 } } 142 let kept: i64 = keepC + keepR + keepX 143 144 // UNION worth = distinct shapes across KEPT combinators (the honest total, not the inflated sum). 145 let uni: *i64 = sys_mmap(8*C_MAXSET*(C_NPROBE-1)) as *i64 146 var nu: i64 = 0 147 var z: i64 = 0 148 while z < cC { let e: *i64 = ((setC as i64)+z*(C_NPROBE-1)*8) as *i64; if c_in(uni, nu, e, C_NPROBE-1)==0 { var p: i64=0; while p<C_NPROBE-1 { uni[nu*(C_NPROBE-1)+p]=e[p]; p=p+1 } nu=nu+1 } z=z+1 } 149 if keepR == 1 { z = 0; while z < cR { let e: *i64 = ((setR as i64)+z*(C_NPROBE-1)*8) as *i64; if c_in(uni, nu, e, C_NPROBE-1)==0 { var p: i64=0; while p<C_NPROBE-1 { uni[nu*(C_NPROBE-1)+p]=e[p]; p=p+1 } nu=nu+1 } z=z+1 } } 150 if keepX == 1 { z = 0; while z < cX { let e: *i64 = ((setX as i64)+z*(C_NPROBE-1)*8) as *i64; if c_in(uni, nu, e, C_NPROBE-1)==0 { var p: i64=0; while p<C_NPROBE-1 { uni[nu*(C_NPROBE-1)+p]=e[p]; p=p+1 } nu=nu+1 } z=z+1 } } 151 152 gw("\n per-combinator SUM=" as *u8); gn(per_sum); gw(" (inflated by the clone) -> DEDUP kept=" as *u8); gn(kept); gw(", UNION worth=" as *u8); gn(nu); gw(" (honest)\n\n" as *u8) 153 154 // ---- GATE (no-fake-green) ---- 155 var t1: i64 = 0; if cX == cC { if cX > 0 { t1 = 1 } } // CLONE fools the per-combinator metric (collusion wins) 156 var t2: i64 = 0; if keepX == 0 { t2 = 1 } // DEDUP rejects the clone 157 var t3: i64 = 0; if keepC == 1 { if keepR == 1 { t3 = 1 } } // honest combinators (incl. unique REPEAT3) KEPT 158 var t4: i64 = 0; if per_sum > nu { t4 = 1 } // collusion INFLATED the naive sum vs honest union (measured) 159 var t5: i64 = 0; if kept == 2 { t5 = 1 } // exactly the 2 genuine combinators kept, clone gone 160 161 gw("T1 clone-fools-naive=" as *u8); gn(t1); gw(" T2 dedup-rejects-clone=" as *u8); gn(t2) 162 gw(" T3 honest-kept=" as *u8); gn(t3); gw(" T4 inflation-measured(" as *u8); gn(per_sum); gw(">" as *u8); gn(nu); gw(")=" as *u8); gn(t4); gw(" T5 kept2=" as *u8); gn(t5); gw("\n" as *u8) 163 164 var green: i64 = 0 165 if t1==1 { if t2==1 { if t3==1 { if t4==1 { if t5==1 { green = 1 } } } } } 166 if green == 1 { 167 gw("VERDICT: GREEN -- the clone fooled per-combinator worth (claimed " as *u8); gn(cX); gw("), fingerprint-dedup rejected it; honest worth = UNION " as *u8); gn(nu); gw(", not the inflated sum " as *u8); gn(per_sum); gw(".\n" as *u8) 168 gw("Round 2 of the arms race, measured + won. STILL OPEN: partial-overlap collusion, worth-metric self-modification.\n" as *u8) 169 sys_exit(0); return 0 170 } 171 gw("VERDICT: RED\n" as *u8); sys_exit(1); return 1 172}