nx_gapledger_gate.nx source
↩ module page · 261 lines · 14311 B
1// nx_gapledger_gate.nx -- THE GAP LEDGER IS CITED, RECONCILED, AND ITERATION-SAFE.
2//
3// Subject: knowledge/gapledger.conf (the quantitative gap ledger vs Infinigen and MetaHuman) plus
4// the pinned mirrors every THEIR-number is quoted from.
5//
6// WHY THESE TEETH. The ledger exists because a saturating ruler was read as a capability cap (the
7// 89k-triangle "target" that was really the generator's own ceiling). The failure mode this gate
8// must make impossible is a DIFFERENT one with the same shape: a best-of-breed number that nobody
9// can trace, quietly becoming a bar. So:
10// - every THEIR-number must be quoted from a mirror whose BYTES ARE STILL ON DISK (T4/T5);
11// - the two Infinigen partitions must SUM, COMPUTED HERE from their parts, never restated
12// (T2/T3) -- a partition that does not reconcile means a number was transcribed, not read;
13// - numbers we could not source must stay UNSOURCED with NO ratio published (T6);
14// - the iteration rule (capability level AND score, never score alone) must be present (T7),
15// because a consumer reading score alone would re-commit the original error.
16//
17// I/O NOTE: this gate composes sys_read_file, which sizes its buffer FROM THE FILE and cannot
18// short-read. v1 hand-rolled open/read/close against a GL_CAP constant; the compiler refused it
19// (sys_open undefined) and the banked law says the same thing louder -- a buffer cap is not a
20// number to tune, and for a FILE read there is no guess to make. There is no cap in this gate.
21
22import "nx_syscalls.nx"
23import "nx_gate_verdict.nx"
24
25const GL_CONF: *u8 = "knowledge/gapledger.conf"
26const GL_M1: *u8 = "knowledge/fetched/cmp_gapledger_infinigen1_abs.html"
27const GL_M2: *u8 = "knowledge/fetched/cmp_gapledger_infinigen1_full.html"
28const GL_M3: *u8 = "knowledge/fetched/cmp_gapledger_mh_dna.md"
29
30func gl_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
31
32// 1 if the file's bytes are present and non-empty. Composes sys_read_file: a citation whose bytes
33// are gone is not a citation, so "exists" here MEANS "readable and non-empty", not merely stat-able.
34func gl_present(path: *u8) -> i64 {
35 let lp: *i64 = sys_mmap(8) as *i64
36 lp[0] = 0
37 let b: *u8 = sys_read_file(path, lp)
38 if (b as i64) == 0 { return 0 }
39 if lp[0] <= 0 { return 0 }
40 return 1
41}
42
43// find needle in buf[0..n); return offset or -1
44func gl_find(buf: *u8, n: i64, ned: *u8) -> i64 {
45 let m: i64 = gl_slen(ned)
46 if m == 0 { return 0 - 1 }
47 var i: i64 = 0
48 while i + m <= n {
49 var j: i64 = 0
50 while j < m { if buf[i + j] != ned[j] { j = m + 9 } else { j = j + 1 } }
51 if j == m { return i }
52 i = i + 1
53 }
54 return 0 - 1
55}
56
57// value of "<key>=<int>" ANCHORED at a line start; -1 if absent.
58// Anchored so a key appearing inside this file's own prose cannot be read as the datum -- the
59// banked anchor-the-parse law (an unanchored match once read a report's explanatory sentence).
60func gl_num(buf: *u8, n: i64, key: *u8) -> i64 {
61 let m: i64 = gl_slen(key)
62 var i: i64 = 0
63 while i + m + 1 <= n {
64 var at_ls: i64 = 0
65 if i == 0 { at_ls = 1 }
66 if i > 0 { if buf[i - 1] == (10 as u8) { at_ls = 1 } }
67 if at_ls == 1 {
68 var j: i64 = 0
69 while j < m { if buf[i + j] != key[j] { j = m + 9 } else { j = j + 1 } }
70 if j == m {
71 if buf[i + m] == (61 as u8) {
72 var p: i64 = i + m + 1
73 var v: i64 = 0
74 var got: i64 = 0
75 var run: i64 = 1
76 while run == 1 {
77 if p >= n { run = 0 }
78 else {
79 let c: i64 = buf[p] as i64
80 if c >= 48 {
81 if c <= 57 { v = v * 10 + (c - 48); got = 1; p = p + 1 }
82 else { run = 0 }
83 } else { run = 0 }
84 }
85 }
86 if got == 1 { return v }
87 return 0 - 1
88 }
89 }
90 }
91 i = i + 1
92 }
93 return 0 - 1
94}
95
96func main(argc: i64, argv: *i64) -> i64 {
97 let ctr: *i64 = sys_mmap(64) as *i64
98 gv_puts("nx_gapledger_gate -- the gap ledger is cited, reconciled, and iteration-safe\n\n" as *u8)
99
100 let lp: *i64 = sys_mmap(8) as *i64
101 lp[0] = 0
102 let buf: *u8 = sys_read_file(GL_CONF, lp)
103 var n: i64 = 0
104 if (buf as i64) != 0 { n = lp[0] }
105
106 gv_puts(" ledger_bytes=" as *u8); gv_num(n); gv_puts("\n" as *u8)
107 gv_check("ledger-readable-and-nonempty" as *u8, n > 0, ctr)
108 if n <= 0 { return gv_verdict("NX-GAPLEDGER" as *u8, ctr, "the ledger could not be read" as *u8) }
109
110 // ---- T2: the Infinigen GENERATOR partition must SUM, computed here from its parts ----------
111 let g1: i64 = gl_num(buf, n, "ifg_gen_material" as *u8)
112 let g2: i64 = gl_num(buf, n, "ifg_gen_terrain" as *u8)
113 let g3: i64 = gl_num(buf, n, "ifg_gen_lighting_weather_fluid" as *u8)
114 let g4: i64 = gl_num(buf, n, "ifg_gen_rock" as *u8)
115 let g5: i64 = gl_num(buf, n, "ifg_gen_plant_underwater" as *u8)
116 let g6: i64 = gl_num(buf, n, "ifg_gen_creature" as *u8)
117 let g7: i64 = gl_num(buf, n, "ifg_gen_tree" as *u8)
118 let g8: i64 = gl_num(buf, n, "ifg_gen_scene_composition" as *u8)
119 let gsum: i64 = g1 + g2 + g3 + g4 + g5 + g6 + g7 + g8
120 let gtot: i64 = gl_num(buf, n, "ifg_generators_total" as *u8)
121 gv_puts(" generators parts=" as *u8); gv_num(gsum)
122 gv_puts(" declared_total=" as *u8); gv_num(gtot); gv_puts("\n" as *u8)
123 var parts_ok: i64 = 0
124 if g1 > 0 { if g2 > 0 { if g3 > 0 { if g4 > 0 { if g5 > 0 { if g6 > 0 { if g7 > 0 { if g8 > 0 { parts_ok = 1 } } } } } } } }
125 gv_check("generator-partition-all-8-parts-present (empty set cannot pass)" as *u8, parts_ok == 1, ctr)
126 gv_check("generator-partition-SUMS-to-declared-total (computed, not restated)" as *u8, gsum == gtot, ctr)
127
128 // ---- T3: the DOF partition must SUM too ----------------------------------------------------
129 let d1: i64 = gl_num(buf, n, "ifg_dof_material" as *u8)
130 let d2: i64 = gl_num(buf, n, "ifg_dof_terrain" as *u8)
131 let d3: i64 = gl_num(buf, n, "ifg_dof_lighting_weather_fluid" as *u8)
132 let d4: i64 = gl_num(buf, n, "ifg_dof_rock" as *u8)
133 let d5: i64 = gl_num(buf, n, "ifg_dof_plant_underwater" as *u8)
134 let d6: i64 = gl_num(buf, n, "ifg_dof_creature" as *u8)
135 let d7: i64 = gl_num(buf, n, "ifg_dof_tree" as *u8)
136 let d8: i64 = gl_num(buf, n, "ifg_dof_scene_composition" as *u8)
137 let dsum: i64 = d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8
138 let dtot: i64 = gl_num(buf, n, "ifg_dof_total" as *u8)
139 gv_puts(" dof parts=" as *u8); gv_num(dsum)
140 gv_puts(" declared_total=" as *u8); gv_num(dtot); gv_puts("\n" as *u8)
141 gv_check("dof-partition-SUMS-to-declared-total (computed, not restated)" as *u8, dsum == dtot, ctr)
142
143 // ---- T4: every declared mirror's BYTES are still present ------------------------------------
144 var mf: i64 = 0
145 if gl_present(GL_M1) == 1 { mf = mf + 1 }
146 if gl_present(GL_M2) == 1 { mf = mf + 1 }
147 if gl_present(GL_M3) == 1 { mf = mf + 1 }
148 gv_puts(" mirrors_readable=" as *u8); gv_num(mf); gv_puts(" of 3\n" as *u8)
149 gv_check("every-declared-mirror-readable-and-nonempty (3 of 3, count bound in condition)" as *u8,
150 mf == 3, ctr)
151
152 // ---- T5: the mirror must actually CONTAIN the claim the ledger quotes -----------------------
153 let mp: *i64 = sys_mmap(8) as *i64
154 mp[0] = 0
155 let mb: *u8 = sys_read_file(GL_M2, mp)
156 var mn: i64 = 0
157 if (mb as i64) != 0 { mn = mp[0] }
158 var q: i64 = 0 - 1
159 if mn > 0 { q = gl_find(mb, mn, "182 procedural asset generators" as *u8) }
160 gv_puts(" quote_found_at_offset=" as *u8); gv_num(q); gv_puts("\n" as *u8)
161 gv_check("the-quoted-claim-is-FOUND-in-the-pinned-mirror-bytes" as *u8, q >= 0, ctr)
162
163 // ---- T6: PROVENANCE -- every best-of-breed number carries a SOURCE CLASS -------------------
164 // The MetaHuman column was UNSOURCED until the operator supplied it directly. That is a real
165 // source class, but it is NOT a pinned mirror, and this tooth exists so the two can never be
166 // confused: the ledger must SAY which class each number is, and must record that independent
167 // verification was attempted rather than quietly skipped.
168 let sc: i64 = gl_find(buf, n, "mh_source_class=operator-specification" as *u8)
169 let pinflag: i64 = gl_num(buf, n, "mh_source_is_pinned_mirror" as *u8)
170 let vatt: i64 = gl_num(buf, n, "mh_verification_attempted" as *u8)
171 let vup: i64 = gl_num(buf, n, "mh_class_upgraded" as *u8)
172 gv_puts(" mh_source_class_labelled=" as *u8); gv_num(sc)
173 gv_puts(" pinned_mirror_flag=" as *u8); gv_num(pinflag)
174 gv_puts(" verification_attempted=" as *u8); gv_num(vatt); gv_puts("\n" as *u8)
175 gv_check("operator-supplied-numbers-LABELLED-and-not-laundered-as-a-mirror" as *u8,
176 sc >= 0, ctr)
177 gv_check("operator-class-explicitly-flagged-NOT-a-pinned-mirror" as *u8, pinflag == 0, ctr)
178 // This tooth was FIRST written as (vatt==1 && vup==0) -- i.e. it assumed the verification would
179 // fail. It then FAILED when the verification SUCCEEDED (a corroborating vendor-doc citation was
180 // found in the estate's own refs register), which is a tooth encoding ONE OUTCOME rather than
181 // the INVARIANT. The invariant is: verification was ATTEMPTED, and its outcome is RECORDED --
182 // and an UPGRADE must NAME what it upgraded to, so nobody can claim corroboration without
183 // saying by what. Both outcomes now pass honestly; neither can be claimed silently.
184 var vres_ok: i64 = 0
185 if vatt == 1 {
186 if vup == 0 { vres_ok = 1 }
187 if vup == 1 {
188 if gl_find(buf, n, "mh_class_after=" as *u8) >= 0 {
189 if gl_find(buf, n, "mh_corroborating_key=" as *u8) >= 0 { vres_ok = 1 }
190 }
191 }
192 }
193 gv_check("verification-ATTEMPTED-and-outcome-RECORDED (an upgrade must name its corroborator)" as *u8,
194 vres_ok == 1, ctr)
195
196 // ---- T9: THE PUBLISHED RATIOS RECONCILE AGAINST THEIR OWN PARTS ----------------------------
197 // A ratio is the one number a reader will quote and the one nobody re-derives, so it is the
198 // easiest place for a transcription error to become a roadmap. Each published ratio is checked
199 // by multiplying it back: ours * ratio must land within ONE UNIT OF OURS of the best-of-breed
200 // value (i.e. the ratio is correct to within rounding). A fabricated or stale ratio fails.
201 let mhj2: i64 = gl_num(buf, n, "mh_joint_count" as *u8)
202 let oj: i64 = gl_num(buf, n, "ours_skelgen_joints" as *u8)
203 let rj: i64 = gl_num(buf, n, "gap_joints_generated_x" as *u8)
204 var dj: i64 = oj * rj - mhj2
205 if dj < 0 { dj = 0 - dj }
206 gv_puts(" joints: ours=" as *u8); gv_num(oj); gv_puts(" x ratio=" as *u8); gv_num(rj)
207 gv_puts(" vs bob=" as *u8); gv_num(mhj2); gv_puts(" residual=" as *u8); gv_num(dj); gv_puts("\n" as *u8)
208 gv_check("joints-ratio-reconciles-against-its-parts" as *u8, dj <= oj, ctr)
209
210 let mhf: i64 = gl_num(buf, n, "mh_facial_controls" as *u8)
211 let of: i64 = gl_num(buf, n, "ours_morf_channels" as *u8)
212 let rf: i64 = gl_num(buf, n, "gap_facial_controls_x" as *u8)
213 var df: i64 = of * rf - mhf
214 if df < 0 { df = 0 - df }
215 gv_puts(" facial: ours=" as *u8); gv_num(of); gv_puts(" x ratio=" as *u8); gv_num(rf)
216 gv_puts(" vs bob=" as *u8); gv_num(mhf); gv_puts(" residual=" as *u8); gv_num(df); gv_puts("\n" as *u8)
217 gv_check("facial-controls-ratio-reconciles-against-its-parts" as *u8, df <= of, ctr)
218
219 let mht2: i64 = gl_num(buf, n, "mh_texture_resolution" as *u8)
220 let ot: i64 = gl_num(buf, n, "ours_texture_resolution" as *u8)
221 let rt: i64 = gl_num(buf, n, "gap_texture_linear_x" as *u8)
222 var dt: i64 = ot * rt - mht2
223 if dt < 0 { dt = 0 - dt }
224 gv_puts(" texture: ours=" as *u8); gv_num(ot); gv_puts(" x ratio=" as *u8); gv_num(rt)
225 gv_puts(" vs bob=" as *u8); gv_num(mht2); gv_puts(" residual=" as *u8); gv_num(dt); gv_puts("\n" as *u8)
226 gv_check("texture-ratio-reconciles-against-its-parts" as *u8, dt <= ot, ctr)
227
228 // ---- T10: the vertices axis must be declared EXCEEDED, not silently worked -----------------
229 // The whole point of the ledger is that an axis we have already won must be visible as won,
230 // or a lane will spend effort on it. This is the roadmap's "vertices NOT AT ALL" row.
231 let vx: i64 = gl_find(buf, n, "gap_verts_verdict=EXCEEDED" as *u8)
232 let r3: i64 = gl_find(buf, n, "roadmap_3=vertices-NOT-AT-ALL" as *u8)
233 var vx_ok: i64 = 0
234 if vx >= 0 { if r3 >= 0 { vx_ok = 1 } }
235 gv_check("an-already-won-axis-is-declared-WON-so-no-lane-works-it" as *u8, vx_ok == 1, ctr)
236
237 // ---- T7: the iteration rule must be present -------------------------------------------------
238 let it1: i64 = gl_find(buf, n, "ITERATION RULE" as *u8)
239 let it2: i64 = gl_find(buf, n, "capability level AND a score" as *u8)
240 var it_ok: i64 = 0
241 if it1 >= 0 { if it2 >= 0 { it_ok = 1 } }
242 gv_check("iteration-rule-present (a score drop with a capability rise is PROGRESS)" as *u8,
243 it_ok == 1, ctr)
244
245 // ---- T8: the highest-leverage rung must carry its evidence ----------------------------------
246 let hl: i64 = gl_find(buf, n, "highest_leverage_rung=" as *u8)
247 let ev: i64 = gl_find(buf, n, "highest_leverage_evidence=" as *u8)
248 var hl_ok: i64 = 0
249 if hl >= 0 { if ev >= 0 { hl_ok = 1 } }
250 gv_check("highest-leverage-rung-named-AND-carries-its-evidence" as *u8, hl_ok == 1, ctr)
251
252 // ---- neg-control: a partition that does NOT reconcile must be REJECTED ----------------------
253 // Built from the ledger's OWN parts with one corrupted, so the control is real data rather than
254 // a synthetic fixture. If the bad sum were accepted, T2/T3 would be vacuous.
255 let bad: i64 = g1 + g2 + g3 + g4 + g5 + g6 + g7 + (g8 + 1)
256 gv_bite("neg-control-a-nonreconciling-partition-is-rejected" as *u8,
257 bad != gtot, gsum != gtot, ctr)
258
259 return gv_verdict("NX-GAPLEDGER" as *u8, ctr,
260 "every THEIR-number is quoted from mirrored bytes, both partitions reconcile, and the ledger cannot be read as a cap" as *u8)
261}