code wiki / (root) / nx_fbx2nxa_gate.nx

nx_fbx2nxa_gate.nx source

↩ module page · 225 lines · 10665 B

1// nx_fbx2nxa_gate.nx -- THE FBX IMPORTER GATE: the unit factor is MEASURED, ANNOUNCED, APPLIED, 2// and REFUSED when forged -- proven on the promoted binary over the FULL donor population. 3// 4// Subject: ./nx_fbx2nxa.elf (the serving-root binary; e2e fork, never an in-process re-derive). 5// All four real donors carry UnitScaleFactor = 1.0 (GlobalSettings dumped 2026-08-23), so the 6// factor legs are proven by FIXTURE: a byte-patched copy of the smallest donor with the D-value 7// set to 2.0 (heights must EXACTLY double, within the derived truncation bound below) and to 0.0 8// (must REFUSE by name). A multiply-by-identity implementation cannot pass the 2.0 tooth -- that 9// is the anti-vacuity. Neutrality: at factor 1.0 every donor's output must be BYTE-IDENTICAL to 10// the shipped knowledge/rigcorpus/*_geom.nxa, all four, no sampling. 11// NOT roster-admitted: imports the 73.6 MB toon donor in-process (multi-second subject; the 12// voxchunk precedent -- the roster beat kills at its declared bound). 13// The absent-record leg (-1 -> announced assumed 1.0) is DECLARED UNTESTED-BY-FIXTURE: no real 14// FBX lacks the record and synthesizing a whole valid record-free FBX would test the synthesizer, 15// not the importer. Covered by code-read; named here so nobody mistakes silence for proof. 16 17import "nx_syscalls.nx" 18import "nx_gate_verdict.nx" 19import "nx_gatekit_lib.nx" 20 21const FG_ELF: *u8 = "./nx_fbx2nxa.elf" 22const FG_DIR: *u8 = "/tmp/nxf2gate" 23const FG_FIX2: *u8 = "/tmp/nxf2gate/witch_x2.fbx" 24const FG_FIX0: *u8 = "/tmp/nxf2gate/witch_x0.fbx" 25const FG_OUT1: *u8 = "/tmp/nxf2gate/witch_base.nxa" 26const FG_OUT2: *u8 = "/tmp/nxf2gate/witch_x2.nxa" 27const FG_OUTP: *u8 = "/tmp/nxf2gate/paladin.nxa" 28const FG_OUTK: *u8 = "/tmp/nxf2gate/knight.nxa" 29const FG_OUTT: *u8 = "/tmp/nxf2gate/toon.nxa" 30const FG_W_FBX: *u8 = "knowledge/rigcorpus/fbx/dark_witch.fbx" 31const FG_P_FBX: *u8 = "knowledge/rigcorpus/fbx/paladin.fbx" 32const FG_K_FBX: *u8 = "knowledge/rigcorpus/fbx/dark_knight.fbx" 33const FG_T_FBX: *u8 = "knowledge/rigcorpus/fbx/toon3d8.fbx" 34const FG_W_REF: *u8 = "knowledge/rigcorpus/dark_witch_geom.nxa" 35const FG_P_REF: *u8 = "knowledge/rigcorpus/paladin_geom.nxa" 36const FG_K_REF: *u8 = "knowledge/rigcorpus/dark_knight_geom.nxa" 37const FG_T_REF: *u8 = "knowledge/rigcorpus/toon3d8_geom.nxa" 38const FG_CAP: i64 = 65536 39// double bit patterns for the patch: 2.0 and 0.0 (IEEE754) 40const FG_BITS_TWO: i64 = 4611686018427387904 41// bound for the exact-double tooth, DERIVED from the announce's own print arithmetic (v1 of 42// this derivation counted only the /1024 conversion truncation and measured a REAL |d|=10): 43// the importer prints height_mm = (h/10/10)*10 -- an integer floor at h/100 then x10, a print 44// quantum of 10. floor((2h+e)/100) vs 2*floor(h/100) differ by at most 2 quanta -> bound 20. 45// The conversion truncation (<=1 raw unit) is inside that. Re-derived, not widened. 46const FG_TRUNC_BOUND: i64 = 20 47 48func fg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 49 50// spawn the importer <fbx> <out> via the estate's PROVEN subprocess primitive (nx_gatekit_lib, 51// deadlock-proven across the whole gate roster). The v1 of this function hand-rolled 52// pipe/fork/exec/wait and DEADLOCKED in production (pid 2240, 50+ min in pipe_wait, artifact 53// frozen at its 91-byte header): an UNCHECKED sys_fork return left the parent reading a 54// writerless pipe forever, and independently the capped drain-then-wait ordering would block 55// the child on any subject writing past the 64 KB buffer. Both defects die with the plumbing -- 56// the banked law: fixtures and subprocess come from nx_gatekit_lib; never re-roll this. 57func fg_run(fbx: *u8, out: *u8, buf: *u8, blen: *i64) -> i64 { 58 return gk_run_capture(FG_ELF, fbx, out, 0 as *u8, 0 as *u8, buf, FG_CAP, blen) 59} 60 61func fg_has(buf: *u8, ned: *u8) -> i64 { 62 let nl: i64 = fg_slen(ned) 63 let bl: i64 = fg_slen(buf) 64 var i: i64 = 0 65 while i + nl <= bl { 66 var j: i64 = 0 67 var hit: i64 = 1 68 while j < nl { if buf[i + j] != ned[j] { hit = 0; j = nl } else { j = j + 1 } } 69 if hit == 1 { return 1 } 70 i = i + 1 71 } 72 return 0 73} 74 75// parse the integer following <key> in buf; -1 if absent 76func fg_num_after(buf: *u8, key: *u8) -> i64 { 77 let kl: i64 = fg_slen(key) 78 let bl: i64 = fg_slen(buf) 79 var i: i64 = 0 80 while i + kl <= bl { 81 var j: i64 = 0 82 var hit: i64 = 1 83 while j < kl { if buf[i + j] != key[j] { hit = 0; j = kl } else { j = j + 1 } } 84 if hit == 1 { 85 var p: i64 = i + kl 86 var v: i64 = 0 87 var any: i64 = 0 88 while buf[p] >= (48 as u8) { 89 if buf[p] > (57 as u8) { p = bl } 90 if p < bl { v = v * 10 + ((buf[p] as i64) - 48); any = 1; p = p + 1 } 91 } 92 if any == 1 { return v } 93 return 0 - 1 94 } 95 i = i + 1 96 } 97 return 0 - 1 98} 99 100// byte-identity of two files, sizes derived from the files themselves 101func fg_same(a: *u8, b: *u8) -> i64 { 102 let la: *i64 = sys_mmap(16) as *i64 103 let lb: *i64 = sys_mmap(16) as *i64 104 let ba: *u8 = sys_read_file(a, la) 105 let bb: *u8 = sys_read_file(b, lb) 106 if (ba as i64) == 0 { return 0 } 107 if (bb as i64) == 0 { return 0 } 108 if la[0] != lb[0] { return 0 } 109 var i: i64 = 0 110 let n: i64 = la[0] 111 while i < n { 112 if ba[i] != bb[i] { return 0 } 113 i = i + 1 114 } 115 return 1 116} 117 118// copy the witch fbx to dst with the UnitScaleFactor D-value patched to bits; return 1 iff the 119// patch site was FOUND (a fixture that never reached the condition proves nothing) 120func fg_patch(dst: *u8, bits: i64) -> i64 { 121 let lp: *i64 = sys_mmap(16) as *i64 122 let b: *u8 = sys_read_file(FG_W_FBX, lp) 123 if (b as i64) == 0 { return 0 } 124 let n: i64 = lp[0] 125 // locate the len-prefixed name (15,0,0,0,"UnitScaleFactor") -- unique in every donor (dumped) 126 var site: i64 = 0 - 1 127 var i: i64 = 0 128 while i + 30 < n { 129 if b[i] == (15 as u8) { 130 if b[i+1] == (0 as u8) { 131 if b[i+2] == (0 as u8) { 132 if b[i+3] == (0 as u8) { 133 var j: i64 = 0 134 var hit: i64 = 1 135 let nm: *u8 = "UnitScaleFactor" as *u8 136 while j < 15 { if b[i + 4 + j] != nm[j] { hit = 0; j = 15 } else { j = j + 1 } } 137 if hit == 1 { site = i + 4 + 15; i = n } 138 } } } 139 } 140 i = i + 1 141 } 142 if site < 0 { return 0 } 143 // walk the S-props to the D scalar 144 var q: i64 = site 145 var guard: i64 = 0 146 var dsite: i64 = 0 - 1 147 while guard < 8 { 148 let t: i64 = (b[q] & 0xff) as i64 149 if t == 68 { dsite = q + 1; guard = 8 } 150 if t == 83 { 151 let sl: i64 = (b[q+1] as i64) | ((b[q+2] as i64) << 8) | ((b[q+3] as i64) << 16) | ((b[q+4] as i64) << 24) 152 q = q + 5 + sl 153 } 154 if t != 68 { if t != 83 { guard = 8 } } 155 guard = guard + 1 156 } 157 if dsite < 0 { return 0 } 158 var k: i64 = 0 159 while k < 8 { b[dsite + k] = ((bits >> (k * 8)) & 255) as u8; k = k + 1 } 160 let fd: i64 = sys_openat_wr(dst, 420) 161 if fd < 0 { return 0 } 162 var w: i64 = 0 163 while w < n { 164 let r: i64 = sys_write(fd, (((b as i64) + w) as *u8), n - w) 165 if r <= 0 { w = n + 1 } else { w = w + r } 166 } 167 sys_close(fd) 168 if w != n { return 0 } 169 return 1 170} 171 172func main(argc: i64, argv: *i64) -> i64 { 173 gv_head("nx_fbx2nxa_gate -- the unit factor is measured, announced, applied, and refused when forged" as *u8) 174 let ctr: *i64 = gv_ctr() 175 sys_mkdir(FG_DIR, 493) 176 let buf: *u8 = sys_mmap(FG_CAP) as *u8 177 let bl: *i64 = sys_mmap(16) as *i64 178 179 // ---- per-donor: announce + neutrality, FULL population ----------------------------------- 180 let rc_w: i64 = fg_run(FG_W_FBX, FG_OUT1, buf, bl) 181 gv_check("witch-import-exits-zero" as *u8, rc_w == 0, ctr) 182 gv_check("witch-announces-factor-1.0-measured" as *u8, fg_has(buf, "unit_scale_micro=1000000" as *u8), ctr) 183 let h_base: i64 = fg_num_after(buf, "height_mm=" as *u8) 184 gv_check("witch-height-parsed" as *u8, h_base > 0, ctr) 185 gv_check("witch-output-byte-identical-to-shipped-geom" as *u8, fg_same(FG_OUT1, FG_W_REF), ctr) 186 187 let rc_p: i64 = fg_run(FG_P_FBX, FG_OUTP, buf, bl) 188 var ok_p: i64 = 0 189 if rc_p == 0 { if fg_has(buf, "unit_scale_micro=1000000" as *u8) == 1 { ok_p = fg_same(FG_OUTP, FG_P_REF) } } 190 gv_check("paladin-announce-and-byte-identity" as *u8, ok_p, ctr) 191 192 let rc_k: i64 = fg_run(FG_K_FBX, FG_OUTK, buf, bl) 193 var ok_k: i64 = 0 194 if rc_k == 0 { if fg_has(buf, "unit_scale_micro=1000000" as *u8) == 1 { ok_k = fg_same(FG_OUTK, FG_K_REF) } } 195 gv_check("knight-announce-and-byte-identity" as *u8, ok_k, ctr) 196 197 let rc_t: i64 = fg_run(FG_T_FBX, FG_OUTT, buf, bl) 198 var ok_t: i64 = 0 199 if rc_t == 0 { if fg_has(buf, "unit_scale_micro=1000000" as *u8) == 1 { ok_t = fg_same(FG_OUTT, FG_T_REF) } } 200 gv_check("toon3d8-announce-and-byte-identity" as *u8, ok_t, ctr) 201 202 // ---- anti-vacuity: factor 2.0 must EXACTLY double the measured height -------------------- 203 gv_check("fixture-patch-x2-reached-the-condition" as *u8, fg_patch(FG_FIX2, FG_BITS_TWO), ctr) 204 let rc2: i64 = fg_run(FG_FIX2, FG_OUT2, buf, bl) 205 gv_check("x2-import-exits-zero" as *u8, rc2 == 0, ctr) 206 gv_check("x2-announces-factor-2.0" as *u8, fg_has(buf, "unit_scale_micro=2000000" as *u8), ctr) 207 let h2: i64 = fg_num_after(buf, "height_mm=" as *u8) 208 var dd: i64 = h2 - 2 * h_base 209 if dd < 0 { dd = 0 - dd } 210 gv_puts(" h_base=" as *u8); gv_num(h_base); gv_puts(" h_x2=" as *u8); gv_num(h2) 211 gv_puts(" |h_x2 - 2*h_base|=" as *u8); gv_num(dd); gv_puts("\n" as *u8) 212 gv_check("x2-height-exactly-doubles-within-derived-truncation-bound" as *u8, dd <= FG_TRUNC_BOUND, ctr) 213 214 // ---- neg-control: factor 0.0 must REFUSE by name ----------------------------------------- 215 gv_check("fixture-patch-x0-reached-the-condition" as *u8, fg_patch(FG_FIX0, 0), ctr) 216 let rc0: i64 = fg_run(FG_FIX0, FG_OUT2, buf, bl) 217 var fired: i64 = 0 218 if rc0 == 3 { fired = fg_has(buf, "REFUSED: UnitScaleFactor" as *u8) } 219 // gv_bite contract: (fired-on-bad, fired-on-good). v1 passed rc_w==0 (true) as the good leg, 220 // i.e. claimed the REFUSAL fired on the good input -- a false positive by argument inversion. 221 // The good leg asks: did the refusal fire on the clean witch run? rc_w==3 is that (false). 222 gv_bite("neg-control-forged-zero-factor-refused-by-name" as *u8, fired, rc_w == 3, ctr) 223 224 return gv_verdict("NX-FBX2NXA" as *u8, ctr, "the unit assumption is now a measurement, and forging it has a named refusal" as *u8) 225}