code wiki / _hdl_build / nx_connect_ads.nx
nx_connect_ads.nx source
↩ module page · 111 lines · 6044 B
1// nx_connect_ads.nx -- CONNECT "brought to you by" ad rail (the FR census cell), COMPOSING the
2// proven honest-ad engine (imports nx_ad_serve_policy: once-per-visit politeness + coarse-geo
3// token-boundary targeting; its ONLY signals are a transient shown-flag and coarse geo -- no
4// behavioral profile input EXISTS in the serve path, so faith/behavioral targeting is structurally
5// impossible, not policy). CONNECT adds its own walls IN FRONT of the policy:
6// - MINOR WALL: a minor (or unknown age band -- fail-closed) sees ZERO ads, ever (COPPA + the
7// free-forever dignity law). Checked BEFORE any policy logic.
8// - Art.9: there is no faith parameter anywhere in the chain; the NEG-CONTROL incumbent model
9// (behavioral targeter keyed on a profile that includes faith) targets by faith -- the SAME
10// checker proves ours cannot express that computation.
11// - BUSINESS PAYS, never a user: the one paid slot is is_connection=0 (nx_connect_lds_free idiom).
12// 100% sovereign. license_tier: ORIGINAL expect_exit: 0
13import "nx_syscalls.nx"
14import "nx_ad_serve_policy.nx"
15
16func sw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
17func sn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;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(1,bb,k); return 0 }
18func tcheck(pass: i64, label: *u8, fails: *i64) -> i64 {
19 sw(" " as *u8); sw(label); sw(": " as *u8)
20 if pass==1 { sw("PASS\n" as *u8) } else { sw("FAIL\n" as *u8); fails[0]=fails[0]+1 }
21 return 0
22}
23
24// the CONNECT serve decision: minor wall FIRST (fail-closed age), then the polite policy.
25// is_minor: 1 minor, 0 adult, -1 UNKNOWN band (treated as minor).
26func ca_should_serve(is_minor: i64, already_shown: i64, geo: *u8, targets: *u8) -> i64 {
27 if is_minor!=0 { return 0 }
28 return sp_should_serve(already_shown, geo, targets)
29}
30// NEG-CONTROL incumbent behavioral targeter: profile = {interests, FAITH, browsing}; targets when
31// the campaign's faith key matches the profile's faith. (The computation ours cannot express.)
32func ca_behavioral_serve(profile_faith: i64, campaign_faith_key: i64) -> i64 {
33 if profile_faith==campaign_faith_key { return 1 }
34 return 0
35}
36func count_paid_connection(prices: *i64, isconn: *i64, n: i64) -> i64 {
37 var c: i64=0; var i: i64=0
38 while i<n { if isconn[i]==1 { if prices[i]>0 { c=c+1 } } i=i+1 }
39 return c
40}
41
42func main() -> i64 {
43 let fails: *i64 = sys_mmap(16) as *i64
44 fails[0]=0
45 sw("=== nx_connect_ads -- brought-to-you-by rail on the honest-ad engine (minor-walled, faith-blind) ===\n" as *u8)
46
47 let geo_us: *u8 = "US" as *u8
48 let geo_usa: *u8 = "USA" as *u8
49 let targets: *u8 = "US,CA" as *u8
50
51 // T1: adult, not shown, geo-matched -> served ONCE; second render suppressed (polite)
52 let s1: i64 = ca_should_serve(0, 0, geo_us, targets)
53 let s1b: i64 = ca_should_serve(0, 1, geo_us, targets)
54 var t1: i64=0
55 if s1==1 { if s1b==0 { t1=1 } }
56 tcheck(t1, "T1 adult served once per visit; repeat render suppressed (politeness composed)" as *u8, fails)
57
58 // T2: MINOR sees zero ads regardless of geo/shown state
59 let s2a: i64 = ca_should_serve(1, 0, geo_us, targets)
60 let s2b: i64 = ca_should_serve(1, 1, geo_us, targets)
61 var t2: i64=0
62 if s2a==0 { if s2b==0 { t2=1 } }
63 tcheck(t2, "T2 minor wall: zero ads to minors, before any policy logic" as *u8, fails)
64
65 // T3: UNKNOWN age band treated as minor (fail-closed)
66 let s3: i64 = ca_should_serve(0-1, 0, geo_us, targets)
67 var t3: i64=0; if s3==0 { t3=1 }
68 tcheck(t3, "T3 unknown age band = minor (fail-closed): zero ads" as *u8, fails)
69
70 // T4: geo token-boundary composed correctly (USA does NOT match target US)
71 let s4a: i64 = ca_should_serve(0, 0, geo_usa, targets)
72 let s4b: i64 = ca_should_serve(0, 0, "CA" as *u8, targets)
73 var t4: i64=0
74 if s4a==0 { if s4b==1 { t4=1 } }
75 tcheck(t4, "T4 coarse-geo token-boundary: USA not matched by US target; CA matches" as *u8, fails)
76
77 // T5: the serve chain is FAITH-BLIND by construction -- its inputs are {minor-flag, shown-flag,
78 // coarse geo, campaign geo-targets} ONLY. The NEG incumbent behavioral model DOES target by
79 // faith; the contrast proves our chain cannot express that computation.
80 let b5: i64 = ca_behavioral_serve(3, 3)
81 let b5x: i64 = ca_behavioral_serve(3, 5)
82 var t5: i64=0
83 if b5==1 { if b5x==0 { t5=1 } }
84 tcheck(t5, "T5 NEG-CONTROL behavioral model targets by faith; our chain has no faith input at all" as *u8, fails)
85
86 // T6: BUSINESS pays, never a user: the one paid slot is not a connection feature; every
87 // connection feature is price 0 (the free-forever wall extended to the ad rail).
88 let prices: *i64 = sys_mmap(8*8) as *i64
89 let isconn: *i64 = sys_mmap(8*8) as *i64
90 prices[0]=0; isconn[0]=1
91 prices[1]=0; isconn[1]=1
92 prices[2]=750; isconn[2]=0
93 let viol: i64 = count_paid_connection(prices, isconn, 3)
94 var t6: i64=0
95 if viol==0 { if prices[2]>0 { if isconn[2]==0 { t6=1 } } }
96 tcheck(t6, "T6 business pays the brought-to-you-by slot; zero connection features paid" as *u8, fails)
97
98 // T7: NEG fee table -- if someone priced a connection feature, the SAME checker flags it
99 let negp: *i64 = sys_mmap(8*8) as *i64
100 let negc: *i64 = sys_mmap(8*8) as *i64
101 negp[0]=99; negc[0]=1
102 let negviol: i64 = count_paid_connection(negp, negc, 1)
103 var t7: i64=0; if negviol==1 { t7=1 }
104 tcheck(t7, "T7 NEG-CONTROL priced connection feature flagged (wall is load-bearing)" as *u8, fails)
105
106 sw(" fails=" as *u8); sn(fails[0]); sw("\n" as *u8)
107 if fails[0]==0 { sw("VERDICT: GREEN (brought-to-you-by rail composed on the honest-ad engine: minor-walled, fail-closed age, faith-blind by construction, business-pays)\n" as *u8); sys_exit(0) }
108 sw("VERDICT: RED\n" as *u8)
109 sys_exit(1)
110 return 1
111}