nx_paper_audit_gate.nx source
↩ module page · 146 lines · 7217 B
1// nx_paper_audit_gate.nx -- KAT + neg-controls for citation RESOLUTION (AS-3).
2// The two central assertions are T3 and T4: a citation naming a row that does not exist,
3// and a citation whose printed number contradicts the row it names, are both CAUGHT --
4// the exact pair that nx_paperbench scored publishable=1 on. T8 is the non-vacuity probe.
5// DRY nx_gate_verdict lib (D001 migrate-on-touch).
6import "nx_paper_audit.nx"
7import "nx_gate_verdict.nx"
8
9func main() -> i64 {
10 let ctr: *i64 = gv_ctr()
11 gv_head("nx_paper_audit -- citation resolution against the ledger (AS-3)")
12
13 // ledger: E01=100 E02=254
14 let led: *u8 = sys_mmap(512)
15 var lo: i64 = 0
16 lo = pf_app(led, lo, "E01" as *u8); led[lo] = 9 as u8; lo = lo + 1
17 lo = pf_app(led, lo, "100" as *u8); led[lo] = 9 as u8; lo = lo + 1
18 lo = pf_app(led, lo, "src" as *u8); led[lo] = 10 as u8; lo = lo + 1
19 lo = pf_app(led, lo, "E02" as *u8); led[lo] = 9 as u8; lo = lo + 1
20 lo = pf_app(led, lo, "254" as *u8); led[lo] = 9 as u8; lo = lo + 1
21 lo = pf_app(led, lo, "src" as *u8); led[lo] = 10 as u8; lo = lo + 1
22 let ledp: *i64 = sys_mmap(2 * 8) as *i64
23 ledp[0] = led as i64
24 ledp[1] = lo
25 let out: *i64 = sys_mmap(8 * 8) as *i64
26
27 // T1 an HONEST manuscript: both citations resolve and match
28 let good: *u8 = "over n=100 [ev:E01] tasks the baseline was 254 [ev:E02] permille" as *u8
29 var gn: i64 = 0
30 while good[gn] != (0 as u8) { gn = gn + 1 }
31 pa_audit(good, gn, ledp, out)
32 var ok1: i64 = 0
33 if out[0] == 2 { if out[1] == 2 { if out[2] == 0 { if out[3] == 0 { ok1 = 1 } } } }
34 gv_check("T1 honest manuscript: 2 tokens, 2 resolve and match", ok1, ctr)
35
36 // T2 integrity + clean on the honest manuscript
37 var ok2: i64 = 0
38 if pa_integrity(out) == 1000 { if pa_clean(out) == 1 { ok2 = 1 } }
39 gv_check("T2 honest manuscript scores integrity 1000 and CLEAN", ok2, ctr)
40
41 // T3 ***NEG-CONTROL*** DANGLING: a well-formed token naming a row that does not exist
42 let dang: *u8 = "the corpus held 4242 [ev:E99] documents" as *u8
43 var dn2: i64 = 0
44 while dang[dn2] != (0 as u8) { dn2 = dn2 + 1 }
45 pa_audit(dang, dn2, ledp, out)
46 var ok3: i64 = 0
47 if out[0] == 1 { if out[2] == 1 { if out[1] == 0 { if pa_clean(out) == 0 { ok3 = 1 } } } }
48 gv_check("T3 NEG-CONTROL dangling citation to a nonexistent row is CAUGHT", ok3, ctr)
49
50 // T4 ***NEG-CONTROL*** CONTRADICTED: the printed number differs from the row it names.
51 // nx_paperbench scored this exact shape publishable=1 -- a counter cannot see it.
52 let lie: *u8 = "the lexical baseline was 999 [ev:E02] permille" as *u8
53 var ln2: i64 = 0
54 while lie[ln2] != (0 as u8) { ln2 = ln2 + 1 }
55 pa_audit(lie, ln2, ledp, out)
56 var ok4: i64 = 0
57 if out[0] == 1 { if out[3] == 1 { if out[1] == 0 { if pa_clean(out) == 0 { ok4 = 1 } } } }
58 gv_check("T4 NEG-CONTROL number contradicting its own ledger row is CAUGHT", ok4, ctr)
59
60 // T5 UNANCHORED: a citation supporting prose rather than a figure is reported
61 // separately -- it is not a lie, and must not be scored as one.
62 let pro: *u8 = "this follows the published protocol [ev:E01] closely" as *u8
63 var pn: i64 = 0
64 while pro[pn] != (0 as u8) { pn = pn + 1 }
65 pa_audit(pro, pn, ledp, out)
66 var ok5: i64 = 0
67 if out[0] == 1 { if out[4] == 1 { if out[3] == 0 { if out[2] == 0 { ok5 = 1 } } } }
68 gv_check("T5 unanchored citation reported separately, not counted as a lie", ok5, ctr)
69
70 // T6 MIXED: one true, one dangling, one contradicted -- counted independently
71 let mix: *u8 = "n=100 [ev:E01] and 999 [ev:E02] and 4242 [ev:E99]" as *u8
72 var mn: i64 = 0
73 while mix[mn] != (0 as u8) { mn = mn + 1 }
74 pa_audit(mix, mn, ledp, out)
75 var ok6: i64 = 0
76 if out[0] == 3 { if out[1] == 1 { if out[3] == 1 { if out[2] == 1 { ok6 = 1 } } } }
77 gv_check("T6 mixed document: 1 ok, 1 contradicted, 1 dangling, counted independently", ok6, ctr)
78
79 // T7 integrity is PROPORTIONAL, not binary: 1 of 3 = 333 permille
80 var ok7: i64 = 0
81 if pa_integrity(out) == 333 { ok7 = 1 }
82 gv_check("T7 integrity proportional: 1 of 3 resolves = 333 permille", ok7, ctr)
83
84 // T8 NON-VACUITY + FAIL-CLOSED: a manuscript with NO citations scores 0 and is NOT
85 // clean. Unverifiable must never be rewarded as verified -- otherwise the cheapest
86 // way to a perfect audit would be to cite nothing at all.
87 let bare: *u8 = "we improved things by a lot and it was good" as *u8
88 var bn: i64 = 0
89 while bare[bn] != (0 as u8) { bn = bn + 1 }
90 pa_audit(bare, bn, ledp, out)
91 var ok8: i64 = 0
92 if out[0] == 0 { if pa_integrity(out) == 0 { if pa_clean(out) == 0 { ok8 = 1 } } }
93 gv_check("T8 NEG-CONTROL citing nothing scores 0, never a free pass", ok8, ctr)
94
95 // T9 DETERMINISM: same input twice, identical counters
96 pa_audit(mix, mn, ledp, out)
97 let a0: i64 = out[0]
98 let a1: i64 = out[1]
99 let a3: i64 = out[3]
100 pa_audit(mix, mn, ledp, out)
101 var ok9: i64 = 0
102 if out[0] == a0 { if out[1] == a1 { if out[3] == a3 { ok9 = 1 } } }
103 gv_check("T9 audit is deterministic", ok9, ctr)
104
105 // ---- ledger <-> SOURCE: the last unverified link in the provenance chain ----------------
106 // T10 row parsing: id / value / source split out of a real ledger row
107 let rw: *i64 = sys_mmap(8 * 8) as *i64
108 var ok10: i64 = 0
109 if pa_rows(led, lo) == 2 {
110 if pa_row(led, lo, 1, rw) == 1 {
111 if rw[3] - rw[2] == 3 {
112 if led[rw[2]] == (50 as u8) { ok10 = 1 }
113 }
114 }
115 }
116 gv_check("T10 ledger row parses to id/value/source (row 1 value = 254)", ok10, ctr)
117
118 // T11 a value that IS in its named source is CONFIRMED
119 let src: *u8 = "run complete: lexical containment scored 254 permille at matched precision" as *u8
120 var sn: i64 = 0
121 while src[sn] != (0 as u8) { sn = sn + 1 }
122 let vr2: *i64 = sys_mmap(2 * 8) as *i64
123 vr2[0] = rw[2]; vr2[1] = rw[3]
124 var ok11: i64 = 0
125 if pa_contains(src, sn, led, vr2) == 1 { ok11 = 1 }
126 gv_check("T11 ledger value present in its source is CONFIRMED", ok11, ctr)
127
128 // T12 ***NEG-CONTROL, THE POINT OF THIS ARC***: a ledger value that does NOT appear in the
129 // log it names is CAUGHT. Without this check a mistyped or invented ledger row passes every
130 // gate in the lane, because everything downstream treats the ledger as ground truth.
131 let bad: *u8 = "run complete: lexical containment scored 999 permille at matched precision" as *u8
132 var bn2: i64 = 0
133 while bad[bn2] != (0 as u8) { bn2 = bn2 + 1 }
134 var ok12: i64 = 0
135 if pa_contains(bad, bn2, led, vr2) == 0 { ok12 = 1 }
136 gv_check("T12 NEG-CONTROL ledger value ABSENT from its named source is CAUGHT", ok12, ctr)
137
138 // T13 an EMPTY source cannot confirm anything (fails closed, never a free pass)
139 var ok13: i64 = 0
140 if pa_contains(src, 0, led, vr2) == 0 { ok13 = 1 }
141 gv_check("T13 empty source confirms nothing (fails closed)", ok13, ctr)
142
143 let rc: i64 = gv_verdict("PAPER-AUDIT", ctr, "dangling + contradicted neg-controls (the pair paperbench passed), unanchored separated, cite-nothing fails closed, ledger-vs-source link closed")
144 sys_exit(rc)
145 return rc
146}