code wiki / _hdl_build / nx_prove_all.nx

nx_prove_all.nx source

↩ module page · 75 lines · 4642 B

1// nx_prove_all.nx -- ONE COMMAND RE-PROVES THE CLAIM SET (operator 2026-06-09: "build all this 2// capabilities WITH PROVABILITY"). A claim is only as good as the cost of re-checking it; this 3// orchestrator re-runs every standing grader through the sovereign runner (nx_cc->nxasm->run, no 4// gcc) and writes one durable PROOF line: critic counter-grade, role scorecard, claude-use meter, 5// site quality gate. Add a grader = add a row (data-driven, law #11). Exit 0 iff every grader 6// passes -- "the ecosystem's claims hold" becomes a single re-runnable fact, not a narrative. 7// license_tier: ORIGINAL (orchestration spine = the proven brn_run fork/execve/wait4 pattern) 8import "nx_syscalls.nx" 9import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 10func _p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 12// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 13// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 14// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 15func _pn(v: i64) -> i64 { nxi_out(v); return 0 } 16func _fp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 17// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 18// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 19// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 20// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 21func _fn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } 22func pa_run(module: *u8) -> i64 { 23 let pid: i64 = sys_fork() 24 if pid == 0 { 25 let argv: *i64 = sys_mmap(32) as *i64 26 argv[0] = "_offc/nx_sov_build_run.elf" as *u8 as i64 27 argv[1] = module as i64 28 argv[2] = 0 29 let envp: *i64 = sys_mmap(16) as *i64 30 envp[0] = 0 31 sys_execve("_offc/nx_sov_build_run.elf" as *u8, argv, envp) 32 sys_exit(127) 33 } 34 let st: *i64 = sys_mmap(16) as *i64 35 sys_wait4(pid, st, 0) 36 if (st[0] % 128) != 0 { return 0 - 1 } 37 return (st[0] >> 8) & 0xff 38} 39// THE GRADER TABLE -- add a row to add a proof obligation 40func pa_module(id: i64) -> *u8 { 41 if id == 0 { return "nx_critic_countergrade" as *u8 } 42 if id == 1 { return "nx_role_scorecard" as *u8 } 43 if id == 2 { return "_claude_meter_authored" as *u8 } 44 if id == 3 { return "nx_site_quality_gate" as *u8 } 45 if id == 4 { return "nx_vault_selftest" as *u8 } // SECURITY: encrypted-at-rest + roundtrip + fail-closed 46 if id == 5 { return "nx_vault_multi" as *u8 } // SECURITY: multi-secret store, per-name IV uniqueness 47 if id == 6 { return "nx_audit_gate" as *u8 } // SECURITY: secret-access history is tamper-evident (hash chain) 48 if id == 7 { return "nx_infomgmt_gate" as *u8 } // INFO-MGMT: sovereign segment store + canonical CID (rung 1, NO SQL) 49 if id == 8 { return "nx_triage_gate" as *u8 } // AWARENESS: the triage instrument detects breakage AND certifies health (KAT) 50 if id == 9 { return "nx_xlate_gap_gate" as *u8 } // TOOLCHAIN: once-gapped syscalls (mkdirat/fsync/renameat2/unlinkat) behave under current bless 51 return "nx_vault_suite_test" as *u8 // SECURITY: whole sovereign Vault (transit/lease/acl/dynamic/auth/shamir/rotation) regression-locked as ONE unit (SUITEGATE) 52} 53func main() -> i64 { 54 _p("=== PROVE-ALL: re-running every standing grader sovereignly (one command = the claim set re-proven) ===\n" as *u8) 55 var passn: i64 = 0 56 var id: i64 = 0 57 while id < 11 { 58 _p("---- " as *u8); _p(pa_module(id)); _p(" ----\n" as *u8) 59 let rc: i64 = pa_run(pa_module(id)) 60 _p(" => exit=" as *u8); _pn(rc); _p("\n" as *u8) 61 if rc == 0 { passn = passn + 1 } 62 id = id + 1 63 } 64 let lfd: i64 = sys_openat_append("knowledge/status/proof_ledger.log" as *u8, 0x1a4) 65 if lfd >= 0 { 66 _fp(lfd, "PROOF epoch=" as *u8); _fn(lfd, sys_now_realtime_sec()) 67 _fp(lfd, " graders=11 passed=" as *u8); _fn(lfd, passn) 68 if passn == 11 { _fp(lfd, " verdict=ALL-CLAIMS-HOLD\n" as *u8) } else { _fp(lfd, " verdict=DEGRADED (a grader failed -- investigate, never silence)\n" as *u8) } 69 sys_close(lfd) 70 } 71 _p("PROVE-ALL: " as *u8); _pn(passn); _p("/11 graders green -> knowledge/status/proof_ledger.log\n" as *u8) 72 if passn == 11 { sys_exit(0); return 0 } 73 sys_exit(1) 74 return 1 75}