code wiki / _hdl_build / nx_evidence_verdict_gate.nx
nx_evidence_verdict_gate.nx source
↩ module page · 195 lines · 9532 B
1// nx_evidence_verdict_gate.nx -- proves the shared evidence law (nx_evidence_verdict.nx) REFUSES every
2// defect it was built to kill, and still passes an honestly-earned claim.
3//
4// This gate is written to its own rule 4 (NON-VACUITY): every clause below has a NEGATIVE CONTROL that
5// makes it fire. A gate that only ever demonstrates PASS has measured nothing -- that is precisely the
6// defect this library outlaws, so this gate must not commit it. T1 is the real, measured production
7// regression, replayed as a test: it is the exact medbilling evidence record from 2026-07-30.
8// license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_evidence_verdict.nx"
11
12func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func wn(v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let b: *u8=sys_mmap(28); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
14func ck(pass: i64, label: *u8, fails: *i64) -> i64 {
15 w(" " as *u8); w(label); w(": " as *u8)
16 if pass==1 { w("PASS\n" as *u8) } else { w("FAIL\n" as *u8); fails[0]=fails[0]+1 }
17 return 0
18}
19
20// build a fully-honest record: 5 of 5 gates green, fresh, provenanced, non-vacuous, triangulated.
21// Each test below then breaks EXACTLY ONE field and asserts the verdict degrades to the named state.
22func ev_seed_good(r: *i64, now: i64) -> i64 {
23 r[EV_R_GREEN] = 5
24 r[EV_R_RAN] = 5
25 r[EV_R_DECLARED] = 5
26 r[EV_R_EPOCH] = now - 60
27 r[EV_R_HOSTLEN] = 12
28 r[EV_R_DIGLEN] = 64
29 r[EV_R_REDSEEN] = 5
30 r[EV_R_CLASSMASK] = EV_CLASS_MECH + EV_CLASS_HUMAN
31 r[EV_R_DISSENT] = 0
32 return 0
33}
34
35func main() -> i64 {
36 let fails: *i64 = sys_mmap(16) as *i64
37 fails[0]=0
38 let now: i64 = 1785433876
39 let r: *i64 = sys_mmap(EV_R_SLOTS*8) as *i64
40 let p: *i64 = sys_mmap(EV_P_SLOTS*8) as *i64
41 p[EV_P_TTL] = 604800
42 p[EV_P_MINCLASSES] = 2
43 p[EV_P_REQHUMAN] = 0
44
45 w("=== nx_evidence_verdict_gate -- the evidence law refuses what it was built to refuse ===\n" as *u8)
46
47 // T0: the honest record PASSES. Without this the gate could refuse everything and look strict.
48 ev_seed_good(r, now)
49 var t0: i64=0
50 if ev_verdict(r, p, now)==EV_PROVEN { t0=1 }
51 ck(t0, "T0 fully-earned claim -> PROVEN (the law is accurate, not merely strict)" as *u8, fails)
52
53 // T1: THE MEASURED PRODUCTION REGRESSION, replayed. medbilling 2026-07-30: 5 gates declared, the old
54 // rule `liar_green = (green >= 1)` stamped ok=1 on a single green gate. Under the law: RED.
55 ev_seed_good(r, now)
56 r[EV_R_GREEN] = 1
57 var t1: i64=0
58 if ev_verdict(r, p, now)==EV_RED { t1=1 }
59 ck(t1, "T1 REGRESSION 1-of-5 gates green (the live medbilling record) -> RED, was PROVEN" as *u8, fails)
60
61 // T1b: the old rule, stated directly, to show this gate discriminates. `green>=1` accepts the very
62 // record the law rejects -- so T1 is a real behaviour change, not a restatement.
63 var t1b: i64=0
64 if (r[EV_R_GREEN] >= 1) == 1 { if ev_verdict(r, p, now) != EV_PROVEN { t1b=1 } }
65 ck(t1b, "T1b NEG-CONTROL: old rule green>=1 accepts this record; the law rejects it" as *u8, fails)
66
67 // T2: a gate that did not RUN cannot be counted. declared 5, ran 4, all 4 green -> RED, not 4/4 PROVEN.
68 ev_seed_good(r, now)
69 r[EV_R_RAN] = 4
70 r[EV_R_GREEN] = 4
71 var t2: i64=0
72 if ev_verdict(r, p, now)==EV_RED { t2=1 }
73 ck(t2, "T2 a declared gate that never ran -> RED (cannot shrink its own denominator)" as *u8, fails)
74
75 // T3: EXPIRY. The measured 13.7-day-old stamp (1183616s) against a 7-day TTL -> STALE, not PROVEN.
76 ev_seed_good(r, now)
77 r[EV_R_EPOCH] = now - 1183616
78 var t3: i64=0
79 if ev_verdict(r, p, now)==EV_STALE { t3=1 }
80 ck(t3, "T3 the live 1183616s-old stamp vs 7d TTL -> STALE (a verdict has an expiry)" as *u8, fails)
81
82 // T4: PROVENANCE. A v1 stamp carrying no host and no digest fails CLOSED -- no grandfathering.
83 ev_seed_good(r, now)
84 r[EV_R_HOSTLEN] = 0
85 r[EV_R_DIGLEN] = 0
86 var t4: i64=0
87 if ev_verdict(r, p, now)==EV_UNPROVEN { t4=1 }
88 ck(t4, "T4 legacy stamp with no host/digest -> UNPROVEN (fails closed, not grandfathered)" as *u8, fails)
89
90 // T5: NON-VACUITY. Gates that have never been observed RED have not been shown to measure anything.
91 ev_seed_good(r, now)
92 r[EV_R_REDSEEN] = 0
93 var t5: i64=0
94 if ev_verdict(r, p, now)==EV_VACUOUS { t5=1 }
95 ck(t5, "T5 gates never observed failing -> VACUOUS (coverage is not detection)" as *u8, fails)
96
97 // T5b: PARTIAL non-vacuity is still vacuity -- 4 of 5 proven-able-to-fail leaves one permanently green.
98 ev_seed_good(r, now)
99 r[EV_R_REDSEEN] = 4
100 var t5b: i64=0
101 if ev_verdict(r, p, now)==EV_VACUOUS { t5b=1 }
102 ck(t5b, "T5b 4-of-5 gates proven able to fail -> still VACUOUS" as *u8, fails)
103
104 // T6: AN LLM MAY NOT CONVICT. Model judgment alone, however confident, cannot reach PROVEN.
105 ev_seed_good(r, now)
106 r[EV_R_CLASSMASK] = EV_CLASS_LLM
107 var t6: i64=0
108 if ev_verdict(r, p, now)==EV_UNPROVEN { t6=1 }
109 ck(t6, "T6 LLM-only evidence -> UNPROVEN (a model corroborates, it never convicts)" as *u8, fails)
110
111 // T6b: LLM + HUMAN, two classes but NO mechanistic leg, is still not proof.
112 ev_seed_good(r, now)
113 r[EV_R_CLASSMASK] = EV_CLASS_LLM + EV_CLASS_HUMAN
114 var t6b: i64=0
115 if ev_verdict(r, p, now)==EV_UNPROVEN { t6b=1 }
116 ck(t6b, "T6b LLM+human with no mechanistic leg -> UNPROVEN (>=1 leg must be mechanistic)" as *u8, fails)
117
118 // T7: A SINGLE mechanistic method is one measurement, not a triangulation.
119 ev_seed_good(r, now)
120 r[EV_R_CLASSMASK] = EV_CLASS_MECH
121 var t7: i64=0
122 if ev_verdict(r, p, now)==EV_UNPROVEN { t7=1 }
123 ck(t7, "T7 mechanistic alone -> UNPROVEN (one method is a measurement, not a triangulation)" as *u8, fails)
124
125 // T8: DISAGREEMENT IS NOT AVERAGED. An independent method reporting FAIL is RED, outranking all else.
126 ev_seed_good(r, now)
127 r[EV_R_DISSENT] = EV_CLASS_HUMAN
128 var t8: i64=0
129 if ev_verdict(r, p, now)==EV_RED { t8=1 }
130 ck(t8, "T8 a dissenting method on an otherwise-perfect record -> RED (never averaged)" as *u8, fails)
131
132 // T9: the honesty ratio keeps an honest denominator -- 10 PROVEN of 40 domains is 250, not 1000.
133 var t9: i64=0
134 if ev_honesty_permil(10, 40)==250 { t9=1 }
135 ck(t9, "T9 honesty ratio 10 of 40 domains = 250 permil (the live measured number)" as *u8, fails)
136
137 // T10: clock skew (a stamp from the future) is refused, not treated as maximally fresh.
138 ev_seed_good(r, now)
139 r[EV_R_EPOCH] = now + 3600
140 var t10: i64=0
141 if ev_verdict(r, p, now)==EV_STALE { t10=1 }
142 ck(t10, "T10 stamp dated in the future -> STALE (skew is refused, not trusted)" as *u8, fails)
143
144 // T11: a domain declaring ZERO gates does not pass on an empty conjunction -- but it is UNPROVEN, not
145 // RED. Nothing ran, so nothing failed. RED is reserved for a method that reported failure.
146 ev_seed_good(r, now)
147 r[EV_R_DECLARED] = 0
148 r[EV_R_RAN] = 0
149 r[EV_R_GREEN] = 0
150 var t11: i64=0
151 if ev_verdict(r, p, now)==EV_UNPROVEN { t11=1 }
152 ck(t11, "T11 zero declared gates -> UNPROVEN (nothing ran, so nothing failed)" as *u8, fails)
153
154 // T11b: RED and UNPROVEN must be DISTINGUISHABLE, not merely both non-PROVEN. A domain whose gate ran
155 // and failed, and a domain with no gate at all, are different problems needing different work.
156 let rb: *i64 = sys_mmap(EV_R_SLOTS*8) as *i64
157 ev_seed_good(rb, now)
158 rb[EV_R_GREEN] = 2
159 var t11b: i64=0
160 if ev_verdict(rb, p, now)==EV_RED { if ev_verdict(r, p, now)==EV_UNPROVEN { t11b=1 } }
161 ck(t11b, "T11b a failed gate reads RED while a missing gate reads UNPROVEN (distinct diagnoses)" as *u8, fails)
162
163 // T12: THE HUMAN LEG CANNOT BE SELF-GRANTED. With require_human on, mechanistic + model agreement is
164 // still not proof -- one agent can produce both in a single session, which is one opinion in two hats.
165 let ph: *i64 = sys_mmap(EV_P_SLOTS*8) as *i64
166 ph[EV_P_TTL] = 604800
167 ph[EV_P_MINCLASSES] = 2
168 ph[EV_P_REQHUMAN] = 1
169 ev_seed_good(r, now)
170 r[EV_R_CLASSMASK] = EV_CLASS_MECH + EV_CLASS_LLM
171 var t12: i64=0
172 if ev_verdict(r, ph, now)==EV_UNPROVEN { t12=1 }
173 ck(t12, "T12 mech+LLM under require_human -> UNPROVEN (an agent cannot certify its own work)" as *u8, fails)
174
175 // T12b: add the human row and the same record earns PROVEN -- the clause gates on the missing leg, it
176 // does not simply refuse everything.
177 ev_seed_good(r, now)
178 r[EV_R_CLASSMASK] = EV_CLASS_MECH + EV_CLASS_LLM + EV_CLASS_HUMAN
179 var t12b: i64=0
180 if ev_verdict(r, ph, now)==EV_PROVEN { t12b=1 }
181 ck(t12b, "T12b mech+LLM+human -> PROVEN (the third leg is what closes it)" as *u8, fails)
182
183 // T12c: the human leg does NOT excuse a missing mechanistic leg. Human+LLM is still two opinions.
184 ev_seed_good(r, now)
185 r[EV_R_CLASSMASK] = EV_CLASS_HUMAN + EV_CLASS_LLM
186 var t12c: i64=0
187 if ev_verdict(r, ph, now)==EV_UNPROVEN { t12c=1 }
188 ck(t12c, "T12c human+LLM without a mechanistic leg -> UNPROVEN (opinions are not measurements)" as *u8, fails)
189
190 w(" fails=" as *u8); wn(fails[0]); w("\n" as *u8)
191 if fails[0]==0 { w("VERDICT: verdict=GREEN (evidence law: quorum, expiry, provenance, non-vacuity, triangulation -- each negative-controlled)\n" as *u8); sys_exit(0) }
192 w("VERDICT: verdict=RED\n" as *u8)
193 sys_exit(1)
194 return 1
195}