code wiki / _hdl_build / nx_evoracle_attest.nx

nx_evoracle_attest.nx source

↩ module page · 220 lines · 9970 B

1// nx_evoracle_attest.nx -- THE ORACLE PRODUCER. The missing writer that makes an oracle attestation a 2// DERIVED FACT instead of hand-typed prose. 3// 4// WHY THIS ORGAN EXISTS (measured 2026-07-31): EV_CLASS_ORACLE had exactly ONE consumer 5// (nx_sota_status.nx:220) and NO producer. The only way an oracle row could ever exist was for an agent to 6// type `class=oracle ref=RFC7748` into a conf file -- having compared absolutely nothing. A class whose 7// only writer is prose is not evidence, it is a claim wearing evidence's clothes. 8// 9// WHAT "DERIVED" MEANS HERE, MECHANICALLY. This organ refuses to emit a row unless it has itself just: 10// 1 READ the subject source and classified its party-ness with nx_evoracle -- and got THIRD. 11// A first-party subject is REFUSED. Its answers are ours; agreement with ourselves is not independence. 12// 2 EXTRACTED the external authority actually named in that source, so ref= is a QUOTE, not a label. 13// 3 HASHED the exact bytes it classified (sha256) -> refdig=. Prose can CLAIM RFC 7748; a digest commits 14// to the bytes. If the vectors are later edited, the digest moves and the old row stops matching. 15// 4 FORKED AND RUN the gate binary and required exit 0. ★A GREEN GATE IS THE ONLY THING THAT LICENSES 16// THE WORD "pass". An attestation written without running anything is the exact defect this whole 17// workstream was opened to delete. 18// Any step failing is a REFUSAL with a named reason, never a downgraded row: a partially-earned oracle row 19// looks like proof while being unverifiable, which is strictly worse than no row. 20// 21// ⚠⚠HONESTY BOUNDARY, STATED IN THE ORGAN SO IT CANNOT BE MISREAD AS WORKING: 22// THE ROW THIS EMITS IS UNSIGNED, AND at_verify_row WILL REFUSE IT. That is correct and deliberate. 23// knowledge/attest_keys.conf is ABSENT, and nx_fs_write DENIES paths matching `key` -- a load-bearing 24// refusal, because an agent that can write the signer registry can register its own key as role=human and 25// certify its own work. This organ does NOT route around that. It produces the DERIVATION; a registered 26// key must supply the ATTRIBUTION. Emitting an unsigned row that is visibly refused is the honest end 27// state for an agent; silently minting a key to make the number move would be the dishonest one. 28// ⚠ALSO MEASURED: nx_evattest.nx defines MECH|LLM|HUMAN and has NO AT_CLASS_ORACLE. Oracle rows are 29// permitted there only by FALL-THROUGH (the role rules constrain HUMAN and LLM and never mention oracle). 30// Permitted by omission is not permitted by declaration -- a future default-deny would silently kill the 31// class, and the loader and the verifier currently disagree about the vocabulary. 32// license_tier: ORIGINAL expect_exit: 0 33import "nx_syscalls.nx" 34import "nx_sha256_wasm.nx" 35import "nx_evoracle.nx" 36const K_MAGIC_1024: i64 = 1024 37 38func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 39func wb(b: *u8, n: i64) -> i64 { sys_write(1, b, n); return 0 } 40 41func nn(v: i64) -> i64 { 42 var m: i64 = v 43 if m < 0 { w("-" as *u8); m = 0 - m } 44 let t: *u8 = sys_mmap(32) 45 var k: i64 = 0 46 if m == 0 { t[0] = 48 as u8; k = 1 } 47 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 48 let b: *u8 = sys_mmap(32) 49 var j: i64 = 0 50 while j < k { b[j] = t[k - 1 - j]; j = j + 1 } 51 sys_write(1, b, k) 52 return 0 53} 54 55func hexnib(v: i64) -> i64 { if v < 10 { return 48 + v } return 87 + v } 56 57// ---- extract the authority actually NAMED in the source, so ref= is a quote and not a label ---- 58// Copies the token starting at the citation plus the following run of [A-Za-z0-9.-], capped. If we cannot 59// quote it we do not invent it: an empty ref means the caller must refuse. 60func extract_ref(b: *u8, n: i64, out: *u8, cap: i64) -> i64 { 61 var at: i64 = 0 - 1 62 if at < 0 { at = evo_find(b, n, "RFC " as *u8) } 63 if at < 0 { at = evo_find(b, n, "RFC7" as *u8) } 64 if at < 0 { at = evo_find(b, n, "FIPS" as *u8) } 65 if at < 0 { at = evo_find(b, n, "NIST" as *u8) } 66 if at < 0 { at = evo_find(b, n, "IEEE" as *u8) } 67 if at < 0 { at = evo_find(b, n, "ISO/IEC" as *u8) } 68 if at < 0 { at = evo_find(b, n, "Unicode" as *u8) } 69 if at < 0 { at = evo_find(b, n, "canonical reference" as *u8) } 70 if at < 0 { at = evo_find(b, n, "reference vector" as *u8) } 71 if at < 0 { at = evo_find(b, n, "OpenSSL" as *u8) } 72 if at < 0 { return 0 } 73 var k: i64 = 0 74 var p: i64 = at 75 while p < n { 76 if k >= cap - 1 { p = n } 77 else { 78 let c: i64 = b[p] as i64 79 var keep: i64 = 0 80 if c >= 48 { if c <= 57 { keep = 1 } } 81 if c >= 65 { if c <= 90 { keep = 1 } } 82 if c >= 97 { if c <= 122 { keep = 1 } } 83 if c == 46 { keep = 1 } 84 if c == 45 { keep = 1 } 85 if c == 47 { keep = 1 } 86 if c == 32 { if k > 0 { if k < 8 { keep = 1 } } } 87 if keep == 0 { p = n } 88 else { out[k] = b[p] as u8; k = k + 1; p = p + 1 } 89 } 90 } 91 // Trim trailing spaces so the emitted row never carries a ragged field. Written as an explicit 92 // done-flag loop: the earlier form had two exit paths tangled together and could spin -- a producer 93 // that hangs on a malformed citation would be a denial of service on the evidence plane itself. 94 var done: i64 = 0 95 while done == 0 { 96 if k <= 0 { done = 1 } 97 else { 98 if out[k - 1] == (32 as u8) { k = k - 1 } else { done = 1 } 99 } 100 } 101 out[k] = 0 as u8 102 return k 103} 104 105// ---- run the gate and demand exit 0. This is what licenses the word "pass". ---- 106func run_gate(elf: *u8) -> i64 { 107 let pid: i64 = sys_fork() 108 if pid == 0 { 109 let av: *i64 = sys_mmap(64) as *i64 110 av[0] = elf as i64 111 av[1] = 0 112 let ev: *i64 = sys_mmap(16) as *i64 113 ev[0] = 0 114 sys_execve(elf, av, ev) 115 sys_exit(127) 116 return 127 117 } 118 if pid < 0 { return 0 - 1 } 119 let st: *i64 = sys_mmap(16) as *i64 120 st[0] = 0 121 sys_wait4(pid, st, 0) 122 let raw: i64 = st[0] 123 if (raw & 127) != 0 { return 0 - 2 } 124 return (raw / 256) & 255 125} 126 127// c[0]=emitted c[1]=refused 128func attest(c: *i64, src: *u8, elf: *u8, scope: *u8, signer: *u8) -> i64 { 129 w("\n--- candidate: " as *u8); w(src); w("\n" as *u8) 130 let lp: *i64 = sys_mmap(16) as *i64 131 lp[0] = 0 132 let b: *u8 = sys_read_file(src, lp) 133 if lp[0] <= 0 { 134 c[1] = c[1] + 1 135 w(" REFUSED reason=UNREADABLE-SUBJECT\n" as *u8) 136 return 0 137 } 138 139 // STEP 1 -- party-ness. A first-party subject can never back an oracle row. 140 let party: i64 = evo_classify(b, lp[0]) 141 if party != EVO_P_THIRD { 142 c[1] = c[1] + 1 143 w(" REFUSED reason=" as *u8) 144 if party == EVO_P_FIRST { w("FIRST-PARTY (its answers are ours -- agreement with ourselves is not independence)\n" as *u8) } 145 else { w("UNRESOLVED (no external authority named; declare one by hand)\n" as *u8) } 146 return 0 147 } 148 149 // STEP 2 -- quote the authority. If we cannot quote it we refuse rather than invent it. 150 let refbuf: *u8 = sys_mmap(64) as *u8 151 let rl: i64 = extract_ref(b, lp[0], refbuf, 48) 152 if rl <= 0 { 153 c[1] = c[1] + 1 154 w(" REFUSED reason=NO-QUOTABLE-REF\n" as *u8) 155 return 0 156 } 157 158 // STEP 3 -- commit to the exact bytes classified. Prose can claim; a digest commits. 159 let ctx: *u8 = sys_mmap(K_MAGIC_1024) as *u8 160 let dig: *u8 = sys_mmap(64) as *u8 161 nx_sha256_one_shot(b, lp[0], ctx, dig) 162 let hx: *u8 = sys_mmap(64) as *u8 163 var i: i64 = 0 164 while i < 8 { 165 hx[i * 2] = hexnib(((dig[i] as i64) / 16) & 15) as u8 166 hx[i * 2 + 1] = hexnib((dig[i] as i64) & 15) as u8 167 i = i + 1 168 } 169 170 // STEP 4 -- RUN IT. No execution, no attestation. 171 let rc: i64 = run_gate(elf) 172 if rc != 0 { 173 c[1] = c[1] + 1 174 w(" REFUSED reason=GATE-NOT-GREEN rc=" as *u8); nn(rc) 175 w(" (an attestation written without a green run is the defect this lane exists to delete)\n" as *u8) 176 return 0 177 } 178 179 let ts: *i64 = sys_mmap(32) as *i64 180 ts[0] = 0 181 sys_clock_gettime_real(ts) 182 183 c[0] = c[0] + 1 184 w(" DERIVED party=THIRD gate-run=GREEN\n" as *u8) 185 w(" class=oracle verdict=pass scope=" as *u8); w(scope) 186 w(" ref=" as *u8); wb(refbuf, rl) 187 w(" refdig=" as *u8); wb(hx, 16) 188 w(" gate=" as *u8); w(elf) 189 w(" signer=" as *u8); w(signer) 190 w(" epoch=" as *u8); nn(ts[0]); w("\n" as *u8) 191 return 0 192} 193 194func main() -> i64 { 195 let c: *i64 = sys_mmap(64) as *i64 196 c[0] = 0 197 c[1] = 0 198 w("nx_evoracle_attest -- ORACLE PRODUCER (derived from an execution, never declared)\n" as *u8) 199 200 attest(c, "runtime/_hdl_build/nx_sha256_native_kat_gate.nx\x00" as *u8, 201 "_build/nx_sha256_native_kat_gate.sov.elf\x00" as *u8, 202 "sha256-native-vs-FIPS180-4\x00" as *u8, "nx_evoracle_attest\x00" as *u8) 203 204 attest(c, "runtime/_hdl_build/nx_lex_kat.nx\x00" as *u8, 205 "_build/nx_lex_kat.sov.elf\x00" as *u8, 206 "lex-classifiers\x00" as *u8, "nx_evoracle_attest\x00" as *u8) 207 208 attest(c, "runtime/_hdl_build/nx_x86_kat_gate.nx\x00" as *u8, 209 "_build/nx_x86_kat_gate.sov.elf\x00" as *u8, 210 "x86-backend-emit\x00" as *u8, "nx_evoracle_attest\x00" as *u8) 211 212 w("\n-- PRODUCER RESULT --\n" as *u8) 213 w(" rows DERIVED : " as *u8); nn(c[0]); w("\n" as *u8) 214 w(" REFUSED : " as *u8); nn(c[1]); w("\n" as *u8) 215 w("\n⚠THESE ROWS ARE UNSIGNED AND at_verify_row WILL REFUSE THEM. That is the correct end state for an\n" as *u8) 216 w(" agent: knowledge/attest_keys.conf is absent by design, and an agent that could register its own\n" as *u8) 217 w(" signing key could certify its own work. This organ supplies the DERIVATION; only a key the\n" as *u8) 218 w(" operator holds supplies the ATTRIBUTION.\n" as *u8) 219 return 0 220}