code wiki / _hdl_build / nx_ecosystem_maturity_rollup_gate.nx

nx_ecosystem_maturity_rollup_gate.nx source

↩ module page · 91 lines · 7116 B

1// nx_ecosystem_maturity_rollup_gate.nx -- proves the unifier MEASURES honestly from the NATIVE store. 2// Seeds tiny test stores (no TSV), rolls them up. T1 GOOD: permil KAT 555 GREEN. T2 NEG-CONTROL: an 3// S-CLASS claim with NO evidence MUST liar-kill -> RED (remove the guard and this fails = load-bearing). 4// T3: S-CLASS WITH evidence is allowed. license_tier: ORIGINAL 5import "nx_ecomat_lib.nx" 6 7func main() -> i64 { 8 var fails: i64 = 0 9 let out: *i64 = sys_mmap(256) 10 let alog: *u8 = "knowledge/status/autonomy_meter.log" as *u8 11 // T1 GOOD: alpha(cur2/bar4/ev1) + beta(cur3/bar5/ev1) => 1000*5/9 = 555, GREEN, 2 domains, 0 liar-kill 12 let w1: *i64 = ss_begin() 13 ec_seed_one(w1, 0, 0, 1, 2, 4, 9, 1, "alpha" as *u8, "b" as *u8, "n" as *u8) 14 ec_seed_one(w1, 1, 1, 7, 3, 5, 9, 1, "beta" as *u8, "b" as *u8, "n" as *u8) 15 ss_commit("/tmp/ecomat_gt_good" as *u8, w1, sys_now_realtime_sec()) 16 let v1: i64 = em_rollup_store("/tmp/ecomat_gt_good" as *u8, alog, out, 0) 17 _p("T1 good : verdict=" as *u8); _fn(1, v1); _p(" permil=" as *u8); _fn(1, out[0]); _p(" liar_kill=" as *u8); _fn(1, out[1]); _p(" domains=" as *u8); _fn(1, out[2]); _p("\n" as *u8) 18 if v1 != 0 { fails = fails + 1 } 19 if out[0] != 555 { fails = fails + 1 } 20 if out[1] != 0 { fails = fails + 1 } 21 if out[2] != 2 { fails = fails + 1 } 22 // T2 NEG-CONTROL: S-CLASS (level 4) claimed with ev=0 -> liar-kill must fire -> RED 23 let w2: *i64 = ss_begin() 24 ec_seed_one(w2, 0, 1, 9, 4, 5, 9, 0, "faker" as *u8, "b" as *u8, "n" as *u8) 25 ss_commit("/tmp/ecomat_gt_bad" as *u8, w2, sys_now_realtime_sec()) 26 let v2: i64 = em_rollup_store("/tmp/ecomat_gt_bad" as *u8, alog, out, 0) 27 _p("T2 neg-ctrl : verdict=" as *u8); _fn(1, v2); _p(" liar_kill=" as *u8); _fn(1, out[1]); _p(" (S-CLASS claim, no evidence -> must be RED)\n" as *u8) 28 if v2 != 1 { fails = fails + 1 } 29 if out[1] < 1 { fails = fails + 1 } 30 // T3: S-CLASS (level 4) WITH ev=1 -> allowed, GREEN, sclass_plus=1 31 let w3: *i64 = ss_begin() 32 ec_seed_one(w3, 0, 0, 1, 4, 5, 9, 1, "real" as *u8, "b" as *u8, "n" as *u8) 33 ss_commit("/tmp/ecomat_gt_hi" as *u8, w3, sys_now_realtime_sec()) 34 let v3: i64 = em_rollup_store("/tmp/ecomat_gt_hi" as *u8, alog, out, 0) 35 _p("T3 sclass+ev : verdict=" as *u8); _fn(1, v3); _p(" sclass_plus=" as *u8); _fn(1, out[3]); _p("\n" as *u8) 36 if v3 != 0 { fails = fails + 1 } 37 if out[3] != 1 { fails = fails + 1 } 38 // T4 PERMIL-DERIVE (evkind=1, anti-staleness): a STALE stored cur=5, but the evlog reads permil=341 39 // -> the rollup OVERRIDES the LEVEL to 2 -> 1000*2/5 = 400 (NOT 1000 the stale stored value gives). 40 ss_writefile("/tmp/ecomat_t4_evlog" as *u8, "permil=341\n" as *u8, 11) 41 let w4: *i64 = ss_begin() 42 ec_seed_one_ev(w4, 0, 2, 13, 5, 5, 9, 1, 1, "autonomy" as *u8, "b" as *u8, "n" as *u8, "/tmp/ecomat_t4_evlog" as *u8, "permil=" as *u8) 43 ss_commit("/tmp/ecomat_gt_derive" as *u8, w4, sys_now_realtime_sec()) 44 let v4: i64 = em_rollup_store("/tmp/ecomat_gt_derive" as *u8, "knowledge/status/autonomy_meter.log" as *u8, out, 0) 45 _p("T4 permil-deriv: verdict=" as *u8); _fn(1, v4); _p(" permil=" as *u8); _fn(1, out[0]); _p(" (stale stored 5 -> evlog permil=341 -> level 2 -> 400)\n" as *u8) 46 if out[0] != 400 { fails = fails + 1 } 47 if v4 != 0 { fails = fails + 1 } 48 // T5 GATE-LIVENESS (evkind=2): stored PRODUCTION(3) with a gate evlog. GREEN -> level holds (3 -> 600). 49 // RED -> the evidence is gone -> DEMOTE to TOY(1 -> 200). Both directions proven (the demote is load-bearing). 50 ss_writefile("/tmp/ecomat_t5_green" as *u8, "x verdict=GREEN\n" as *u8, 16) 51 ss_writefile("/tmp/ecomat_t5_red" as *u8, "x verdict=RED\n" as *u8, 14) 52 let w5g: *i64 = ss_begin() 53 ec_seed_one_ev(w5g, 0, 1, 9, 3, 5, 9, 1, 2, "gd" as *u8, "b" as *u8, "n" as *u8, "/tmp/ecomat_t5_green" as *u8, "verdict=" as *u8) 54 ss_commit("/tmp/ecomat_gt_t5g" as *u8, w5g, sys_now_realtime_sec()) 55 let v5g: i64 = em_rollup_store("/tmp/ecomat_gt_t5g" as *u8, "knowledge/status/autonomy_meter.log" as *u8, out, 0) 56 _p("T5g gate-GREEN : permil=" as *u8); _fn(1, out[0]); _p(" (GREEN -> level 3 holds -> 600)\n" as *u8) 57 if out[0] != 600 { fails = fails + 1 } 58 let w5r: *i64 = ss_begin() 59 ec_seed_one_ev(w5r, 0, 1, 9, 3, 5, 9, 1, 2, "gd" as *u8, "b" as *u8, "n" as *u8, "/tmp/ecomat_t5_red" as *u8, "verdict=" as *u8) 60 ss_commit("/tmp/ecomat_gt_t5r" as *u8, w5r, sys_now_realtime_sec()) 61 let v5r: i64 = em_rollup_store("/tmp/ecomat_gt_t5r" as *u8, "knowledge/status/autonomy_meter.log" as *u8, out, 0) 62 _p("T5r gate-RED : permil=" as *u8); _fn(1, out[0]); _p(" (RED -> evidence gone -> DEMOTE to 1 -> 200)\n" as *u8) 63 if out[0] != 200 { fails = fails + 1 } 64 // T6 TRIANGULATED: two INDEPENDENT GREEN gate witnesses converge -> triangulated, 0 conflict (stored 2 -> 400). 65 ss_writefile("/tmp/ecomat_t6a" as *u8, "x verdict=GREEN\n" as *u8, 16) 66 ss_writefile("/tmp/ecomat_t6b" as *u8, "x verdict=GREEN\n" as *u8, 16) 67 let w6: *i64 = ss_begin() 68 ec_seed_two(w6, 0, 1, 9, 2, 5, 9, 1, 2, 2, "td" as *u8, "b" as *u8, "n" as *u8, "/tmp/ecomat_t6a" as *u8, "verdict=" as *u8, "/tmp/ecomat_t6b" as *u8, "verdict=" as *u8) 69 ss_commit("/tmp/ecomat_gt_t6" as *u8, w6, sys_now_realtime_sec()) 70 let v6: i64 = em_rollup_store("/tmp/ecomat_gt_t6" as *u8, "knowledge/status/autonomy_meter.log" as *u8, out, 0) 71 _p("T6 triangulated: permil=" as *u8); _fn(1, out[0]); _p(" tri=" as *u8); _fn(1, out[8]); _p(" conflict=" as *u8); _fn(1, out[9]); _p("\n" as *u8) 72 if out[8] != 1 { fails = fails + 1 } 73 if out[9] != 0 { fails = fails + 1 } 74 if out[0] != 400 { fails = fails + 1 } 75 // T7 CONFLICT (the anti-self-validation guarantee): two INDEPENDENT sources that DISAGREE must be FLAGGED, 76 // not silently trusted. src1 permil=900 -> level 5, src2 gate RED -> 1; diff=4 -> conflict; conservative min -> 200. 77 ss_writefile("/tmp/ecomat_t7a" as *u8, "permil=900\n" as *u8, 11) 78 ss_writefile("/tmp/ecomat_t7b" as *u8, "x verdict=RED\n" as *u8, 14) 79 let w7: *i64 = ss_begin() 80 ec_seed_two(w7, 0, 1, 9, 4, 5, 9, 1, 1, 2, "cd" as *u8, "b" as *u8, "n" as *u8, "/tmp/ecomat_t7a" as *u8, "permil=" as *u8, "/tmp/ecomat_t7b" as *u8, "verdict=" as *u8) 81 ss_commit("/tmp/ecomat_gt_t7" as *u8, w7, sys_now_realtime_sec()) 82 let v7: i64 = em_rollup_store("/tmp/ecomat_gt_t7" as *u8, "knowledge/status/autonomy_meter.log" as *u8, out, 0) 83 _p("T7 conflict : permil=" as *u8); _fn(1, out[0]); _p(" tri=" as *u8); _fn(1, out[8]); _p(" conflict=" as *u8); _fn(1, out[9]); _p(" (independent disagreement CAUGHT, not silently passed)\n" as *u8) 84 if out[9] != 1 { fails = fails + 1 } 85 if out[8] != 0 { fails = fails + 1 } 86 if out[0] != 200 { fails = fails + 1 } 87 if fails == 0 { _p("GATE nx_ecosystem_maturity_rollup verdict=GREEN pass=18/18 (liar-kill + permil-derive + gate-liveness + TRIANGULATION convergence/conflict)\n" as *u8); sys_exit(0); return 0 } 88 _p("GATE nx_ecosystem_maturity_rollup verdict=RED fails=" as *u8); _fn(1, fails); _p("\n" as *u8) 89 sys_exit(1) 90 return 1 91}