code wiki / _hdl_build / nx_ad_reach_gate.nx

nx_ad_reach_gate.nx source

↩ module page · 71 lines · 3926 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" 10 11const RG_LOG: *u8 = "knowledge/status/ad_reach.log" 12 13func 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 } 14func 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 } 15 16func main() -> i64 { 17 let rules: *i64 = sys_mmap(8 * 64) as *i64 18 let nrules: i64 = ads_botrules(rules, 32) 19 20 // funnel corpus [viewed, dwell_ms, ua, src, js, n] (js=1 executed=human, js=0 raw=bot per BR-JS-RAW) 21 let ev: *i64 = sys_mmap(8 * 6 * 4) as *i64 22 ev[0]=1; ev[1]=1500; ev[2]=0; ev[3]=0; ev[4]=1; ev[5]=50 // seen + human -> billable 50 23 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 24 ev[12]=0; ev[13]=5000; ev[14]=0; ev[15]=0; ev[16]=1; ev[17]=15 // unseen + human -> NOT viewable 25 ev[18]=1; ev[19]=500; ev[20]=0; ev[21]=0; ev[22]=1; ev[23]=10 // under-dwell + human -> NOT viewable 26 let osv: *i64 = sys_mmap(8) as *i64 27 let ovw: *i64 = sys_mmap(8) as *i64 28 let obill: *i64 = sys_mmap(8) as *i64 29 ar_tally(ev, 4, AV_MIN_DISPLAY, rules, nrules, osv, ovw, obill) 30 let served: i64 = osv[0] // 95 31 let viewable: i64 = ovw[0] // 70 32 let billable: i64 = obill[0] // 50 33 34 // liar-kill on the single-impression predicate 35 let bot_seen: i64 = ar_billable_one(1, 1500, 1, 0, 1, AV_MIN_DISPLAY, rules, nrules) // viewable bot -> 0 36 let human_unseen: i64 = ar_billable_one(0, 5000, 0, 0, 1, AV_MIN_DISPLAY, rules, nrules) // unseen human -> 0 37 let human_seen: i64 = ar_billable_one(1, 1500, 0, 0, 1, AV_MIN_DISPLAY, rules, nrules) // seen human -> 1 38 39 var ok: i64 = 1 40 if nrules < 1 { ok = 0 } 41 if served != 95 { ok = 0 } 42 if viewable != 70 { ok = 0 } 43 if billable != 50 { ok = 0 } 44 if billable >= viewable { ok = 0 } // bot stripped from billing 45 if viewable >= served { ok = 0 } // unseen stripped from viewable 46 if bot_seen != 0 { ok = 0 } 47 if human_unseen != 0 { ok = 0 } 48 if human_seen != 1 { ok = 0 } 49 50 rg_w(1, "REACHGATE authored=organ source=store served=" as *u8); rg_wn(1, served) 51 rg_w(1, " viewable=" as *u8); rg_wn(1, viewable) 52 rg_w(1, " billable=" as *u8); rg_wn(1, billable) 53 rg_w(1, " (charged_only_for_seen_humans) bot_seen_billable=" as *u8); rg_wn(1, bot_seen) 54 rg_w(1, " unseen_human_billable=" as *u8); rg_wn(1, human_unseen) 55 rg_w(1, " seen_human_billable=" as *u8); rg_wn(1, human_seen) 56 if ok == 1 { rg_w(1, " verdict=GREEN\n" as *u8) } 57 if ok != 1 { rg_w(1, " verdict=RED\n" as *u8) } 58 59 let lf: i64 = sys_openat_append(RG_LOG, 420) 60 if lf >= 0 { 61 rg_w(lf, "REACHGATE served=" as *u8); rg_wn(lf, served) 62 rg_w(lf, " viewable=" as *u8); rg_wn(lf, viewable) 63 rg_w(lf, " billable=" as *u8); rg_wn(lf, billable) 64 if ok == 1 { rg_w(lf, " verdict=GREEN\n" as *u8) } 65 if ok != 1 { rg_w(lf, " verdict=RED\n" as *u8) } 66 sys_close(lf) 67 } 68 69 if ok == 1 { return 0 } 70 return 1 71}