code wiki / _hdl_build / nx_ecomat_domledger_gate.nx

nx_ecomat_domledger_gate.nx source

↩ module page · 56 lines · 2878 B

1// nx_ecomat_domledger_gate.nx -- proves the per-domain walk RECONCILES with the aggregate rollup. 2// 3// The per-domain ledger only earns trust if it adds up to the number the rollup already publishes. 4// T3/T4/T5 walk the same store by two separate code paths and demand the domain count, sum_cur and 5// sum_bar agree TO THE LEVEL. This is a reconciliation, not an independent measurement -- both paths 6// share the record codec and em_domain_level -- but it is exactly the drift that would otherwise 7// ship silently, because a per-domain file that quietly disagrees with the headline is worse than 8// no per-domain file at all: it makes every future attribution wrong with a receipt. 9// license_tier: ORIGINAL No hw writes (Rule 26). 10import "nx_ecomat_domledger_lib.nx" 11import "nx_gate_verdict.nx" 12 13func dg_eq(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 } 14 15func main(argc: i64, argv: *i64) -> i64 { 16 let ctr: *i64 = gv_ctr() 17 gv_head("nx_ecomat_domledger -- per-domain rows reconcile with the aggregate rollup" as *u8) 18 19 let sums: *i64 = sys_mmap(EDL_SUMS * 8) as *i64 20 let n: i64 = edl_walk(ECOMAT_STORE, 0 - 1, 0, sums) 21 22 var t1: i64 = 0 23 if n >= 0 { t1 = 1 } 24 gv_check("T1 the ecomat store opens (-1 would mean unopenable, not empty)" as *u8, t1, ctr) 25 if n < 0 { 26 let bad: i64 = gv_verdict("ECOMAT-DOMLEDGER" as *u8, ctr, "store unopenable" as *u8) 27 sys_exit(bad) 28 return bad 29 } 30 31 var t2: i64 = 0 32 if n > 0 { t2 = 1 } 33 gv_check("T2 at least one domain is present in the store" as *u8, t2, ctr) 34 35 let out: *i64 = sys_mmap(256) as *i64 36 em_rollup_store(ECOMAT_STORE, "knowledge/status/autonomy_meter.log" as *u8, out, 0) 37 38 gv_check("T3 RECONCILE domain count matches the aggregate rollup" as *u8, dg_eq(n, out[2]), ctr) 39 gv_check("T4 RECONCILE sum_cur matches the aggregate rollup to the level" as *u8, dg_eq(sums[0], out[6]), ctr) 40 gv_check("T5 RECONCILE sum_bar matches the aggregate rollup to the level" as *u8, dg_eq(sums[1], out[7]), ctr) 41 42 gv_check("T6 a dry-run walk (fd<0) writes nothing and still reconciles" as *u8, dg_eq(edl_end(0 - 1, 0, n, sums), 0), ctr) 43 44 var t7: i64 = 0 45 if sums[1] >= sums[0] { t7 = 1 } 46 gv_check("T7 every domain's bar is at or above its current level (no domain past its own bar)" as *u8, t7, ctr) 47 48 _p("\n-- PER-DOMAIN WALK --\n" as *u8) 49 _p(" domains " as *u8); _fn(1, n); _p(" (rollup says " as *u8); _fn(1, out[2]); _p(")\n" as *u8) 50 _p(" sum_cur " as *u8); _fn(1, sums[0]); _p(" (rollup says " as *u8); _fn(1, out[6]); _p(")\n" as *u8) 51 _p(" sum_bar " as *u8); _fn(1, sums[1]); _p(" (rollup says " as *u8); _fn(1, out[7]); _p(")\n\n" as *u8) 52 53 let rc: i64 = gv_verdict("ECOMAT-DOMLEDGER" as *u8, ctr, "per-domain attribution reconciles with the published headline" as *u8) 54 sys_exit(rc) 55 return rc 56}