code wiki / _hdl_build / nx_ad_bill_gate.nx
nx_ad_bill_gate.nx source
↩ module page · 79 lines · 4361 B
1// nx_ad_bill_gate.nx -- GATE (runnable) for ADS-008 the billing FSM. Proves on baked controls +
2// the LIVE store prices (operator go-live 2026-06-13) that billing is an honest function of the
3// meter verdict + real figures:
4// boundaries (numeric) : UNDER->$0, PERFORM->fee, EXCEED->fee+bonus, ceiling=fee+bonus, UNMEASURABLE->REFUSED
5// LIVE off the store : reach fee=50 bonus=25 -> PERFORM=50, EXCEED=75, ceiling=75 (hard max)
6// STILL REFUSES honestly : a goal with NO price (adpricing:nonexistent) -> REFUSED
7// Cannot false-green: the live + refusal controls read the real store; a missing/wrong figure breaks them.
8//
9// Evidence -> knowledge/status/ad_bill.log (BILLGATE authored=organ ... verdict=GREEN).
10// license_tier: ORIGINAL
11import "nx_ad_bill.nx"
12import "nx_ad_store.nx"
13import "nx_syscalls.nx"
14import "nx_gate_verdict.nx"
15
16const ABG_LOG: *u8 = "knowledge/status/ad_bill.log"
17
18func ab_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 }
19func ab_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 }
20
21func abg_emit(fd: i64, pf: i64, eb: i64, lperf: i64, lexc: i64, lceil: i64, unmeas: i64, missref: i64, ok: i64) -> i64 {
22 ab_w(fd, "BILLGATE authored=organ source=store live_reach_fee=" as *u8); ab_wn(fd, pf)
23 ab_w(fd, " live_reach_bonus=" as *u8); ab_wn(fd, eb)
24 ab_w(fd, " live_perform=" as *u8); ab_wn(fd, lperf)
25 ab_w(fd, " live_exceed=" as *u8); ab_wn(fd, lexc)
26 ab_w(fd, " live_ceiling=" as *u8); ab_wn(fd, lceil)
27 ab_w(fd, " unmeasurable=" as *u8); ab_wn(fd, unmeas)
28 ab_w(fd, " missing_price_charge=" as *u8); ab_wn(fd, missref)
29 ab_w(fd, " (-1=REFUSED/no-charge)" as *u8)
30 if ok == 1 { ab_w(fd, " verdict=GREEN\n" as *u8) } else { ab_w(fd, " verdict=RED\n" as *u8) }
31 return 0
32}
33
34func main() -> i64 {
35 // boundary controls with numeric prices: perform_fee=50, exceed_bonus=20.
36 let b_under: i64 = ab_charge(0, 50, 20) // 0
37 let b_perform: i64 = ab_charge(1, 50, 20) // 50
38 let b_exceed: i64 = ab_charge(2, 50, 20) // 70
39 let b_unmeas: i64 = ab_charge(0 - 1, 50, 20) // -1 REFUSED (no meter verdict)
40
41 // LIVE prices from the store (reach): fee=50, exceed_bonus=25 -> ceiling 75.
42 let pf: i64 = ab_perform_fee_of("adpricing:reach" as *u8) // 50
43 let eb: i64 = ab_exceed_bonus_of("adpricing:reach" as *u8) // 25
44 let l_perform: i64 = ab_charge(1, pf, eb) // 50
45 let l_exceed: i64 = ab_charge(2, pf, eb) // 75
46 let l_ceiling: i64 = ab_period_ceiling(pf, eb) // 75
47
48 // STILL REFUSES honestly: a goal with NO price -> REFUSED.
49 let miss_pf: i64 = ab_perform_fee_of("adpricing:nonexistent" as *u8) // -1
50 let miss_eb: i64 = ab_exceed_bonus_of("adpricing:nonexistent" as *u8) // -1
51 let miss_charge: i64 = ab_charge(1, miss_pf, miss_eb) // -1 REFUSED
52
53 var ok: i64 = 1
54 if b_under != 0 { ok = 0 }
55 if b_perform != 50 { ok = 0 }
56 if b_exceed != 70 { ok = 0 }
57 if b_unmeas != 0 - 1 { ok = 0 }
58 if pf != 50 { ok = 0 }
59 if eb != 25 { ok = 0 }
60 if l_perform != 50 { ok = 0 }
61 if l_exceed != 75 { ok = 0 }
62 if l_ceiling != 75 { ok = 0 }
63 if miss_pf != 0 - 1 { ok = 0 }
64 if miss_charge != 0 - 1 { ok = 0 }
65
66 abg_emit(1, pf, eb, l_perform, l_exceed, l_ceiling, b_unmeas, miss_charge, ok)
67 let lf: i64 = sys_openat_append(ABG_LOG, 420)
68 if lf >= 0 { abg_emit(lf, pf, eb, l_perform, l_exceed, l_ceiling, b_unmeas, miss_charge, ok); sys_close(lf) }
69
70 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
71 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
72 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
73 let ctr__dry: *i64 = gv_ctr()
74 ctr__dry[0] = ok
75 ctr__dry[1] = 1
76 let rc__dry: i64 = gv_verdict("AD-BILL-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
77 sys_exit(rc__dry)
78 return rc__dry
79}