nx_uxf_cid_gate.nx source
↩ module page · 104 lines · 5282 B
1// nx_uxf_cid_gate.nx -- the D001 MIGRATION of nx_uxf_cid_test onto nx_gate_verdict (2026-09-06).
2//
3// WHY THIS EXISTS. nx_uxf_cid_test proved the self-describing multicodec CID in June 2026 and has been
4// UNPROMOTABLE ever since: /api/promote refuses it D001 because it hand-rolls its pass and total counters
5// and prints its own verdict line, so nx_gate_green cannot judge it and it records no harness frame --
6// flake and erosion stay invisible for it. The sanctioned answer is to MIGRATE, never to pass
7// allow_own_verdict=yes, which would ship a permanently unreadable gate.
8//
9// EVERY TOOTH IS PRESERVED EXACTLY. The five checks are the original five, in the original order, with the
10// original predicates; what changes is that gv_check owns the counting (so declared and executed cannot
11// diverge) and gv_kv emits the values, so this gate's GREEN can be contradicted from outside by anyone who
12// recomputes a CID. The original test is left untouched as provenance.
13// license_tier: ORIGINAL No hw writes (Rule 26).
14import "nx_gate_verdict.nx"
15import "nx_syscalls.nx"
16import "nx_canon_cid.nx"
17import "nx_uxf_cid.nx"
18
19const UG_PTRTAB: i64 = 64
20const UG_CANON: i64 = 4096
21const UG_CIDBUF: i64 = 128
22const UG_NFIELDS: i64 = 2
23const UG_PROF_HASH_OFF: i64 = 8 // profiled CID is nxc1-<2hex codec>-<64hex>, hash starts at 8
24const UG_PLAIN_HASH_OFF: i64 = 5 // plain cid_of is nxc1-<64hex>, hash starts at 5
25const UG_HASH_HEX: i64 = 64
26
27func ug_streq(a: *u8, b: *u8) -> i64 {
28 var i: i64 = 0
29 while 1 == 1 {
30 if a[i] != b[i] { return 0 }
31 if a[i] == (0 as u8) { return 1 }
32 i = i + 1
33 }
34 return 1
35}
36
37// do the 64-hex hash parts differ? This is the tooth that proves the codec is FOLDED INTO the hash rather
38// than merely prefixed onto it -- a prefix would leave the hash part identical and this returns 0.
39func ug_hash_differs(cidprof: *u8, plain: *u8) -> i64 {
40 var i: i64 = 0
41 while i < UG_HASH_HEX { if cidprof[UG_PROF_HASH_OFF + i] != plain[UG_PLAIN_HASH_OFF + i] { return 1 } i = i + 1 }
42 return 0
43}
44
45func main(argc: i64, argv: *i64) -> i64 {
46 let ctr: *i64 = gv_ctr()
47 gv_head("nx_uxf_cid -- the self-describing multicodec profile CID" as *u8)
48
49 // record 1: {name:User, type:record}
50 let keys: *i64 = sys_mmap(UG_PTRTAB) as *i64
51 let vals: *i64 = sys_mmap(UG_PTRTAB) as *i64
52 keys[0] = ("name\x00") as i64; vals[0] = ("User\x00") as i64
53 keys[1] = ("type\x00") as i64; vals[1] = ("record\x00") as i64
54 let canon: *u8 = sys_mmap(UG_CANON)
55 let clen: i64 = canon_encode(keys, vals, UG_NFIELDS, canon)
56
57 // record 2: {name:Ben, type:record} -- DIFFERENT content, same shape
58 let keys2: *i64 = sys_mmap(UG_PTRTAB) as *i64
59 let vals2: *i64 = sys_mmap(UG_PTRTAB) as *i64
60 keys2[0] = ("name\x00") as i64; vals2[0] = ("Ben\x00") as i64
61 keys2[1] = ("type\x00") as i64; vals2[1] = ("record\x00") as i64
62 let canon2: *u8 = sys_mmap(UG_CANON)
63 let clen2: i64 = canon_encode(keys2, vals2, UG_NFIELDS, canon2)
64
65 let cidA: *u8 = sys_mmap(UG_CIDBUF)
66 let cidB: *u8 = sys_mmap(UG_CIDBUF)
67 let cidC: *u8 = sys_mmap(UG_CIDBUF)
68 let cidD: *u8 = sys_mmap(UG_CIDBUF)
69 let plain: *u8 = sys_mmap(UG_CIDBUF)
70 uxf_cid_profiled(UXF_DATA, canon, clen, cidA)
71 uxf_cid_profiled(UXF_DATA, canon, clen, cidB)
72 uxf_cid_profiled(UXF_DOC, canon, clen, cidC)
73 uxf_cid_profiled(UXF_DATA, canon2, clen2, cidD)
74 cid_of(canon, clen, plain)
75
76 let ra: i64 = uxf_codec_of_cid(cidA)
77 let rc: i64 = uxf_codec_of_cid(cidC)
78
79 gv_check("T1 determinism: same content and same profile give the same CID" as *u8, ug_streq(cidA, cidB), ctr)
80 gv_check("T2 the profile DISTINGUISHES: same content under DATA and DOC give different CIDs" as *u8, 1 - ug_streq(cidA, cidC), ctr)
81 gv_check_eq("T3a self-describing: the DATA profile is readable back out of its CID" as *u8, ra, UXF_DATA, ctr)
82 gv_check_eq("T3b self-describing: the DOC profile is readable back out of its CID" as *u8, rc, UXF_DOC, ctr)
83 gv_check("T4 neg-control still content-addressed: different content under one profile gives different CIDs" as *u8, 1 - ug_streq(cidA, cidD), ctr)
84 gv_check("T5 the codec is FOLDED INTO the hash, not merely prefixed onto it" as *u8, ug_hash_differs(cidA, plain), ctr)
85
86 gv_values_head()
87 gv_kv("canon_len_record1" as *u8, clen)
88 gv_kv("canon_len_record2" as *u8, clen2)
89 gv_kv("codec_read_from_cidA" as *u8, ra)
90 gv_kv("codec_read_from_cidC" as *u8, rc)
91 gv_kv("UXF_DATA" as *u8, UXF_DATA)
92 gv_kv("UXF_DOC" as *u8, UXF_DOC)
93 gv_kv("cidA_eq_cidB" as *u8, ug_streq(cidA, cidB))
94 gv_kv("cidA_eq_cidC" as *u8, ug_streq(cidA, cidC))
95 gv_kv("cidA_eq_cidD" as *u8, ug_streq(cidA, cidD))
96 gv_kv("profiled_hash_differs_from_plain" as *u8, ug_hash_differs(cidA, plain))
97 gv_puts(" cidA(DATA) = " as *u8); gv_puts(cidA); gv_puts("\n" as *u8)
98 gv_puts(" cidC(DOC) = " as *u8); gv_puts(cidC); gv_puts("\n" as *u8)
99 gv_puts(" plain = " as *u8); gv_puts(plain); gv_puts("\n" as *u8)
100
101 let rc2: i64 = gv_verdict("UXF-CID-GATE" as *u8, ctr, "the profile byte is folded into the hash, so two profiles over identical content can never collide and the profile is readable without rehashing" as *u8)
102 sys_exit(rc2)
103 return rc2
104}