code wiki / _hdl_build / nx_gen_cid_gate.nx

nx_gen_cid_gate.nx

buildroot/runtime/_hdl_build/nx_gen_cid_gate.nx

7613 B155 linesdepth 7pulls 11 transitivereach 0 importersview sourcekind gate/prooftopic gen
docsdependenciesstructsconstsfunctions

about

nx_gen_cid_gate.nx -- REFEREE for the GALLERY CID CANON (debt 1785881333 / 1785881657). WHAT IT PROTECTS. The gallery CID is NOT a hash of the pixels, despite the name: it is a hash of a CANONICAL FORM built from the PNG's tEXt fields. Twice on 2026-08-04 that canon was missing a field that genuinely changes the image, and the consequence each time was SILENT DATA LOSS -- the second render collided onto the first cid and gp_one's openat_wr truncated the earlier blob: * resolution: 512x512 (md5 a9fa671a) then 768x1024 under the SAME cid -> the 512 image was gone. * cfg_scale: cfg 1.0 (md5 f10849c2) vs 5.0 (md5 6471d466), two different pictures, ONE cid. Fixed by adding `size` and then `args` (the exact generator-facing argument string) to the canon. ★WHY A GATE AND NOT JUST THE FIX: the second collision existed the whole time the first was being celebrated as fixed. Nothing was checking, so a narrower trigger survived. This gate encodes the INVARIANT rather than the two instances: ANY tEXt field that differs must move the cid. ★HERMETIC AND GPU-FREE. It builds tiny synthetic PNGs in memory and drives the REAL png_insert_genrec + nx_store_ingest_compute_cid -- the same code the daemon runs. No render, no engine, no network, so it is safe on any cadence. (A gate that needs a GPU is a gate nobody runs.) license_tier: ORIGINAL expect_exit: 0 module: nishi-core.gen.cidgate

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_png_textw.nx nx_store_ingest.nx nx_gen_cid_gate.nx

imports: nx_syscalls.nxnx_png_textw.nxnx_store_ingest.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap cw sys_write cg_cid sys_mmap ↻ cg_stub cg_be32 png_insert_genrec pw_find_iend pw_text pw_slen nx_store_ingest_compute_ci sys_mmap ↻ nx_store_ingest_harvest sys_mmap ↻ _pe_pngchunk_rdbe _pe_pngtext_locate nx_store_ingest_keq canon_encode sys_mmap ↻ cc_cmp cc_w32 cc_len sys_munmap cid_of sys_mmap ↻ sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_final blk_set_byte ↻ sha256_compress ↻ cid_from_digest

structs

none

consts

25const CG_BUF: i64 = 262144

functions

27func cw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
28func cn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
40func cg_be32(b: *u8, o: i64, v: i64) -> i64
called by 1: cg_stub
45func cg_stub(dst: *u8, w: i64, h: i64) -> i64
called by 2: cg_cidmain calls 1: cg_be32
65func cg_cid(seed: *u8, model: *u8, sampler: *u8, steps: *u8, host: *u8, prompt: *u8, size: *u8, args: *u8, cidout: *u8) -> i64
76func cg_same(a: *u8, b: *u8) -> i64
called by 1: main
82func main(argc: i64, argv: *i64) -> i64