code wiki / _hdl_build / nx_auto_builder_gate.nx
nx_auto_builder_gate.nx source
↩ module page · 81 lines · 4514 B
1// nx_auto_builder_gate.nx -- the SELF-BUILD gate: proves spec-in/gated-capability-out works
2// hands-off across three shapes, output is byte-REPRODUCIBLE, and the honest paths hold
3// (malformed spec REFUSED, unsupported shape NEEDS-TUTOR). The S-class-exceed claims of
4// build-code synthesis, each as a row. Durable: ABGATE-ROW/ABGATE lines ->
5// knowledge/status/auto_builder_gate.log. Exit 0 iff every row passes. Owner: Engineer.
6// license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9func abg_w(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 }
10func abg_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 }
11
12// run the organ on a spec; returns its exit code
13func abg_run(spec: *u8) -> i64 {
14 let pid: i64 = sys_fork()
15 if pid == 0 {
16 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 0x1a4)
17 if dn >= 0 { sys_dup3(dn, 1, 0); sys_dup3(dn, 2, 0) }
18 let argv: *i64 = sys_mmap(32) as *i64
19 argv[0] = "/tmp/nx_auto_builder.sov.elf" as *u8 as i64
20 argv[1] = spec as i64
21 argv[2] = 0
22 let envp: *i64 = sys_mmap(16) as *i64
23 envp[0] = 0
24 sys_execve("/tmp/nx_auto_builder.sov.elf" as *u8, argv, envp)
25 sys_exit(127)
26 }
27 let st: *i64 = sys_mmap(16) as *i64
28 sys_wait4(pid, st, 0)
29 return (st[0] >> 8) & 0xff
30}
31
32// content hash of a file (reproducibility probe)
33func abg_hash(path: *u8) -> i64 {
34 let lenp: *i64 = sys_mmap(16) as *i64
35 let b: *u8 = sys_read_file(path, lenp)
36 let n: i64 = lenp[0]
37 if n <= 0 { return 0 - 1 }
38 var h: i64 = 1469598103
39 var i: i64 = 0
40 while i < n { h = (h * 131 + (b[i] as i64)) & 0x7fffffffffff; i = i + 1 }
41 return h
42}
43
44func abg_row(lfd: i64, name: *u8, got: i64, want: i64) -> i64 {
45 abg_w(1, " " as *u8); abg_w(1, name); abg_w(1, ": got=" as *u8); abg_wn(1, got)
46 abg_w(lfd, "ABGATE-ROW name=" as *u8); abg_w(lfd, name)
47 abg_w(lfd, " got=" as *u8); abg_wn(lfd, got); abg_w(lfd, " want=" as *u8); abg_wn(lfd, want)
48 if got == want { abg_w(1, " PASS\n" as *u8); abg_w(lfd, " verdict=PASS\n" as *u8); return 1 }
49 abg_w(1, " FAIL\n" as *u8); abg_w(lfd, " verdict=FAIL\n" as *u8)
50 return 0
51}
52
53func main() -> i64 {
54 abg_w(1, "=== AUTO-BUILDER GATE: spec in, gated capability out -- hands-off, reproducible, honest ===\n" as *u8)
55 let lfd: i64 = sys_openat_append("knowledge/status/auto_builder_gate.log" as *u8, 0x1a4)
56 if lfd < 0 { abg_w(1, " gate log open FAILED -- loud fail\n" as *u8); sys_exit(1); return 1 }
57 var pass: i64 = 0
58 // [1-3] three shapes synthesized hands-off, KATs green inside the organ run
59 pass = pass + abg_row(lfd, "synth-state-machine" as *u8, abg_run("knowledge/specs/build_httpsm.spec" as *u8), 0)
60 pass = pass + abg_row(lfd, "synth-wire-tlv" as *u8, abg_run("knowledge/specs/build_tlv2b.spec" as *u8), 0)
61 pass = pass + abg_row(lfd, "synth-struct-walk" as *u8, abg_run("knowledge/specs/build_chwalk2.spec" as *u8), 0)
62 // [4] reproducibility: a second run from the same spec authors a byte-identical module
63 let h1: i64 = abg_hash("runtime/_hdl_build/_pe_httpsm.nx" as *u8)
64 abg_run("knowledge/specs/build_httpsm.spec" as *u8)
65 let h2: i64 = abg_hash("runtime/_hdl_build/_pe_httpsm.nx" as *u8)
66 var same: i64 = 0
67 if h1 == h2 { if h1 != (0 - 1) { same = 1 } }
68 pass = pass + abg_row(lfd, "byte-reproducible" as *u8, same, 1)
69 // [5] malformed spec REFUSED (exit 2)
70 pass = pass + abg_row(lfd, "malformed-refused" as *u8, abg_run("knowledge/specs/build_badspec.spec" as *u8), 2)
71 // [6] unsupported shape NEEDS-TUTOR (exit 3) -- novelty stays measured
72 pass = pass + abg_row(lfd, "uncovered-needs-tutor" as *u8, abg_run("knowledge/specs/build_needs_tutor.spec" as *u8), 3)
73 abg_w(lfd, "ABGATE rows=6 pass=" as *u8); abg_wn(lfd, pass)
74 if pass == 6 { abg_w(lfd, " verdict=GREEN\n" as *u8) } else { abg_w(lfd, " verdict=RED\n" as *u8) }
75 sys_close(lfd)
76 abg_w(1, " --- AUTO-BUILDER GATE: " as *u8); abg_wn(1, pass); abg_w(1, "/6 rows ---\n" as *u8)
77 if pass == 6 { abg_w(1, " AUTO-BUILDER GATE: GREEN (self-build synthesis holds, honest paths proven)\n" as *u8); sys_exit(0); return 0 }
78 abg_w(1, " AUTO-BUILDER GATE: RED\n" as *u8)
79 sys_exit(1)
80 return 1
81}