code wiki / _hdl_build / nx_ad_reach_gate.nx
nx_ad_reach_gate.nx source
↩ module page · 79 lines · 4460 B
1// nx_ad_reach_gate.nx -- GATE (runnable) for HONEST BILLABLE REACH (nx_ad_reach). Proves the charge
2// basis is ONLY genuinely-seen humans, on a baked funnel + the store-resident bot rules:
3// funnel : served=95 -> viewable=70 -> billable=50 (bot, unseen, under-dwell all stripped)
4// liar-kill: a VIEWABLE BOT is NOT billable; an UNSEEN human is NOT billable; a seen human IS
5// honesty: billable < viewable < served (we never charge for the gap = "no fake impressions")
6// Evidence -> knowledge/status/ad_reach.log (REACHGATE ... verdict=GREEN). license_tier: ORIGINAL
7import "nx_ad_reach.nx"
8import "nx_ad_store.nx"
9import "nx_syscalls.nx"
10import "nx_gate_verdict.nx"
11
12const RG_LOG: *u8 = "knowledge/status/ad_reach.log"
13
14func rg_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 }
15func rg_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 }
16
17func main() -> i64 {
18 let rules: *i64 = sys_mmap(8 * 64) as *i64
19 let nrules: i64 = ads_botrules(rules, 32)
20
21 // funnel corpus [viewed, dwell_ms, ua, src, js, n] (js=1 executed=human, js=0 raw=bot per BR-JS-RAW)
22 let ev: *i64 = sys_mmap(8 * 6 * 4) as *i64
23 ev[0]=1; ev[1]=1500; ev[2]=0; ev[3]=0; ev[4]=1; ev[5]=50 // seen + human -> billable 50
24 ev[6]=1; ev[7]=1500; ev[8]=1; ev[9]=0; ev[10]=1; ev[11]=20 // seen + BOT (ua=1) -> viewable, NOT billable
25 ev[12]=0; ev[13]=5000; ev[14]=0; ev[15]=0; ev[16]=1; ev[17]=15 // unseen + human -> NOT viewable
26 ev[18]=1; ev[19]=500; ev[20]=0; ev[21]=0; ev[22]=1; ev[23]=10 // under-dwell + human -> NOT viewable
27 let osv: *i64 = sys_mmap(8) as *i64
28 let ovw: *i64 = sys_mmap(8) as *i64
29 let obill: *i64 = sys_mmap(8) as *i64
30 ar_tally(ev, 4, AV_MIN_DISPLAY, rules, nrules, osv, ovw, obill)
31 let served: i64 = osv[0] // 95
32 let viewable: i64 = ovw[0] // 70
33 let billable: i64 = obill[0] // 50
34
35 // liar-kill on the single-impression predicate
36 let bot_seen: i64 = ar_billable_one(1, 1500, 1, 0, 1, AV_MIN_DISPLAY, rules, nrules) // viewable bot -> 0
37 let human_unseen: i64 = ar_billable_one(0, 5000, 0, 0, 1, AV_MIN_DISPLAY, rules, nrules) // unseen human -> 0
38 let human_seen: i64 = ar_billable_one(1, 1500, 0, 0, 1, AV_MIN_DISPLAY, rules, nrules) // seen human -> 1
39
40 var ok: i64 = 1
41 if nrules < 1 { ok = 0 }
42 if served != 95 { ok = 0 }
43 if viewable != 70 { ok = 0 }
44 if billable != 50 { ok = 0 }
45 if billable >= viewable { ok = 0 } // bot stripped from billing
46 if viewable >= served { ok = 0 } // unseen stripped from viewable
47 if bot_seen != 0 { ok = 0 }
48 if human_unseen != 0 { ok = 0 }
49 if human_seen != 1 { ok = 0 }
50
51 rg_w(1, "REACHGATE authored=organ source=store served=" as *u8); rg_wn(1, served)
52 rg_w(1, " viewable=" as *u8); rg_wn(1, viewable)
53 rg_w(1, " billable=" as *u8); rg_wn(1, billable)
54 rg_w(1, " (charged_only_for_seen_humans) bot_seen_billable=" as *u8); rg_wn(1, bot_seen)
55 rg_w(1, " unseen_human_billable=" as *u8); rg_wn(1, human_unseen)
56 rg_w(1, " seen_human_billable=" as *u8); rg_wn(1, human_seen)
57 if ok == 1 { rg_w(1, " verdict=GREEN\n" as *u8) }
58 if ok != 1 { rg_w(1, " verdict=RED\n" as *u8) }
59
60 let lf: i64 = sys_openat_append(RG_LOG, 420)
61 if lf >= 0 {
62 rg_w(lf, "REACHGATE served=" as *u8); rg_wn(lf, served)
63 rg_w(lf, " viewable=" as *u8); rg_wn(lf, viewable)
64 rg_w(lf, " billable=" as *u8); rg_wn(lf, billable)
65 if ok == 1 { rg_w(lf, " verdict=GREEN\n" as *u8) }
66 if ok != 1 { rg_w(lf, " verdict=RED\n" as *u8) }
67 sys_close(lf)
68 }
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-REACH-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}