code wiki / _hdl_build / nx_benchmark_ref_gate.nx

nx_benchmark_ref_gate.nx source

↩ module page · 84 lines · 6070 B

1// nx_benchmark_ref_gate.nx -- liar-kill gate for the durable benchmark-reference registry (operator: "benchmarks 2// must exist SEPARATE or you appear to hallucinate and use them"). Proves, mechanically, for the two references this 3// session leaned on (the HUFF/CDIC algorithm + the MOBI spec): 4// (1) REAL, not hallucinated -- nx_benchmark_ref verify re-hashes the stored bytes; cid must match the meta. 5// (2) REALLY THE CITED THING -- the stored bytes contain the expected markers (huffcdic.py: load_huff/CDIC/Python 6// "import struct"; MOBI spec: "17480"/"HUFF"). 7// (3) SEPARATE, not used -- the sovereign organ nx_huffcdic.nx is a DIFFERENT LANGUAGE (NishiLang func/->i64, 8// and even names its fn huff_load vs the ref's load_huff = clean-room) and contains NO Python ("def "/"import 9// struct"/"self.") and reads NO ref ("knowledge/benchmarks"); its only import is nx_syscalls. 10// GREEN = the benchmarks exist as separate, verifiable, unused artifacts -- killing both the "hallucinated" and the 11// "secretly used" appearances. expect_exit: 0 license_tier: ORIGINAL 12import "nx_syscalls.nx" 13 14func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 15func gnum(v0: i64) -> i64 { var v: i64=v0; if v<0 { sys_write(1,"-" as *u8,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48 as u8;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 } 16func ghas(hay: *u8, hl: i64, needle: *u8) -> i64 { 17 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 18 if nl == 0 { return 0 } 19 var i: i64 = 0 20 while i + nl <= hl { var k: i64=0; var hit: i64=1; while k<nl { if hay[i+k]!=needle[k]{hit=0;k=nl}else{k=k+1} } if hit==1 {return 1} i=i+1 } 21 return 0 22} 23func rd(path: *u8, lenp: *i64) -> *u8 { lenp[0]=0; return sys_read_file(path, lenp) } 24 25func spawn(path: *u8, a0: *u8, a1: *u8, redir: *u8) -> i64 { 26 let pid: i64 = sys_fork() 27 if pid == 0 { 28 let fd: i64 = sys_openat_wr(redir, 420) 29 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) } 30 let argv: *i64 = sys_mmap(64) as *i64 31 var n: i64 = 0 32 argv[0] = path as i64; n = 1 33 if (a0 as i64) != 0 { argv[n] = a0 as i64; n = n + 1 } 34 if (a1 as i64) != 0 { argv[n] = a1 as i64; n = n + 1 } 35 argv[n] = 0 36 let envp: *i64 = sys_mmap(16) as *i64 37 envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0 38 sys_execve(path, argv, envp) 39 sys_exit(127) 40 } 41 let st: *i64 = sys_mmap(16) as *i64 42 sys_wait4(pid, st, 0) 43 return (st[0] >> 8) & 0xff 44} 45 46func main() -> i64 { 47 gp("=== nx_benchmark_ref_gate: benchmarks exist SEPARATE, verifiable, and unused (anti-hallucinate, anti-use) ===\n" as *u8) 48 let BR: *u8 = "_offc/nx_benchmark_ref.elf\x00" as *u8 49 let SC: *u8 = "knowledge/status/benchref_gate_scratch.log\x00" as *u8 50 51 // (1) REAL: verify both stored refs re-hash to their recorded cid 52 let v_huff: i64 = spawn(BR, "verify\x00" as *u8, "calibre-huffcdic\x00" as *u8, SC) 53 let v_mobi: i64 = spawn(BR, "verify\x00" as *u8, "mobileread-mobi\x00" as *u8, SC) 54 55 // load the stored bytes for content + separation checks 56 let lh: *i64 = sys_mmap(8) as *i64; let href: *u8 = rd("knowledge/benchmarks/refs/calibre-huffcdic.ref\x00" as *u8, lh); let hn: i64 = lh[0] 57 let lm: *i64 = sys_mmap(8) as *i64; let mref: *u8 = rd("knowledge/benchmarks/refs/mobileread-mobi.ref\x00" as *u8, lm); let mn: i64 = lm[0] 58 let lo: *i64 = sys_mmap(8) as *i64; let org: *u8 = rd("runtime/_hdl_build/nx_huffcdic.nx\x00" as *u8, lo); let on: i64 = lo[0] 59 60 gp(" verify: huffcdic=" as *u8); gnum(v_huff); gp(" mobi=" as *u8); gnum(v_mobi) 61 gp(" bytes: huffcdic.ref=" as *u8); gnum(hn); gp(" mobi.ref=" as *u8); gnum(mn); gp(" organ=" as *u8); gnum(on); gp("\n" as *u8) 62 63 var pass: i64 = 0; var fail: i64 = 0 64 // (1) real / not hallucinated 65 if v_huff == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL huffcdic-ref-not-real\n" as *u8) } 66 if v_mobi == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL mobi-ref-not-real\n" as *u8) } 67 // (2) really the cited thing 68 if (href as i64)!=0 { if ghas(href, hn, "load_huff" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL huffcdic-no-load_huff\n" as *u8) } } else { fail=fail+1; gp(" FAIL huffcdic-ref-missing\n" as *u8) } 69 if (href as i64)!=0 { if ghas(href, hn, "CDIC" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL huffcdic-no-CDIC\n" as *u8) } } 70 if (mref as i64)!=0 { if ghas(mref, mn, "17480" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL mobi-no-17480\n" as *u8) } } else { fail=fail+1; gp(" FAIL mobi-ref-missing\n" as *u8) } 71 if (mref as i64)!=0 { if ghas(mref, mn, "HUFF" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL mobi-no-HUFF\n" as *u8) } } 72 // (3) SEPARATE / not used: organ is NishiLang, contains NO Python and reads NO ref 73 if (org as i64)!=0 { 74 if ghas(org, on, "func huff_load" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL organ-not-nishilang\n" as *u8) } 75 if ghas(org, on, "def " as *u8)==0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL organ-has-python-def\n" as *u8) } 76 if ghas(org, on, "import struct" as *u8)==0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL organ-has-python-import\n" as *u8) } 77 if ghas(org, on, "self." as *u8)==0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL organ-has-python-self\n" as *u8) } 78 if ghas(org, on, "knowledge/benchmarks" as *u8)==0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL organ-reads-the-ref\n" as *u8) } 79 } else { fail=fail+5; gp(" FAIL organ-missing\n" as *u8) } 80 81 gp("BENCHREF-GATE pass=" as *u8); gnum(pass); gp(" fail=" as *u8); gnum(fail) 82 if fail == 0 { gp(" verdict=GREEN (benchmarks materialized SEPARATE + sha-verified REAL + provably UNUSED by the sovereign organ)\n" as *u8); sys_exit(0); return 0 } 83 gp(" verdict=RED\n" as *u8); sys_exit(1); return 1 84}