code wiki / _hdl_build / nx_ad_bill_gate.nx
nx_ad_bill_gate.nx source
↩ module page · 71 lines · 3828 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"
14
15const ABG_LOG: *u8 = "knowledge/status/ad_bill.log"
16
17func 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 }
18func 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 }
19
20func abg_emit(fd: i64, pf: i64, eb: i64, lperf: i64, lexc: i64, lceil: i64, unmeas: i64, missref: i64, ok: i64) -> i64 {
21 ab_w(fd, "BILLGATE authored=organ source=store live_reach_fee=" as *u8); ab_wn(fd, pf)
22 ab_w(fd, " live_reach_bonus=" as *u8); ab_wn(fd, eb)
23 ab_w(fd, " live_perform=" as *u8); ab_wn(fd, lperf)
24 ab_w(fd, " live_exceed=" as *u8); ab_wn(fd, lexc)
25 ab_w(fd, " live_ceiling=" as *u8); ab_wn(fd, lceil)
26 ab_w(fd, " unmeasurable=" as *u8); ab_wn(fd, unmeas)
27 ab_w(fd, " missing_price_charge=" as *u8); ab_wn(fd, missref)
28 ab_w(fd, " (-1=REFUSED/no-charge)" as *u8)
29 if ok == 1 { ab_w(fd, " verdict=GREEN\n" as *u8) } else { ab_w(fd, " verdict=RED\n" as *u8) }
30 return 0
31}
32
33func main() -> i64 {
34 // boundary controls with numeric prices: perform_fee=50, exceed_bonus=20.
35 let b_under: i64 = ab_charge(0, 50, 20) // 0
36 let b_perform: i64 = ab_charge(1, 50, 20) // 50
37 let b_exceed: i64 = ab_charge(2, 50, 20) // 70
38 let b_unmeas: i64 = ab_charge(0 - 1, 50, 20) // -1 REFUSED (no meter verdict)
39
40 // LIVE prices from the store (reach): fee=50, exceed_bonus=25 -> ceiling 75.
41 let pf: i64 = ab_perform_fee_of("adpricing:reach" as *u8) // 50
42 let eb: i64 = ab_exceed_bonus_of("adpricing:reach" as *u8) // 25
43 let l_perform: i64 = ab_charge(1, pf, eb) // 50
44 let l_exceed: i64 = ab_charge(2, pf, eb) // 75
45 let l_ceiling: i64 = ab_period_ceiling(pf, eb) // 75
46
47 // STILL REFUSES honestly: a goal with NO price -> REFUSED.
48 let miss_pf: i64 = ab_perform_fee_of("adpricing:nonexistent" as *u8) // -1
49 let miss_eb: i64 = ab_exceed_bonus_of("adpricing:nonexistent" as *u8) // -1
50 let miss_charge: i64 = ab_charge(1, miss_pf, miss_eb) // -1 REFUSED
51
52 var ok: i64 = 1
53 if b_under != 0 { ok = 0 }
54 if b_perform != 50 { ok = 0 }
55 if b_exceed != 70 { ok = 0 }
56 if b_unmeas != 0 - 1 { ok = 0 }
57 if pf != 50 { ok = 0 }
58 if eb != 25 { ok = 0 }
59 if l_perform != 50 { ok = 0 }
60 if l_exceed != 75 { ok = 0 }
61 if l_ceiling != 75 { ok = 0 }
62 if miss_pf != 0 - 1 { ok = 0 }
63 if miss_charge != 0 - 1 { ok = 0 }
64
65 abg_emit(1, pf, eb, l_perform, l_exceed, l_ceiling, b_unmeas, miss_charge, ok)
66 let lf: i64 = sys_openat_append(ABG_LOG, 420)
67 if lf >= 0 { abg_emit(lf, pf, eb, l_perform, l_exceed, l_ceiling, b_unmeas, miss_charge, ok); sys_close(lf) }
68
69 if ok == 1 { return 0 }
70 return 1
71}