code wiki / (root) / nx_npc_atlas_gate.nx

nx_npc_atlas_gate.nx source

↩ module page · 182 lines · 9508 B

1// nx_npc_atlas_gate.nx -- THE CLAY-FIX GATE (cw_npc_atlas, charsim+graphics watch contract). 2// Subject: the SHIPPED world surface. Proves, on the LIVE docroot artifacts (never fixtures 3// standing in for them): 4// (1) the NPC asset carries TEXC (UVs) and TEXM (baked PBR maps) -- the DATA is real; 5// (2) the TEXM albedo is a real, non-constant PNG -- a solid-color stub cannot pass; 6// (3) the TEXC UVs are non-degenerate -- a constant-UV bake cannot pass; 7// (4) every builtin world page carries the sampling path (aUV attribute, uAtl sampler, 8// npc_atlas runtime marker) -- the WIRING is real; 9// (5) bite: a page with the marker stripped is DETECTED (the detector fires on bad); 10// (6) bite: the banked PRE-TEXM asset is DETECTED (a genuine pre-fix artifact, not a synthetic). 11// DECLARED IMPRECISION (do not trust this gate as more than it is): pixel-level proof that the 12// GPU actually sampled the texture is browser territory -- this gate proves data-real + 13// wiring-real + refusal-real. The ship lane's cw_npc_atlas stage enforces the same contract 14// IN THE PATH, so a clay ship cannot reach the docroot even between gate runs. 15// Recipe-world pages are enforced by that ship stage; this gate re-checks the three BUILTIN 16// pages independently (scope printed, not implied). 17 18import "nx_syscalls.nx" 19import "nx_gate_verdict.nx" 20 21const NAG_ASSET: *u8 = "sites/nishifamily/world/ref9d.nxa" 22const NAG_BANKED_PRETEXM: *u8 = "knowledge/bank/ref9d.nxa.pretexm-20260823" 23const NAG_PAGE1: *u8 = "sites/nishifamily/world/craft.html" 24const NAG_PAGE2: *u8 = "sites/nishifamily/world/beach.html" 25const NAG_PAGE3: *u8 = "sites/nishifamily/world/vale.html" 26const NAG_NPAGES: i64 = 3 27// PNG signature bytes (published, RFC 2083): a map that does not begin with these is not a PNG. 28const NAG_PNG0: i64 = 137 29const NAG_PNG1: i64 = 80 30const NAG_PNG2: i64 = 78 31const NAG_PNG3: i64 = 71 32// TEXM header geometry (nx_nxa_texm contract): 6 hdr words, 3 words per map record, 4 maps. 33const NAG_HDRW: i64 = 6 34const NAG_RECW: i64 = 3 35const NAG_NMAPS: i64 = 4 36const NAG_RES_MIN: i64 = 8 37 38func nag_rd64(b: *u8, off: i64) -> i64 { var v: i64 = 0; var k: i64 = 7; while k >= 0 { v = v*256 + (b[off+k] as i64); k = k - 1 } return v } 39func nag_tag4(b: *u8, off: i64, t: *u8) -> i64 { if b[off] == t[0] { if b[off+1] == t[1] { if b[off+2] == t[2] { if b[off+3] == t[3] { return 1 } } } } return 0 } 40func nag_find(hay: *u8, n: i64, needle: *u8) -> i64 { 41 var nl: i64 = 0 42 while needle[nl] != (0 as u8) { nl = nl + 1 } 43 if nl == 0 { return 0 } 44 var i: i64 = 0 45 while i + nl <= n { 46 var k: i64 = 0 47 while k < nl { if hay[i+k] != needle[k] { k = nl + 1 } else { k = k + 1 } } 48 if k == nl { return 1 } 49 i = i + 1 50 } 51 return 0 52} 53// section byte-offset by tag, or -1 -- reads the TOC the same way the page JS does 54func nag_sec(b: *u8, tag: *u8) -> i64 { 55 let ns: i64 = nag_rd64(b, 16) 56 var s: i64 = 0 57 while s < ns { 58 let e: i64 = 32 + s*32 59 if nag_tag4(b, e, tag) == 1 { return nag_rd64(b, e + 8) } 60 s = s + 1 61 } 62 return 0 - 1 63} 64func nag_page_ok(path: *u8) -> i64 { 65 let box: *i64 = sys_mmap(16) as *i64 66 let pb: *u8 = sys_read_file(path, box) 67 if (pb as i64) == 0 { return 0 } 68 if nag_find(pb, box[0], "uAtl" as *u8) == 0 { return 0 } 69 if nag_find(pb, box[0], "npc_atlas" as *u8) == 0 { return 0 } 70 if nag_find(pb, box[0], "aUV" as *u8) == 0 { return 0 } 71 return 1 72} 73 74func main() -> i64 { 75 let ctr: *i64 = gv_ctr() 76 gv_head("nx_npc_atlas_gate -- the clay fix is DATA + WIRING + REFUSAL, each proven on the live artifact" as *u8) 77 78 // setup: fixture scratch OUTSIDE production paths (fixture-ratchet law) 79 sys_mkdir("/tmp/nx_npc_atlas_gate" as *u8, 493) 80 81 let abox: *i64 = sys_mmap(16) as *i64 82 let ab: *u8 = sys_read_file(NAG_ASSET, abox) 83 gv_check("live-asset-readable" as *u8, (ab as i64) != 0, ctr) 84 if (ab as i64) == 0 { return gv_verdict("NX-NPC-ATLAS" as *u8, ctr, "asset unreadable; nothing else is decidable" as *u8) } 85 86 let texc: i64 = nag_sec(ab, "TEXC" as *u8) 87 let texm: i64 = nag_sec(ab, "TEXM" as *u8) 88 gv_check("asset-carries-TEXC" as *u8, texc > 0, ctr) 89 gv_check("asset-carries-TEXM" as *u8, texm > 0, ctr) 90 if texm <= 0 { return gv_verdict("NX-NPC-ATLAS" as *u8, ctr, "no TEXM; the map teeth cannot run" as *u8) } 91 92 let nmaps: i64 = nag_rd64(ab, texm) 93 let res: i64 = nag_rd64(ab, texm + 8) 94 gv_puts(" TEXM nmaps=" as *u8); gv_num(nmaps); gv_puts(" res=" as *u8); gv_num(res); gv_puts("\n" as *u8) 95 gv_check("texm-declares-four-maps" as *u8, nmaps == NAG_NMAPS, ctr) 96 gv_check("texm-res-at-least-one-filter-block" as *u8, res >= NAG_RES_MIN, ctr) 97 98 // map record 0 = ALBEDO: [id, off, len]; blob base = hdr(6) + 4*3 records = 18 words 99 let mid: i64 = nag_rd64(ab, texm + NAG_HDRW*8) 100 let moff: i64 = nag_rd64(ab, texm + NAG_HDRW*8 + 8) 101 let mlen: i64 = nag_rd64(ab, texm + NAG_HDRW*8 + 16) 102 let blob: i64 = texm + (NAG_HDRW + NAG_NMAPS*NAG_RECW)*8 103 gv_check("albedo-record-is-map-zero" as *u8, mid == 0, ctr) 104 gv_puts(" albedo off=" as *u8); gv_num(moff); gv_puts(" len=" as *u8); gv_num(mlen); gv_puts("\n" as *u8) 105 var pngok: i64 = 0 106 if mlen > 8 { 107 if (ab[blob+moff] as i64) == NAG_PNG0 { if (ab[blob+moff+1] as i64) == NAG_PNG1 { if (ab[blob+moff+2] as i64) == NAG_PNG2 { if (ab[blob+moff+3] as i64) == NAG_PNG3 { pngok = 1 } } } } 108 } 109 gv_check("albedo-is-a-real-png" as *u8, pngok == 1, ctr) 110 // a CONSTANT-color PNG of res x res compresses to well under one byte per row; a real baked 111 // atlas (per-joint region palette + hash detail noise) cannot. Bound: len > res. This kills 112 // the solid-color stub; it is a FLOOR, deliberately loose, and says so. 113 gv_check("albedo-entropy-above-constant-color-floor" as *u8, mlen > res, ctr) 114 115 // TEXC non-degeneracy: rows [u,v,joint] x nv; a constant-UV bake fails both legs 116 let tnv: i64 = nag_rd64(ab, texc) 117 gv_puts(" TEXC rows=" as *u8); gv_num(tnv); gv_puts("\n" as *u8) 118 gv_check("texc-has-rows" as *u8, tnv > 0, ctr) 119 var umin: i64 = 0 - 1 120 var umax: i64 = 0 - 1 121 var j0: i64 = 0 - 1 122 var jdistinct: i64 = 0 123 var i: i64 = 0 124 while i < tnv { 125 let uu: i64 = nag_rd64(ab, texc + 32 + (i*3)*8) 126 let jj: i64 = nag_rd64(ab, texc + 32 + (i*3 + 2)*8) 127 if umin < 0 { umin = uu } 128 if umax < 0 { umax = uu } 129 if uu < umin { umin = uu } 130 if uu > umax { umax = uu } 131 if j0 < 0 { j0 = jj; jdistinct = 1 } 132 if jj != j0 { if jdistinct == 1 { jdistinct = 2 } } 133 i = i + 1 134 } 135 gv_puts(" u-spread=" as *u8); gv_num(umax - umin); gv_puts(" (q16) distinct-joint-charts>=" as *u8); gv_num(jdistinct); gv_puts("\n" as *u8) 136 gv_check("texc-uvs-nondegenerate-u-spread" as *u8, umax > umin, ctr) 137 gv_check("texc-uvs-span-multiple-joint-charts" as *u8, jdistinct >= 2, ctr) 138 139 // the three builtin world pages carry the sampling path (denominator printed, no empty set) 140 gv_puts(" pages-checked=" as *u8); gv_num(NAG_NPAGES); gv_puts(" of 3 builtin worlds (recipe worlds are enforced by the ship stage itself)\n" as *u8) 141 gv_check("craft-page-carries-sampling-path" as *u8, nag_page_ok(NAG_PAGE1) == 1, ctr) 142 gv_check("beach-page-carries-sampling-path" as *u8, nag_page_ok(NAG_PAGE2) == 1, ctr) 143 gv_check("vale-page-carries-sampling-path" as *u8, nag_page_ok(NAG_PAGE3) == 1, ctr) 144 145 // BITE 1: strip the marker from a COPY of the live craft page; the detector must fire. 146 let pbox: *i64 = sys_mmap(16) as *i64 147 let pb: *u8 = sys_read_file(NAG_PAGE1, pbox) 148 var bite1_bad: i64 = 0 149 var bite1_good: i64 = 0 150 if (pb as i64) != 0 { 151 var w: i64 = 0 152 while w + 9 <= pbox[0] { 153 if pb[w] == (110 as u8) { if pb[w+1] == (112 as u8) { if pb[w+2] == (99 as u8) { if pb[w+3] == (95 as u8) { if pb[w+4] == (97 as u8) { 154 pb[w+4] = 122 as u8 155 } } } } } 156 w = w + 1 157 } 158 let fd: i64 = sys_openat_wr("/tmp/nx_npc_atlas_gate/stripped.html" as *u8, 420) 159 if fd >= 0 { 160 var off2: i64 = 0 161 while off2 < pbox[0] { let wr: i64 = sys_write(fd, ((pb as i64) + off2) as *u8, pbox[0] - off2); if wr <= 0 { off2 = pbox[0] } else { off2 = off2 + wr } } 162 sys_close(fd) 163 if nag_page_ok("/tmp/nx_npc_atlas_gate/stripped.html" as *u8) == 0 { bite1_bad = 1 } 164 } 165 // gv_bite contract: good = DID THE DETECTOR FIRE ON THE GOOD INPUT (must be 0). 166 // Computed from the live page, never a constant -- a constant 0 would be a vacuous leg. 167 bite1_good = 1 - nag_page_ok(NAG_PAGE1) 168 } 169 gv_bite("neg-control-stripped-page-detected" as *u8, bite1_bad, bite1_good, ctr) 170 171 // BITE 2: the BANKED pre-TEXM asset (a genuine pre-fix artifact) must be detected as clay. 172 let bbox: *i64 = sys_mmap(16) as *i64 173 let bb: *u8 = sys_read_file(NAG_BANKED_PRETEXM, bbox) 174 var bite2_bad: i64 = 0 175 if (bb as i64) != 0 { if nag_sec(bb, "TEXM" as *u8) < 0 { bite2_bad = 1 } } 176 // good leg computed from the LIVE asset (0 = detector silent on good), never a constant 177 var bite2_good: i64 = 0 178 if nag_sec(ab, "TEXM" as *u8) < 0 { bite2_good = 1 } 179 gv_bite("neg-control-pretexm-asset-detected" as *u8, bite2_bad, bite2_good, ctr) 180 181 return gv_verdict("NX-NPC-ATLAS" as *u8, ctr, "data + wiring + refusal proven on live artifacts; pixel proof is browser territory and says so above" as *u8) 182}