code wiki / _hdl_build / nx_evclass_route.nx
nx_evclass_route.nx source
↩ module page · 266 lines · 11198 B
1// nx_evclass_route.nx -- route DERIVED oracle rows to the DOMAINS that actually earned them.
2//
3// THE DEFECT THIS CLOSES (measured 2026-08-01): nx_evoracle_sweep correctly derives third-party oracle
4// rows -- RFC 9807, RFC 7748, RFC 9497, FIPS 180-4 -- and writes them ALL to knowledge/status/
5// evclass_sovereign.conf. But `sovereign` IS NOT A DOMAIN (no sovereign.matrix), while nx_sota_status
6// reads evclass_<domain>.conf per domain. So 7 genuine third-party attestations landed in a file NO
7// CONSUMER READS, and PROVEN stayed 0/41 with the evidence sitting right there.
8//
9// ★★★★★A NEAR-ZERO MATCH MEANS A WRONG JOIN KEY, NOT A MISSING POPULATION. The derivation was never the
10// problem; the rows simply were not addressed to anyone.
11//
12// THE JOIN: every derived row carries `gate=<name>`, and knowledge/compare/<domain>.gates names the gates
13// a domain claims. So gate -> domain is a real, checkable key, not an inference.
14//
15// OUTCOMES ARE NEVER COLLAPSED (the sweep's own law): ROUTED / ALREADY / UNROUTED are counted and named
16// separately -- a row nobody claims and a row already present must never look the same.
17// ⚠These rows remain UNSIGNED. at_verify_row refuses them until an operator-held key exists. This organ
18// supplies ADDRESSING; it does not and cannot supply ATTRIBUTION.
19//
20// nx_evclass_route [srcfile] default knowledge/status/evclass_sovereign.conf
21// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
22import "nx_gateorder_lib.nx"
23import "nx_estate_path.nx" // ep_anchor: the CWD must not decide this organ verdict
24const ER_MAGIC_65536: i64 = 65536
25
26const ER_CAP: i64 = 262144
27const ER_PATH: i64 = 512
28const ER_NAMEW: i64 = 96
29const ER_MAXDOM: i64 = 128
30
31static er_src: *u8
32static er_gates: *u8
33static er_doms: *u8
34static er_ndom: i64
35static er_routed: i64
36static er_already: i64
37static er_unrouted: i64
38static er_rows: i64
39
40func er_init() {
41 er_src = sys_mmap(ER_CAP + 64) as *u8
42 er_gates = sys_mmap(ER_CAP + 64) as *u8
43 er_doms = sys_mmap(ER_MAXDOM * ER_NAMEW + 64) as *u8
44 er_ndom = 0
45 er_routed = 0
46 er_already = 0
47 er_unrouted = 0
48 er_rows = 0
49}
50
51func er_read_into(path: *u8, buf: *u8, cap: i64) -> i64 {
52 let fd: i64 = sys_openat_rd(path)
53 if fd < 0 { return 0 - 1 }
54 var total: i64 = 0
55 var done: i64 = 0
56 while done == 0 {
57 let want: i64 = cap - total
58 if want <= 0 { done = 1 }
59 else {
60 let got: i64 = sys_read(fd, ((buf as i64) + total) as *u8, want)
61 if got <= 0 { done = 1 }
62 else { total = total + got }
63 }
64 }
65 sys_close(fd)
66 buf[total] = 0 as u8
67 return total
68}
69
70// Collect domain names from knowledge/compare/*.gates
71func er_collect_domains() {
72 let dfd: i64 = sys_openat_rd("knowledge/compare" as *u8)
73 if dfd < 0 { return }
74 let dbuf: *u8 = sys_mmap(ER_MAGIC_65536 + 64) as *u8
75 var looping: i64 = 1
76 while looping == 1 {
77 let nread: i64 = sys_getdents64(dfd, dbuf, ER_MAGIC_65536)
78 if nread <= 0 { looping = 0 }
79 else {
80 var off: i64 = 0
81 while off < nread {
82 let lo: i64 = dbuf[off + 16] as i64
83 let hi: i64 = dbuf[off + 17] as i64
84 let reclen: i64 = lo + hi * 256
85 let nm: *u8 = ((dbuf as i64) + off + 19) as *u8
86 var nlen: i64 = 0
87 while nm[nlen] != (0 as u8) { nlen = nlen + 1 }
88 if nlen > 6 {
89 if go_match_at(nm, nlen - 6, nlen, ".gates" as *u8) == 1 {
90 if er_ndom < ER_MAXDOM {
91 var w: i64 = 0
92 let slot: i64 = (er_doms as i64) + er_ndom * ER_NAMEW
93 while w < nlen - 6 {
94 if w < ER_NAMEW - 1 {
95 let d: *u8 = (slot + w) as *u8
96 d[0] = nm[w]
97 }
98 w = w + 1
99 }
100 let term: *u8 = (slot + w) as *u8
101 term[0] = 0 as u8
102 er_ndom = er_ndom + 1
103 }
104 }
105 }
106 if reclen <= 0 { off = nread }
107 else { off = off + reclen }
108 }
109 }
110 }
111 sys_close(dfd)
112}
113
114func er_path_for(pre: *u8, dom: *u8, suf: *u8, out: *u8) {
115 var w: i64 = 0
116 var i: i64 = 0
117 while pre[i] != (0 as u8) {
118 out[w] = pre[i]
119 w = w + 1
120 i = i + 1
121 }
122 var j: i64 = 0
123 while dom[j] != (0 as u8) {
124 if w < ER_PATH - 12 {
125 out[w] = dom[j]
126 w = w + 1
127 }
128 j = j + 1
129 }
130 var k: i64 = 0
131 while suf[k] != (0 as u8) {
132 out[w] = suf[k]
133 w = w + 1
134 k = k + 1
135 }
136 out[w] = 0 as u8
137}
138
139func main(argc: i64, argv: *i64) -> i64 {
140 // ANCHOR FIRST (2026-08-04, nx_cwdguard finding): this organ reads a RELATIVE
141 // knowledge/ path, so its answer depended on where it was launched. No-op when
142 // already at the estate root, so the cron/MCP context is unchanged.
143 ep_anchor()
144 er_init()
145 var src: *u8 = "knowledge/status/evclass_sovereign.conf" as *u8
146 if argc > 1 { src = argv[1] as *u8 }
147 go_puts("=== NX-EVCLASS-ROUTE: address derived oracle rows to the domains that earned them ===\n\n" as *u8)
148 let sn: i64 = er_read_into(src, er_src, ER_CAP)
149 if sn <= 0 {
150 go_puts("no derived rows to route (run nx_evoracle_sweep first)\n" as *u8)
151 return 0
152 }
153 er_collect_domains()
154 go_kv("domains_with_gates" as *u8, er_ndom)
155 go_puts("\n\n" as *u8)
156
157 let gpath: *u8 = sys_mmap(ER_PATH + 64) as *u8
158 let opath: *u8 = sys_mmap(ER_PATH + 64) as *u8
159 let gname: *u8 = sys_mmap(ER_NAMEW + 64) as *u8
160
161 var ls: i64 = 0
162 var i: i64 = 0
163 while i <= sn {
164 var eol: i64 = 0
165 if i == sn { eol = 1 }
166 else { if er_src[i] == (10 as u8) { eol = 1 } }
167 if eol == 1 {
168 var skip: i64 = 0
169 if ls >= i { skip = 1 }
170 else { if er_src[ls] == (35 as u8) { skip = 1 } }
171 if skip == 0 {
172 // pull gate=<name> out of the row -- the join key
173 var gp: i64 = 0 - 1
174 var s: i64 = ls
175 while s < i {
176 if go_match_at(er_src, s, i, "gate=" as *u8) == 1 {
177 gp = s + 5
178 s = i
179 } else { s = s + 1 }
180 }
181 if gp > 0 {
182 er_rows = er_rows + 1
183 var w: i64 = 0
184 var q: i64 = gp
185 var stop: i64 = 0
186 while stop == 0 {
187 if q >= i { stop = 1 }
188 else {
189 if er_src[q] == (32 as u8) { stop = 1 }
190 else {
191 if w < ER_NAMEW - 1 {
192 gname[w] = er_src[q]
193 w = w + 1
194 }
195 q = q + 1
196 }
197 }
198 }
199 gname[w] = 0 as u8
200 var hit: i64 = 0
201 var d: i64 = 0
202 while d < er_ndom {
203 let dom: *u8 = ((er_doms as i64) + d * ER_NAMEW) as *u8
204 er_path_for("knowledge/compare/" as *u8, dom, ".gates" as *u8, gpath)
205 let gn: i64 = er_read_into(gpath, er_gates, ER_CAP)
206 if gn > 0 {
207 if go_first(er_gates, gn, gname) >= 0 {
208 hit = 1
209 er_path_for("knowledge/status/evclass_" as *u8, dom, ".conf" as *u8, opath)
210 // ALREADY vs ROUTED must not look the same
211 let existing: i64 = er_read_into(opath, er_gates, ER_CAP)
212 var dup: i64 = 0
213 if existing > 0 {
214 if go_first(er_gates, existing, gname) >= 0 { dup = 1 }
215 }
216 if dup == 1 {
217 er_already = er_already + 1
218 } else {
219 let fd: i64 = sys_openat_append(opath, 0x1A4)
220 if fd >= 0 {
221 if existing <= 0 {
222 sys_write(fd, "# DERIVED by nx_evoracle_sweep, ADDRESSED here by nx_evclass_route.\n" as *u8, 68)
223 sys_write(fd, "# Join key: the row's gate= is cited by this domain's .gates. UNSIGNED -- at_verify_row\n" as *u8, 88)
224 sys_write(fd, "# refuses these until an operator-held key is registered. Derivation, not attribution.\n" as *u8, 87)
225 }
226 sys_write(fd, ((er_src as i64) + ls) as *u8, i - ls)
227 sys_write(fd, "\n" as *u8, 1)
228 sys_close(fd)
229 er_routed = er_routed + 1
230 go_puts(" ROUTED " as *u8)
231 go_puts(gname)
232 go_puts(" -> " as *u8)
233 go_puts(dom)
234 go_puts("\n" as *u8)
235 }
236 }
237 }
238 }
239 d = d + 1
240 }
241 if hit == 0 {
242 er_unrouted = er_unrouted + 1
243 go_puts(" UNROUTED " as *u8)
244 go_puts(gname)
245 go_puts(" (no domain's .gates cites this gate -- real evidence with no claimant)\n" as *u8)
246 }
247 }
248 }
249 ls = i + 1
250 }
251 i = i + 1
252 }
253
254 go_puts("\n-- RESULT (outcomes named separately, never collapsed) --\n" as *u8)
255 go_kv("rows_read" as *u8, er_rows)
256 go_kv("ROUTED" as *u8, er_routed)
257 go_kv("ALREADY" as *u8, er_already)
258 go_kv("UNROUTED" as *u8, er_unrouted)
259 go_puts("\n\n" as *u8)
260 go_puts(" UNROUTED is not a failure of derivation -- it is a gate whose third-party evidence NO\n" as *u8)
261 go_puts(" domain currently claims. Wiring it into a <domain>.gates converts it into countable\n" as *u8)
262 go_puts(" evidence; leaving it means a real external attestation benefits nobody.\n" as *u8)
263 go_puts(" ⚠ROUTED rows are UNSIGNED and will be REFUSED by at_verify_row until an operator-held\n" as *u8)
264 go_puts(" key is registered. This organ supplies ADDRESSING; only that key supplies ATTRIBUTION.\n" as *u8)
265 return 0
266}