code wiki / _hdl_build / nx_metric_integrity_gate.nx
nx_metric_integrity_gate.nx source
↩ module page · 138 lines · 8388 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_metric_integrity_gate.nx -- R7: the DEEPEST degeneration mode -- corrupting the JUDGE (worth
4// metric) itself. Eurisko's worst failure: heuristics modified the worth machinery to inflate
5// themselves. STRUCTURAL DEFENSE (by construction here): combinators are op-list DATA; the worth
6// metric is FIXED organ CODE that reads that data -- there is NO channel for a combinator to rewrite
7// the metric's logic (Eurisko's code-level self-modification is impossible here). The REAL remaining
8// surface = adversarial INPUT: a combinator feeds the metric output that corrupts its COMPUTATION.
9// Concretely: DEEP SQUARING overflows i64, wrapping to garbage that the naive metric scores as novel
10// worth (the judge mis-computes on attacker-chosen input). The guard = OVERFLOW DETECTION: a function
11// whose evaluation would overflow is OUT-OF-RANGE -> not scored. HONEST: the naive metric IS corrupted
12// (real finding); the guarded metric is incorruptible by input, honest productivity preserved.
13// Sovereign nx_cc->nxasm. license_tier: ORIGINAL [[feedback-no-wave-measured-exceed]]
14import "nx_syscalls.nx"
15
16const M_NPROBE: i64 = 4
17const M_MAXOPS: i64 = 8
18const M_MAXSET: i64 = 32
19const M_BOUND: i64 = 1500000000 // 1.5e9; BOUND^2 < i64 max, so values <= BOUND never overflow
20
21
22// apply function `idx` to x; SET ovf[0]=1 if any step's magnitude would overflow (>BOUND before a
23// multiply/square). The value still wraps (as the naive metric sees it); ovf records the corruption.
24func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
25" as *u8); return ok }
26func m_apply(sops: *i64, sargs: *i64, slens: *i64, idx: i64, x: i64, ovf: *i64) -> i64 {
27 var acc: i64 = x
28 var k: i64 = 0
29 while k < slens[idx] {
30 var mag: i64 = acc; if mag < 0 { mag = 0 - mag }
31 if mag > M_BOUND { ovf[0] = 1 }
32 let op: i64 = sops[idx*M_MAXOPS+k]
33 if op == 0 { acc = acc + sargs[idx*M_MAXOPS+k] }
34 if op == 1 { acc = acc * sargs[idx*M_MAXOPS+k] }
35 if op == 2 { acc = acc * acc }
36 k = k + 1
37 }
38 var mag2: i64 = acc; if mag2 < 0 { mag2 = 0 - mag2 }
39 if mag2 > M_BOUND { ovf[0] = 1 }
40 return acc
41}
42func m_in(sigs: *i64, n: i64, cand: *i64, w: i64) -> i64 {
43 var i: i64 = 0
44 while i < n { var same: i64 = 1; var p: i64 = 0; while p < w { if sigs[i*w+p] != cand[p] { same = 0; p = w } else { p = p + 1 } } if same == 1 { return 1 } i = i + 1 }
45 return 0
46}
47// count novel + non-constant behaviors of a set. heed_ovf=1 -> skip any function that would overflow
48// (the integrity guard); heed_ovf=0 -> the naive metric (scores the wrapped garbage).
49func m_novcount(sops: *i64, sargs: *i64, slens: *i64, nset: i64, Fraw: *i64, nF: i64, heed_ovf: i64) -> i64 {
50 let seen: *i64 = sys_mmap(8*M_MAXSET*M_NPROBE) as *i64
51 var nseen: i64 = 0
52 let raw: *i64 = sys_mmap(8*M_NPROBE) as *i64
53 let ovf: *i64 = sys_mmap(16) as *i64
54 var count: i64 = 0
55 var i: i64 = 0
56 while i < nset {
57 var anyovf: i64 = 0
58 var p: i64 = 0
59 while p < M_NPROBE { ovf[0] = 0; raw[p] = m_apply(sops, sargs, slens, i, p, ovf); if ovf[0] == 1 { anyovf = 1 } p = p + 1 }
60 var skip: i64 = 0
61 if heed_ovf == 1 { if anyovf == 1 { skip = 1 } }
62 if skip == 0 {
63 var isc: i64 = 1; var q: i64 = 1
64 while q < M_NPROBE { if raw[q] != raw[0] { isc = 0 } q = q + 1 }
65 if isc == 0 {
66 if m_in(Fraw, nF, raw, M_NPROBE) == 0 { if m_in(seen, nseen, raw, M_NPROBE) == 0 { if nseen < M_MAXSET { var z: i64 = 0; while z < M_NPROBE { seen[nseen*M_NPROBE+z] = raw[z]; z = z + 1 } nseen = nseen + 1; count = count + 1 } } }
67 }
68 }
69 i = i + 1
70 }
71 return count
72}
73
74func main(argc: i64, argv: *i64) -> i64 {
75 gw("=== R7 METRIC INTEGRITY: can a combinator corrupt the JUDGE? ===\n" as *u8)
76 gw("STRUCTURAL: combinators are op-list DATA; the worth metric is FIXED organ CODE -> no channel to rewrite the metric (Eurisko's code-level self-mod is impossible here).\n" as *u8)
77 gw("TEST: the remaining surface = adversarial INPUT -- deep-squaring overflows i64 -> wrapped garbage. Does the metric stay correct?\n\n" as *u8)
78 // F = {x+1, x*2, x^2}
79 let fo: *i64 = sys_mmap(8*3*M_MAXOPS) as *i64
80 let fa: *i64 = sys_mmap(8*3*M_MAXOPS) as *i64
81 let fl: *i64 = sys_mmap(8*3) as *i64
82 fo[0*M_MAXOPS+0]=0; fa[0*M_MAXOPS+0]=1; fl[0]=1
83 fo[1*M_MAXOPS+0]=1; fa[1*M_MAXOPS+0]=2; fl[1]=1
84 fo[2*M_MAXOPS+0]=2; fa[2*M_MAXOPS+0]=0; fl[2]=1
85 let Fraw: *i64 = sys_mmap(8*3*M_NPROBE) as *i64
86 let ov0: *i64 = sys_mmap(16) as *i64
87 var fi: i64 = 0
88 while fi < 3 { var p: i64 = 0; while p < M_NPROBE { ov0[0]=0; Fraw[fi*M_NPROBE+p] = m_apply(fo, fa, fl, fi, p, ov0); p = p + 1 } fi = fi + 1 }
89
90 // ATTACK set: deep-square overflow functions. square 6-7 times -> x^64..x^128 -> i64 wrap = garbage.
91 let ao: *i64 = sys_mmap(8*M_MAXSET*M_MAXOPS) as *i64
92 let aa: *i64 = sys_mmap(8*M_MAXSET*M_MAXOPS) as *i64
93 let al: *i64 = sys_mmap(8*M_MAXSET) as *i64
94 var na: i64 = 0
95 // A0: square x6 (x^64)
96 var k: i64 = 0; while k < 6 { ao[na*M_MAXOPS+k]=2; aa[na*M_MAXOPS+k]=0; k=k+1 } al[na]=6; na=na+1
97 // A1: +1 then square x6
98 ao[na*M_MAXOPS+0]=0; aa[na*M_MAXOPS+0]=1; k=1; while k < 7 { ao[na*M_MAXOPS+k]=2; aa[na*M_MAXOPS+k]=0; k=k+1 } al[na]=7; na=na+1
99 // A2: *2 then square x5
100 ao[na*M_MAXOPS+0]=1; aa[na*M_MAXOPS+0]=2; k=1; while k < 6 { ao[na*M_MAXOPS+k]=2; aa[na*M_MAXOPS+k]=0; k=k+1 } al[na]=6; na=na+1
101 // A3: square x7 (x^128)
102 k=0; while k < 7 { ao[na*M_MAXOPS+k]=2; aa[na*M_MAXOPS+k]=0; k=k+1 } al[na]=7; na=na+1
103
104 // HONEST set: COMPOSE pairs of F (small values, no overflow).
105 let ho: *i64 = sys_mmap(8*M_MAXSET*M_MAXOPS) as *i64
106 let ha: *i64 = sys_mmap(8*M_MAXSET*M_MAXOPS) as *i64
107 let hl: *i64 = sys_mmap(8*M_MAXSET) as *i64
108 var nh: i64 = 0
109 var i: i64 = 0
110 while i < 3 { var j: i64 = 0; while j < 3 { ho[nh*M_MAXOPS+0]=fo[i*M_MAXOPS+0]; ha[nh*M_MAXOPS+0]=fa[i*M_MAXOPS+0]; ho[nh*M_MAXOPS+1]=fo[j*M_MAXOPS+0]; ha[nh*M_MAXOPS+1]=fa[j*M_MAXOPS+0]; hl[nh]=2; nh=nh+1; j=j+1 } i=i+1 }
111
112 let attack_naive: i64 = m_novcount(ao, aa, al, na, Fraw, 3, 0)
113 let attack_guard: i64 = m_novcount(ao, aa, al, na, Fraw, 3, 1)
114 let honest_naive: i64 = m_novcount(ho, ha, hl, nh, Fraw, 3, 0)
115 let honest_guard: i64 = m_novcount(ho, ha, hl, nh, Fraw, 3, 1)
116
117 gw(" ATTACK (deep-square overflow): naive-metric worth=" as *u8); gn(attack_naive); gw(" guarded worth=" as *u8); gn(attack_guard); gw("\n" as *u8)
118 gw(" HONEST (compose, small values): naive-metric worth=" as *u8); gn(honest_naive); gw(" guarded worth=" as *u8); gn(honest_guard); gw("\n\n" as *u8)
119
120 // ---- GATE (no-fake-green) ----
121 var t1: i64 = 0; if attack_naive >= 1 { t1 = 1 } // the naive judge IS corrupted by overflow input
122 var t2: i64 = 0; if attack_guard == 0 { t2 = 1 } // overflow guard rejects ALL the corruption
123 var t3: i64 = 0; if honest_guard == honest_naive { t3 = 1 } // the guard does NOT change honest worth (no false reject)
124 var t4: i64 = 0; if honest_guard > 0 { t4 = 1 } // honest still productive
125 var t5: i64 = 0; if honest_guard > attack_guard { t5 = 1 } // the guarded judge discriminates honest from corruption
126
127 gw("T1 naive-corrupted=" as *u8); gn(t1); gw(" T2 guard-rejects-overflow=" as *u8); gn(t2)
128 gw(" T3 honest-unaffected=" as *u8); gn(t3); gw(" T4 honest-productive=" as *u8); gn(t4); gw(" T5 discriminates=" as *u8); gn(t5); gw("\n" as *u8)
129
130 var green: i64 = 0
131 if t1==1 { if t2==1 { if t3==1 { if t4==1 { if t5==1 { green = 1 } } } } }
132 if green == 1 {
133 gw("VERDICT: GREEN -- code-level self-mod impossible (structural); the input-corruption surface (overflow) corrupted the NAIVE judge (worth " as *u8); gn(attack_naive); gw("), the overflow-guard makes it incorruptible (worth 0), honest preserved (" as *u8); gn(honest_guard); gw(").\n" as *u8)
134 gw("Round 3 of the arms race -- the deepest mode -- measured + won. The judge is now input-incorruptible + structurally unmodifiable.\n" as *u8)
135 sys_exit(0); return 0
136 }
137 gw("VERDICT: RED\n" as *u8); sys_exit(1); return 1
138}