code wiki / _hdl_build / nx_genesis_trace_gate.nx
nx_genesis_trace_gate.nx source
↩ module page · 203 lines · 11027 B
1// nx_genesis_trace_gate.nx -- THE REFEREE for the genesis genealogy tracer.
2//
3// Proves nx_genesis_trace correctly verifies the god->adam&eve->...->IO-endpoint chain
4// BOTH directions, AND that it can actually SEE every failure mode (no-fabricated-green):
5//
6// POSITIVE (real lineage knowledge/registry/genesis_lineage.tsv):
7// T1 healthy (operator 2026-06-16: LOCKS ALLOWED IF FLAGGED): endpoint reaches god,
8// 0 broken/orphan/floater/purposeless, >=2 hardware variants, >=1 fragmentation axis
9// proven-unified (we ACTUALLY escaped a lock somewhere), 0 NEVER-BRICK violations.
10// LOCKED axes are REPORTED as the worklist, NOT a failure (outs[5] may be >0).
11//
12// NEGATIVE CONTROLS (each a hermetic /tmp fixture; the flag MUST fire):
13// N1 broken-link : a node whose parent names no node -> broken_links >= 1
14// N2 orphan : a node that does NOT bottom out at god -> orphans >= 1
15// N3 floater : a non-endpoint/non-variant/non-uni leaf -> floaters >= 1
16// N4 purposeless : a node with an empty label (no purpose) -> purposeless >= 1
17// N5 lock-in : a fragmentation axis with NO unification -> locked >= 1
18// N6 no-god : endpoint chain ends at a non-origination -> reaches_god == 0
19// N7 all-locked : chain-whole but NO axis proven-unified -> NOT green (>=1-unified has teeth)
20// N8 never-brick : a firmware node w/o a never-brick flag -> unsafe >= 1
21//
22// GREEN only if T1 AND N1..N8 all hold. Evidence rows + verdict -> knowledge/status/
23// genesis_trace_gate.log via fa_appendz (one-buffer-one-locked-write). Exit 0/1.
24// Sovereign: imports the tracer + nx_framed_append + nx_syscalls (no gcc). license_tier: ORIGINAL
25import "nx_genesis_trace.nx"
26import "nx_framed_append.nx"
27import "nx_syscalls.nx"
28
29const GG_LOG: *u8 = "knowledge/status/genesis_trace_gate.log"
30const GG_REAL: *u8 = "knowledge/registry/genesis_lineage.tsv"
31const GG_RECCAP: i64 = 512
32
33func gg_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != 0 as u8 { dst[off + i] = s[i]; i = i + 1 } return off + i }
34func gg_catn(dst: *u8, off: i64, v: i64) -> i64 {
35 var m: i64 = v; var o: i64 = off
36 if m < 0 { m = 0 - m }
37 let t: *u8 = sys_mmap(28); var k: i64 = 0
38 if m == 0 { t[0] = 48 as u8; k = 1 }
39 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
40 var i: i64 = 0
41 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 }
42 return o + k
43}
44
45func gg_write_file(path: *u8, content: *u8) -> i64 {
46 let fd: i64 = sys_openat_wr(path, 0x1a4)
47 if fd < 0 { return 0 - 1 }
48 var n: i64 = 0; while content[n] != 0 as u8 { n = n + 1 }
49 sys_write(fd, content, n)
50 sys_close(fd)
51 return 0
52}
53
54func gg_tmppath(out: *u8, stem: *u8, epoch: i64, pid: i64) -> i64 {
55 var o: i64 = 0
56 o = gg_cat(out, o, stem)
57 o = gg_catn(out, o, epoch)
58 o = gg_cat(out, o, "." as *u8)
59 o = gg_catn(out, o, pid)
60 o = gg_cat(out, o, ".tsv" as *u8)
61 out[o] = 0 as u8
62 return o
63}
64
65func gg_row(name: *u8, pass: i64) -> i64 {
66 let buf: *u8 = sys_mmap(GG_RECCAP + 16)
67 var o: i64 = 0
68 o = gg_cat(buf, o, "GENGATE row=\x00" as *u8)
69 o = gg_cat(buf, o, name)
70 if pass == 1 { o = gg_cat(buf, o, " verdict=PASS\x00" as *u8) } else { o = gg_cat(buf, o, " verdict=FAIL\x00" as *u8) }
71 buf[o] = 0 as u8
72 fa_appendz(GG_LOG, buf, GG_RECCAP)
73 sys_write(1, " \x00" as *u8, 2)
74 var n: i64 = 0; while name[n] != 0 as u8 { n = n + 1 } sys_write(1, name, n)
75 if pass == 1 { sys_write(1, " PASS\n\x00" as *u8, 6) } else { sys_write(1, " FAIL\n\x00" as *u8, 6) }
76 return 0
77}
78
79// the NEW green predicate (operator 2026-06-16: locks ALLOWED if flagged). GREEN iff:
80// chain whole (reaches god, no broken, endpoint present, no orphans/floaters/purposeless),
81// >=2 hardware variants (not locked to one hardware god),
82// >=1 fragmentation axis proven-unified (= nfrag - locked >= 1: we ESCAPED a lock somewhere),
83// 0 NEVER-BRICK violations (no firmware/CMOS node without a never-brick guarantee).
84// LOCKED axes are allowed + reported as the worklist (outs[5] may be > 0).
85func gg_healthy(o: *i64) -> i64 {
86 if o[1] != 1 { return 0 } // endpoint reaches god(origination)
87 if o[2] != 0 { return 0 } // no broken links
88 if o[7] != 1 { return 0 } // endpoint present
89 if o[8] != 0 { return 0 } // no orphans (every node reaches god)
90 if o[9] != 0 { return 0 } // no floaters (every node has an upward purpose)
91 if o[10] != 0 { return 0 } // no purposeless (every lock is at least flagged)
92 if o[6] < 2 { return 0 } // >=2 hardware variants
93 if (o[3] - o[5]) < 1 { return 0 } // >=1 fragmentation axis proven-unified
94 if o[17] != 0 { return 0 } // NEVER-BRICK: 0 violations
95 return 1
96}
97
98func main() -> i64 {
99 let epoch: i64 = sys_now_realtime_sec()
100 let pid: i64 = __syscall(39, 0, 0, 0, 0, 0, 0)
101 let outs: *i64 = sys_mmap(256) as *i64
102
103 // ---- T1: the REAL lineage is healthy (locks allowed if flagged) ----
104 var t1: i64 = 0
105 if gt_analyze(GG_REAL, outs) == 0 { t1 = gg_healthy(outs) }
106
107 // ---- build hermetic neg-control fixtures ----
108 let p1: *u8 = sys_mmap(256); gg_tmppath(p1, "/tmp/gt_broken." as *u8, epoch, pid)
109 let p2: *u8 = sys_mmap(256); gg_tmppath(p2, "/tmp/gt_orphan." as *u8, epoch, pid)
110 let p3: *u8 = sys_mmap(256); gg_tmppath(p3, "/tmp/gt_floater." as *u8, epoch, pid)
111 let p4: *u8 = sys_mmap(256); gg_tmppath(p4, "/tmp/gt_purpose." as *u8, epoch, pid)
112 let p5: *u8 = sys_mmap(256); gg_tmppath(p5, "/tmp/gt_lock." as *u8, epoch, pid)
113 let p6: *u8 = sys_mmap(256); gg_tmppath(p6, "/tmp/gt_nogod." as *u8, epoch, pid)
114 let p7: *u8 = sys_mmap(256); gg_tmppath(p7, "/tmp/gt_alllocked." as *u8, epoch, pid)
115 let p8: *u8 = sys_mmap(256); gg_tmppath(p8, "/tmp/gt_unsafe." as *u8, epoch, pid)
116
117 gg_write_file(p1, "ORIGIN\torigination\t-\t-\torigin\tgod\nENDPOINT-IO\tendpoint\tGHOST\t-\t-\tio loop bad parent\n" as *u8)
118 gg_write_file(p2, "ORIGIN\torigination\t-\t-\torigin\tgod\nFLOATROOT\tdescent\t-\t-\tsovereign\torphan root not god\nENDPOINT-IO\tendpoint\tORIGIN\t-\t-\tio loop\n" as *u8)
119 gg_write_file(p3, "ORIGIN\torigination\t-\t-\torigin\tgod\nDANGLE\tdescent\tORIGIN\t-\tsovereign\tdangles upward\nENDPOINT-IO\tendpoint\tORIGIN\t-\t-\tio loop\n" as *u8)
120 gg_write_file(p4, "ORIGIN\torigination\t-\t-\torigin\tgod\nNOPURP\tdescent\tORIGIN\t-\tsovereign\t\nENDPOINT-IO\tendpoint\tNOPURP\t-\t-\tio loop\n" as *u8)
121 gg_write_file(p5, "ORIGIN\torigination\t-\t-\torigin\tgod\nFRAG-NET\tfragmentation\tORIGIN\tnetwork\tthird-party\tnet axis no unification\nENDPOINT-IO\tendpoint\tFRAG-NET\t-\t-\tio loop\n" as *u8)
122 gg_write_file(p6, "ANCHOR\tdescent\t-\t-\tsovereign\tnon-god root\nENDPOINT-IO\tendpoint\tANCHOR\t-\t-\tio loop no god\n" as *u8)
123 // p7: chain-whole + 2 hardware variants, but its ONE fragmentation axis has NO unification
124 // -> unified_axes = 0 -> gg_healthy must REJECT (proves the >=1-unified rule has teeth).
125 gg_write_file(p7, "ORIGIN\torigination\t-\t-\torigin\tgod\t-\nFRAG-HW\tfragmentation\tORIGIN\thardware\tthird-party\thw axis no unification\t-\nVAR-A\tvariant\tFRAG-HW\thardware\tthird-party\tchip A\t-\nVAR-B\tvariant\tFRAG-HW\thardware\tthird-party\tchip B\t-\nENDPOINT-IO\tendpoint\tFRAG-HW\t-\t-\tio loop\t-\n" as *u8)
126 // p8: a firmware-axis node with NO never-brick flag -> unsafe >= 1 (the never-brick detector fires).
127 gg_write_file(p8, "ORIGIN\torigination\t-\t-\torigin\tgod\t-\nFRAG-FW\tfragmentation\tORIGIN\tfirmware\tthird-party\tfirmware MISSING never-brick\t-\nENDPOINT-IO\tendpoint\tFRAG-FW\t-\t-\tio loop\t-\n" as *u8)
128
129 // ---- N1 broken-link ----
130 var n1: i64 = 0
131 if gt_analyze(p1, outs) == 0 { if outs[2] >= 1 { n1 = 1 } }
132 // ---- N2 orphan ----
133 var n2: i64 = 0
134 if gt_analyze(p2, outs) == 0 { if outs[8] >= 1 { n2 = 1 } }
135 // ---- N3 floater ----
136 var n3: i64 = 0
137 if gt_analyze(p3, outs) == 0 { if outs[9] >= 1 { n3 = 1 } }
138 // ---- N4 purposeless ----
139 var n4: i64 = 0
140 if gt_analyze(p4, outs) == 0 { if outs[10] >= 1 { n4 = 1 } }
141 // ---- N5 lock-in ----
142 var n5: i64 = 0
143 if gt_analyze(p5, outs) == 0 { if outs[5] >= 1 { n5 = 1 } }
144 // ---- N6 no-god ----
145 var n6: i64 = 0
146 if gt_analyze(p6, outs) == 0 { if outs[1] == 0 { n6 = 1 } }
147 // ---- N7 all-locked is NOT green (no axis proven-unified) ----
148 var n7: i64 = 0
149 if gt_analyze(p7, outs) == 0 { if gg_healthy(outs) == 0 { n7 = 1 } }
150 // ---- N8 never-brick violation seen ----
151 var n8: i64 = 0
152 if gt_analyze(p8, outs) == 0 { if outs[17] >= 1 { n8 = 1 } }
153
154 var passes: i64 = 0
155 if t1 == 1 { passes = passes + 1 }
156 if n1 == 1 { passes = passes + 1 }
157 if n2 == 1 { passes = passes + 1 }
158 if n3 == 1 { passes = passes + 1 }
159 if n4 == 1 { passes = passes + 1 }
160 if n5 == 1 { passes = passes + 1 }
161 if n6 == 1 { passes = passes + 1 }
162 if n7 == 1 { passes = passes + 1 }
163 if n8 == 1 { passes = passes + 1 }
164 var green: i64 = 0
165 if passes == 9 { green = 1 }
166
167 sys_write(1, "genesis-trace gate (locks-flagged completeness + 8 neg-controls)\n\x00" as *u8, 65)
168 gg_row("T1-real-lineage-healthy \x00" as *u8, t1)
169 gg_row("N1-broken-link-seen \x00" as *u8, n1)
170 gg_row("N2-orphan-seen \x00" as *u8, n2)
171 gg_row("N3-floater-seen \x00" as *u8, n3)
172 gg_row("N4-purposeless-seen \x00" as *u8, n4)
173 gg_row("N5-lockin-seen \x00" as *u8, n5)
174 gg_row("N6-no-god-seen \x00" as *u8, n6)
175 gg_row("N7-all-locked-not-green \x00" as *u8, n7)
176 gg_row("N8-never-brick-violation\x00" as *u8, n8)
177
178 let vb: *u8 = sys_mmap(GG_RECCAP + 16)
179 var o: i64 = 0
180 o = gg_cat(vb, o, "GENESIS-TRACE verdict=\x00" as *u8)
181 if green == 1 { o = gg_cat(vb, o, "GREEN\x00" as *u8) } else { o = gg_cat(vb, o, "RED\x00" as *u8) }
182 o = gg_cat(vb, o, " passes=\x00" as *u8); o = gg_catn(vb, o, passes); o = gg_cat(vb, o, "/9\x00" as *u8)
183 if green == 0 {
184 o = gg_cat(vb, o, " reason=\x00" as *u8)
185 if t1 == 0 { o = gg_cat(vb, o, "real-lineage-unhealthy \x00" as *u8) }
186 if n1 == 0 { o = gg_cat(vb, o, "broken-link-blind \x00" as *u8) }
187 if n2 == 0 { o = gg_cat(vb, o, "orphan-blind \x00" as *u8) }
188 if n3 == 0 { o = gg_cat(vb, o, "floater-blind \x00" as *u8) }
189 if n4 == 0 { o = gg_cat(vb, o, "purposeless-blind \x00" as *u8) }
190 if n5 == 0 { o = gg_cat(vb, o, "lockin-blind \x00" as *u8) }
191 if n6 == 0 { o = gg_cat(vb, o, "no-god-blind \x00" as *u8) }
192 if n7 == 0 { o = gg_cat(vb, o, "all-locked-passed-as-green \x00" as *u8) }
193 if n8 == 0 { o = gg_cat(vb, o, "never-brick-blind \x00" as *u8) }
194 }
195 o = gg_cat(vb, o, " END\x00" as *u8)
196 vb[o] = 0 as u8
197 fa_appendz(GG_LOG, vb, GG_RECCAP)
198 sys_write(1, vb, o)
199 sys_write(1, "\n\x00" as *u8, 1)
200
201 if green == 1 { return 0 }
202 return 1
203}