nx_commonsbench.nx source
↩ module page · 218 lines · 13272 B
1// nx_commonsbench.nx -- THE RULER for neighbour-network standing: does a reciprocity rule actually
2// reward the person who shares and starve the person who skims?
3//
4// Method (per feedback-match-known-good-then-improve): we do NOT invent a ruler. We take the estate's
5// EXISTING reciprocity rule -- the pairwise tolerance-ratio audit shipped in nx_mycorrhiza
6// (nx_my_audit_kind) and nx_hypha (nx_hy_reciprocity_verdict) -- and measure it against a labelled
7// population of economic archetypes with declared ground truth. The bench is CALIBRATED TO FAIL THE
8// INCUMBENT: a ruler that the current rule passes would measure nothing.
9//
10// THE STRUCTURAL CLAIM UNDER TEST:
11// AN EXTRACTOR IS BALANCED WITH EVERY COUNTERPARTY AND NET-NEGATIVE ON THE NETWORK.
12// A PAIRWISE AUDIT IS THEREFORE STRUCTURALLY BLIND TO THE CLASS.
13// The skimmer always gives each counterparty *something* fee-justifying, so every pairwise audit
14// returns BALANCED. The extraction is only visible in the network aggregate. Symmetrically, the most
15// generous member (a nurse: gives 7x what she takes) is the one a ratio rule flags as anomalous.
16// If that is true, the incumbent rule does not merely miss the predator -- it INVERTS the ordering.
17//
18// Ground truth is declared per archetype and is the thing later rules are scored against. Integer
19// only, no floats, no content read. license_tier: ORIGINAL expect_exit: 0
20import "nx_syscalls.nx"
21
22const CB_N: i64 = 10 // actors in the labelled population
23const CB_Q10: i64 = 1024 // Q10 unit (1.0x) -- matches NX_MAGIC_1024 in nx_mycorrhiza
24const CB_TOL_Q10: i64 = 2048 // pairwise tolerance = 2.0x slack, the mycorrhiza-style admit window
25const CB_RING: i64 = 7 // index of first sybil-ring member (ring occupies 7,8,9)
26const CB_RING_N: i64 = 3
27
28// ground-truth standing classes (higher = more deserving of standing)
29const CB_ADMIT_HIGH: i64 = 3
30const CB_NEUTRAL: i64 = 1
31const CB_THROTTLE: i64 = 0
32const CB_EXCLUDE: i64 = 0 - 1
33
34func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
35func cn(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 }
36func cpad(s: *u8, w: i64) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); var j: i64=n; while j<w { sys_write(1," " as *u8,1); j=j+1 } return 0 }
37
38// archetype name by index (if-chain, not a pointer table -- no cast tricks)
39func cname(i: i64) -> i64 {
40 if i==0 { cpad("JANITOR" as *u8, 14); return 0 }
41 if i==1 { cpad("NURSE" as *u8, 14); return 0 }
42 if i==2 { cpad("TEACHER" as *u8, 14); return 0 }
43 if i==3 { cpad("NEWCOMER" as *u8, 14); return 0 }
44 if i==4 { cpad("APPRENTICE" as *u8, 14); return 0 }
45 if i==5 { cpad("SKIMMER(PE)" as *u8, 14); return 0 }
46 if i==6 { cpad("HOARDER" as *u8, 14); return 0 }
47 if i==7 { cpad("SYBIL-A" as *u8, 14); return 0 }
48 if i==8 { cpad("SYBIL-B" as *u8, 14); return 0 }
49 cpad("SYBIL-C" as *u8, 14); return 0
50}
51
52// ---- THE INCUMBENT RULE (what nx_mycorrhiza / nx_hypha compute today) -------------------------
53//
54// nx_my_audit_kind compares gives vs takes FOR ONE PARTNERSHIP and flags extraction when the ratio
55// leaves the tolerance window. An actor is admitted when no counterparty audit flags them. So the
56// only input the incumbent has is the WORST pairwise ratio the actor presents to any counterparty.
57// Standing falls as that ratio departs from parity.
58func incumbent_standing(worst_pair_ratio_q10: i64) -> i64 {
59 var r: i64 = worst_pair_ratio_q10
60 if r < CB_Q10 { r = CB_Q10 }
61 var s: i64 = (CB_Q10 * 1000) / r
62 if s > 1000 { s = 1000 }
63 return s
64}
65
66func incumbent_flags(worst_pair_ratio_q10: i64) -> i64 {
67 if worst_pair_ratio_q10 > CB_TOL_Q10 { return 1 }
68 return 0
69}
70
71func main() -> i64 {
72 // ---- labelled population -------------------------------------------------------------------
73 // gave/took : total magnitude given to / taken from the network (not event counts)
74 // partners : distinct counterparties
75 // worst_pair_q10 : worst pairwise give:take ratio presented to ANY single counterparty (Q10)
76 // passed_on : of what was taken, how much was converted and passed onward (flow-through)
77 // witnessed : share of "gave" attested by a third party who is NOT the counterparty (permil)
78 // outside_partners : counterparties OUTSIDE the actor's own ring (sybil-independence)
79 // truth : declared ground-truth standing class
80 let gave: *i64 = sys_mmap(8 * CB_N) as *i64
81 let took: *i64 = sys_mmap(8 * CB_N) as *i64
82 let partners: *i64 = sys_mmap(8 * CB_N) as *i64
83 let worst: *i64 = sys_mmap(8 * CB_N) as *i64
84 let passed: *i64 = sys_mmap(8 * CB_N) as *i64
85 let witn: *i64 = sys_mmap(8 * CB_N) as *i64
86 let outside: *i64 = sys_mmap(8 * CB_N) as *i64
87 let truth: *i64 = sys_mmap(8 * CB_N) as *i64
88 let rank: *i64 = sys_mmap(8 * CB_N) as *i64 // ground-truth desert ordering, higher = more deserving
89
90 // 0 JANITOR -- works hard, shares steadily, takes modestly, everything he gives is witnessed.
91 gave[0]=900; took[0]=300; partners[0]=12; worst[0]=1400; passed[0]=280; witn[0]=950; outside[0]=12; truth[0]=CB_ADMIT_HIGH; rank[0]=90
92 // 1 NURSE -- the most generous member: gives 7x what she takes, bursty. A RATIO rule flags her.
93 // NEGATIVE CONTROL: any rule that punishes the biggest net giver is disqualified outright.
94 gave[1]=1500; took[1]=200; partners[1]=20; worst[1]=7680; passed[1]=190; witn[1]=980; outside[1]=20; truth[1]=CB_ADMIT_HIGH; rank[1]=95
95 // 2 TEACHER -- balanced, broad, well witnessed.
96 gave[2]=600; took[2]=400; partners[2]=15; worst[2]=1300; passed[2]=380; witn[2]=900; outside[2]=15; truth[2]=CB_ADMIT_HIGH; rank[2]=85
97 // 3 NEWCOMER -- arrived with nothing. Must NOT be punished (the starter-quota principle).
98 gave[3]=0; took[3]=0; partners[3]=0; worst[3]=1024; passed[3]=0; witn[3]=0; outside[3]=0; truth[3]=CB_NEUTRAL; rank[3]=50
99 // 4 APPRENTICE -- genuine net taker because he is LEARNING. Throttled, never excluded.
100 // NEGATIVE CONTROL: a rule that cannot tell an apprentice from a skimmer will starve the young.
101 gave[4]=50; took[4]=400; partners[4]=3; worst[4]=8192; passed[4]=40; witn[4]=800; outside[4]=3; truth[4]=CB_THROTTLE; rank[4]=40
102 // 5 SKIMMER (the rent-extraction / private-equity actor) -- THE CASE THAT MATTERS.
103 // Balanced with EVERY counterparty individually (always renders a fee-justifying service), huge
104 // reach, net-negative on the network, converts almost nothing onward, and almost nothing he
105 // "gave" is witnessed by anyone but the counterparty he billed.
106 gave[5]=1000; took[5]=1400; partners[5]=40; worst[5]=1100; passed[5]=60; witn[5]=120; outside[5]=40; truth[5]=CB_EXCLUDE; rank[5]=5
107 // 6 HOARDER -- gave once, long ago; sits on the balance; no throughput.
108 gave[6]=800; took[6]=100; partners[6]=2; worst[6]=1500; passed[6]=5; witn[6]=700; outside[6]=2; truth[6]=CB_THROTTLE; rank[6]=20
109 // 7,8,9 SYBIL RING -- three identities trading with each other to MANUFACTURE perfect reciprocity.
110 // Pairwise-flawless by construction. Nothing witnessed outside the ring; no outside partners.
111 gave[7]=2000; took[7]=2000; partners[7]=2; worst[7]=1024; passed[7]=1990; witn[7]=0; outside[7]=0; truth[7]=CB_EXCLUDE; rank[7]=1
112 gave[8]=2000; took[8]=2000; partners[8]=2; worst[8]=1024; passed[8]=1990; witn[8]=0; outside[8]=0; truth[8]=CB_EXCLUDE; rank[8]=1
113 gave[9]=2000; took[9]=2000; partners[9]=2; worst[9]=1024; passed[9]=1990; witn[9]=0; outside[9]=0; truth[9]=CB_EXCLUDE; rank[9]=1
114
115 cw("=== nx_commonsbench -- THE RULER for neighbour-network standing ===\n" as *u8)
116 cw("incumbent rule under test: PAIRWISE tolerance-ratio audit (nx_mycorrhiza nx_my_audit_kind /\n" as *u8)
117 cw("nx_hypha nx_hy_reciprocity_verdict). Ground truth declared per archetype.\n\n" as *u8)
118 cw("actor gave took ptnr worst standing flagged truth-rank\n" as *u8)
119
120 let score: *i64 = sys_mmap(8 * CB_N) as *i64
121 let flag: *i64 = sys_mmap(8 * CB_N) as *i64
122 var i: i64 = 0
123 while i < CB_N {
124 score[i] = incumbent_standing(worst[i])
125 flag[i] = incumbent_flags(worst[i])
126 cname(i)
127 cn(gave[i]); cw(" " as *u8); cn(took[i]); cw(" " as *u8); cn(partners[i]); cw(" " as *u8)
128 cn(worst[i]); cw(" " as *u8); cn(score[i]); cw(" " as *u8)
129 if flag[i]==1 { cw("FLAG " as *u8) } else { cw("ok " as *u8) }
130 cw(" " as *u8); cn(rank[i]); cw("\n" as *u8)
131 i = i + 1
132 }
133 cw("\n" as *u8)
134
135 // ---- T1: ordering agreement with ground truth ----------------------------------------------
136 // For every ordered pair the truth ranks strictly, does the incumbent agree?
137 var agree: i64 = 0
138 var pairs: i64 = 0
139 var a: i64 = 0
140 while a < CB_N {
141 var b: i64 = 0
142 while b < CB_N {
143 if rank[a] > rank[b] {
144 pairs = pairs + 1
145 if score[a] > score[b] { agree = agree + 1 }
146 }
147 b = b + 1
148 }
149 a = a + 1
150 }
151 var agree_permil: i64 = 0
152 if pairs > 0 { agree_permil = (agree * 1000) / pairs }
153 cw("T1 ordering agreement with ground truth = " as *u8); cn(agree_permil)
154 cw(" permil (" as *u8); cn(agree); cw("/" as *u8); cn(pairs); cw(" ordered pairs)\n" as *u8)
155
156 // ---- T2: THE SKIMMER TOOTH -- must rank strictly below the janitor -------------------------
157 var t2: i64 = 0
158 if score[0] > score[5] { t2 = 1 }
159 cw("T2 janitor outranks skimmer : " as *u8)
160 if t2==1 { cw("PASS" as *u8) } else { cw("FAIL <-- the skimmer is invisible to a pairwise audit" as *u8) }
161 cw(" (janitor=" as *u8); cn(score[0]); cw(" skimmer=" as *u8); cn(score[5]); cw(")\n" as *u8)
162
163 // ---- T3: THE GENEROSITY TOOTH -- the biggest net giver must not be flagged -----------------
164 var t3: i64 = 0
165 if flag[1]==0 { t3 = 1 }
166 cw("T3 nurse (7x net giver) not flagged : " as *u8)
167 if t3==1 { cw("PASS" as *u8) } else { cw("FAIL <-- a ratio rule punishes the most generous member" as *u8) }
168 cw("\n" as *u8)
169
170 // ---- T4: THE APPRENTICE TOOTH -- a learner must be throttled, never excluded ----------------
171 var t4: i64 = 0
172 if score[4] > score[5] { t4 = 1 }
173 cw("T4 apprentice outranks skimmer : " as *u8)
174 if t4==1 { cw("PASS" as *u8) } else { cw("FAIL <-- the young are starved before the predator is" as *u8) }
175 cw("\n" as *u8)
176
177 // ---- T5: THE SYBIL BOUND -- ring total standing must not grow with ring size ----------------
178 // A ring of N identities trading internally manufactures perfect pairwise reciprocity for free.
179 // If total standing scales with N, the attack is unbounded: mint more identities, mint more claim.
180 var ring_total: i64 = 0
181 var r: i64 = 0
182 while r < CB_RING_N { ring_total = ring_total + score[CB_RING + r]; r = r + 1 }
183 let honest_total: i64 = score[0] + score[1] + score[2]
184 var per_identity: i64 = 0
185 if CB_RING_N > 0 { per_identity = ring_total / CB_RING_N }
186 var t5: i64 = 0
187 if ring_total < honest_total { t5 = 1 }
188 cw("T5 sybil ring total < honest total : " as *u8)
189 if t5==1 { cw("PASS" as *u8) } else { cw("FAIL <-- standing scales with identity count, so the ring is unbounded" as *u8) }
190 cw(" (ring=" as *u8); cn(ring_total); cw(" honest=" as *u8); cn(honest_total)
191 cw(" per-identity=" as *u8); cn(per_identity); cw(")\n" as *u8)
192
193 // ---- T6: THE NEWCOMER TOOTH -- arriving with nothing must not be punished ------------------
194 var t6: i64 = 0
195 if flag[3]==0 { t6 = 1 }
196 cw("T6 newcomer not punished for arriving : " as *u8)
197 if t6==1 { cw("PASS" as *u8) } else { cw("FAIL" as *u8) }
198 cw("\n\n" as *u8)
199
200 var teeth: i64 = t2 + t3 + t4 + t5 + t6
201 cw("teeth passed by the INCUMBENT rule = " as *u8); cn(teeth); cw("/5 ordering=" as *u8)
202 cn(agree_permil); cw(" permil\n" as *u8)
203
204 // ---- CALIBRATION GATE ----------------------------------------------------------------------
205 // This bench is only worth running if it can KILL the incumbent. If the pairwise rule passes all
206 // five teeth, the population is too easy and the ruler is toothless -- that is a RED on the
207 // BENCH, not a green on the rule. (feedback: critics CALIBRATED TO FAIL THE TOY.)
208 cw("\n--- calibration --- a ruler the incumbent passes measures nothing.\n" as *u8)
209 if teeth >= 5 {
210 cw("COMMONSBENCH verdict=RED (TOOTHLESS: the incumbent passed every tooth -- harden the population)\n" as *u8)
211 sys_exit(1); return 1
212 }
213 cw("COMMONSBENCH verdict=GREEN (ruler has teeth: the incumbent pairwise rule FAILS " as *u8)
214 cn(5 - teeth); cw(" of 5 teeth)\n" as *u8)
215 cw("BASELINE BANKED: pairwise-ratio standing, teeth=" as *u8); cn(teeth)
216 cw("/5, ordering=" as *u8); cn(agree_permil); cw(" permil. Any replacement rule must beat BOTH.\n" as *u8)
217 sys_exit(0); return 0
218}