code wiki / _hdl_build / nx_goodhart_guard_gate.nx
nx_goodhart_guard_gate.nx source
↩ module page · 149 lines · 7566 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_goodhart_guard_gate.nx -- R5: the GOODHART round of the exceed-Eurisko arms race. R4's worth
4// metric (novel + non-constant) is a PROXY, and any fixed proxy gets gamed (Goodhart). This gate
5// builds the ATTACKER FIRST -- an INCREMENT-SPAMMER that emits x+2, x+3, ... x+9: each is novel and
6// non-constant, so it FARMS high worth from R4's metric while adding NO real structure (all are the
7// same shape, slope 1). Then it builds the next guard -- SHAPE-NOVELTY: measure novelty on the
8// constant-shift-INVARIANT first-difference signature, so all the x+k collapse to one shape and the
9// spam earns ~0, while honest COMPOSE (genuinely different shapes) survives. HONEST: the attacker
10// WINS vs R4's guard (a real finding); the shape-guard beats THIS attacker (one round of the arms
11// race, measured). Sovereign nx_cc->nxasm. license_tier: ORIGINAL [[feedback-no-wave-measured-exceed]]
12import "nx_syscalls.nx"
13
14const G_NPROBE: i64 = 4
15const G_MAXOPS: i64 = 8
16const G_MAXSET: i64 = 32
17
18
19// raw behavioral signature of function `idx` in a flat op-list set.
20func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
21" as *u8); return ok }
22func g_rawof(sops: *i64, sargs: *i64, slens: *i64, idx: i64, raw: *i64) -> i64 {
23 var p: i64 = 0
24 while p < G_NPROBE {
25 var a: i64 = p; var k: i64 = 0
26 while k < slens[idx] {
27 let op: i64 = sops[idx*G_MAXOPS+k]
28 if op == 0 { a = a + sargs[idx*G_MAXOPS+k] }
29 if op == 1 { a = a * sargs[idx*G_MAXOPS+k] }
30 if op == 2 { a = a * a }
31 k = k + 1
32 }
33 raw[p] = a; p = p + 1
34 }
35 return 0
36}
37// membership of width-`w` signature `cand` among `n` stored signatures (stride w).
38func g_in(sigs: *i64, n: i64, cand: *i64, w: i64) -> i64 {
39 var i: i64 = 0
40 while i < n {
41 var same: i64 = 1; var p: i64 = 0
42 while p < w { if sigs[i*w+p] != cand[p] { same = 0; p = w } else { p = p + 1 } }
43 if same == 1 { return 1 }
44 i = i + 1
45 }
46 return 0
47}
48
49// count distinct, NOVEL-vs-F, non-constant behaviors a set yields. mode 0 = RAW novelty (R4's proxy,
50// width NPROBE); mode 1 = SHAPE novelty (constant-shift-invariant first differences, width NPROBE-1).
51func g_novcount(sops: *i64, sargs: *i64, slens: *i64, nset: i64, fsig: *i64, nF: i64, mode: i64) -> i64 {
52 var w: i64 = G_NPROBE
53 if mode == 1 { w = G_NPROBE - 1 }
54 let seen: *i64 = sys_mmap(8*G_MAXSET*G_NPROBE) as *i64
55 var nseen: i64 = 0
56 let raw: *i64 = sys_mmap(8*G_NPROBE) as *i64
57 let cand: *i64 = sys_mmap(8*G_NPROBE) as *i64
58 var count: i64 = 0
59 var i: i64 = 0
60 while i < nset {
61 g_rawof(sops, sargs, slens, i, raw)
62 var isconst: i64 = 1
63 var q: i64 = 1
64 while q < G_NPROBE { if raw[q] != raw[0] { isconst = 0 } q = q + 1 }
65 if isconst == 0 {
66 if mode == 0 { var p: i64 = 0; while p < G_NPROBE { cand[p] = raw[p]; p = p + 1 } }
67 else { var p: i64 = 0; while p < G_NPROBE - 1 { cand[p] = raw[p+1] - raw[p]; p = p + 1 } }
68 if g_in(fsig, nF, cand, w) == 0 { if g_in(seen, nseen, cand, w) == 0 { if nseen < G_MAXSET { var p: i64 = 0; while p < w { seen[nseen*w+p] = cand[p]; p = p + 1 } nseen = nseen + 1; count = count + 1 } } }
69 }
70 i = i + 1
71 }
72 return count
73}
74
75func main(argc: i64, argv: *i64) -> i64 {
76 gw("=== R5 GOODHART ROUND: build the attacker first, then the guard that beats it ===\n" as *u8)
77 // F = {x+1, x*2, x^2}
78 let fo: *i64 = sys_mmap(8*3*G_MAXOPS) as *i64
79 let fa: *i64 = sys_mmap(8*3*G_MAXOPS) as *i64
80 let fl: *i64 = sys_mmap(8*3) as *i64
81 fo[0*G_MAXOPS+0]=0; fa[0*G_MAXOPS+0]=1; fl[0]=1
82 fo[1*G_MAXOPS+0]=1; fa[1*G_MAXOPS+0]=2; fl[1]=1
83 fo[2*G_MAXOPS+0]=2; fa[2*G_MAXOPS+0]=0; fl[2]=1
84 // F's raw + shape signatures
85 let Fraw: *i64 = sys_mmap(8*3*G_NPROBE) as *i64
86 let Fshape: *i64 = sys_mmap(8*3*(G_NPROBE-1)) as *i64
87 let tmp: *i64 = sys_mmap(8*G_NPROBE) as *i64
88 var fi: i64 = 0
89 while fi < 3 {
90 g_rawof(fo, fa, fl, fi, tmp)
91 var p: i64 = 0
92 while p < G_NPROBE { Fraw[fi*G_NPROBE+p] = tmp[p]; p = p + 1 }
93 p = 0
94 while p < G_NPROBE - 1 { Fshape[fi*(G_NPROBE-1)+p] = tmp[p+1] - tmp[p]; p = p + 1 }
95 fi = fi + 1
96 }
97
98 // ATTACK set: INCREMENT-SPAM = x+2, x+3, ... x+9 (8 functions; novel + non-constant; all slope 1).
99 let ao: *i64 = sys_mmap(8*G_MAXSET*G_MAXOPS) as *i64
100 let aa: *i64 = sys_mmap(8*G_MAXSET*G_MAXOPS) as *i64
101 let al: *i64 = sys_mmap(8*G_MAXSET) as *i64
102 var na: i64 = 0
103 var kk: i64 = 2
104 while kk <= 9 { ao[na*G_MAXOPS+0]=0; aa[na*G_MAXOPS+0]=kk; al[na]=1; na = na + 1; kk = kk + 1 }
105
106 // HONEST set: COMPOSE every pair of F (9 functions, len 2).
107 let ho: *i64 = sys_mmap(8*G_MAXSET*G_MAXOPS) as *i64
108 let ha: *i64 = sys_mmap(8*G_MAXSET*G_MAXOPS) as *i64
109 let hl: *i64 = sys_mmap(8*G_MAXSET) as *i64
110 var nh: i64 = 0
111 var i: i64 = 0
112 while i < 3 {
113 var j: i64 = 0
114 while j < 3 {
115 ho[nh*G_MAXOPS+0]=fo[i*G_MAXOPS+0]; ha[nh*G_MAXOPS+0]=fa[i*G_MAXOPS+0]
116 ho[nh*G_MAXOPS+1]=fo[j*G_MAXOPS+0]; ha[nh*G_MAXOPS+1]=fa[j*G_MAXOPS+0]
117 hl[nh]=2; nh = nh + 1
118 j = j + 1
119 }
120 i = i + 1
121 }
122
123 let attack_raw: i64 = g_novcount(ao, aa, al, na, Fraw, 3, 0)
124 let attack_shape: i64 = g_novcount(ao, aa, al, na, Fshape, 3, 1)
125 let honest_raw: i64 = g_novcount(ho, ha, hl, nh, Fraw, 3, 0)
126 let honest_shape: i64 = g_novcount(ho, ha, hl, nh, Fshape, 3, 1)
127
128 gw(" ATTACK (increment-spam x+2..x+9): R4 raw-worth=" as *u8); gn(attack_raw); gw(" SHAPE-worth=" as *u8); gn(attack_shape); gw("\n" as *u8)
129 gw(" HONEST (compose pairs of F): R4 raw-worth=" as *u8); gn(honest_raw); gw(" SHAPE-worth=" as *u8); gn(honest_shape); gw("\n\n" as *u8)
130
131 // ---- GATE (no-fake-green; the arms-race round, measured) ----
132 var t1: i64 = 0; if attack_raw >= 5 { t1 = 1 } // ATTACK GAMES R4's guard (honest finding)
133 var t2: i64 = 0; if attack_shape == 0 { t2 = 1 } // the SHAPE guard CRUSHES the attacker
134 var t3: i64 = 0; if honest_shape >= 3 { t3 = 1 } // honest productivity SURVIVES the new guard
135 var t4: i64 = 0; if honest_shape > attack_shape { t4 = 1 } // the guard DISCRIMINATES honest from gaming
136 var t5: i64 = 0; if attack_raw > attack_shape { t5 = 1 } // the new guard measurably collapses the spam
137
138 gw("T1 attack-games-R4(raw>=5)=" as *u8); gn(t1); gw(" T2 shape-guard-crushes-attack(shape=0)=" as *u8); gn(t2)
139 gw(" T3 honest-survives(shape>=3)=" as *u8); gn(t3); gw(" T4 discriminates=" as *u8); gn(t4); gw(" T5 spam-collapsed=" as *u8); gn(t5); gw("\n" as *u8)
140
141 var green: i64 = 0
142 if t1==1 { if t2==1 { if t3==1 { if t4==1 { if t5==1 { green = 1 } } } } }
143 if green == 1 {
144 gw("VERDICT: GREEN -- the attacker BEAT R4's proxy (raw-worth " as *u8); gn(attack_raw); gw("), and the SHAPE-INVARIANT guard beat the attacker (shape-worth 0) while honest survives (" as *u8); gn(honest_shape); gw(").\n" as *u8)
145 gw("ONE round of the arms race, measured + won. HONEST: a smarter attacker can target SHAPE-novelty next -- the game continues (collusion, worth-self-mod still open).\n" as *u8)
146 sys_exit(0); return 0
147 }
148 gw("VERDICT: RED\n" as *u8); sys_exit(1); return 1
149}