nx_commons_units_gate.nx source
↩ module page · 92 lines · 4905 B
1// nx_commons_units_gate.nx -- proves, against the REAL shipped nx_hypha, that a reciprocity floor
2// denominated in EVENT COUNTS cannot see magnitude, and that the units-based verdict can.
3//
4// Calls the real organs, never a copy: a hand-copied differential probe is evidence only if proven
5// character-identical, and this estate has already paid four rounds for that lesson.
6//
7// THE ATTACK BEING MEASURED: make your giving granular and your taking bulky. The skimmer renders
8// many tiny fee-justifying services and extracts in a few large events. Under a COUNT floor the
9// books look 50/50 and pass a 30% threshold with room to spare. Under a UNITS floor the same peer
10// is a 1:1,000,000 free-rider.
11//
12// T2 is the NEGATIVE CONTROL and it is the test that matters most: the units verdict must ACCEPT a
13// genuinely balanced peer. A rule that rejects everyone is not a detector, it is a wall.
14// license_tier: ORIGINAL expect_exit: 0
15import "nx_gate_verdict.nx"
16import "nx_hypha.nx"
17
18const UG_TINY: i64 = 100 // units this peer actually shared
19const UG_HUGE: i64 = 100000000 // units this peer actually received (1e8)
20const UG_BAL: i64 = 90 // a balanced peer's shared units
21const UG_BAL_R: i64 = 110 // ...and received units
22const UG_DRAIN: i64 = 100 // receives needed to drain NX_HY_STARTER_QUOTA_DEFAULT
23
24// A peer whose starter quota is spent, carrying `shares` share-events and UG_DRAIN receive-events.
25// The starter quota is grace for newcomers -- it must be gone before any reciprocity rule applies,
26// otherwise every test here would trivially return OK and prove nothing (the vacuity trap).
27func ug_seasoned_peer(shares: i64) -> *NxPeerExchangeState {
28 let p: *NxPeerExchangeState = nx_hy_peer_state_new(42, 0, 1)
29 var i: i64 = 0
30 while i < UG_DRAIN {
31 nx_hy_record_exchange(p, NX_EM_STORAGE, NX_EM_DIR_RECEIVE, 0)
32 i = i + 1
33 }
34 var j: i64 = 0
35 while j < shares {
36 nx_hy_record_exchange(p, NX_EM_STORAGE, NX_EM_DIR_SHARE, 0)
37 j = j + 1
38 }
39 return p
40}
41
42func main() -> i64 {
43 let ctr: *i64 = gv_ctr()
44 gv_head("nx_commons_units_gate -- can a COUNT-based reciprocity floor see magnitude?" as *u8)
45
46 // The skimmer: 100 share-events and 100 receive-events (counts look 50/50), but he shared 100
47 // units and received 100,000,000. Same peer object, two rulers.
48 let skim: *NxPeerExchangeState = ug_seasoned_peer(100)
49 let skim_count: i64 = nx_hy_reciprocity_verdict(skim)
50 let skim_units: i64 = nx_hy_reciprocity_verdict_units(skim, UG_TINY, UG_HUGE)
51
52 // Negative control: a genuinely balanced peer must pass BOTH rulers.
53 let fair: *NxPeerExchangeState = ug_seasoned_peer(100)
54 let fair_count: i64 = nx_hy_reciprocity_verdict(fair)
55 let fair_units: i64 = nx_hy_reciprocity_verdict_units(fair, UG_BAL, UG_BAL_R)
56
57 gv_puts(" skimmer 100 share-events/100 recv-events, 100 units shared / 1e8 received\n" as *u8)
58 gv_puts(" count-based verdict = " as *u8); gv_num(skim_count)
59 gv_puts(" units-based verdict = " as *u8); gv_num(skim_units)
60 gv_puts(" (" as *u8); gv_num(NX_HY_OK); gv_puts("=OK " as *u8)
61 gv_num(NX_HY_ERR_RECIPROCITY_VIOLATION); gv_puts("=VIOLATION)\n" as *u8)
62 gv_puts(" balanced 90 units shared / 110 received\n" as *u8)
63 gv_puts(" count-based verdict = " as *u8); gv_num(fair_count)
64 gv_puts(" units-based verdict = " as *u8); gv_num(fair_units); gv_puts("\n\n" as *u8)
65
66 var t1: i64 = 0
67 if skim_units == NX_HY_ERR_RECIPROCITY_VIOLATION { t1 = 1 }
68 gv_check("T1 units floor REJECTS the 1:1,000,000 free-rider" as *u8, t1, ctr)
69
70 var t2: i64 = 0
71 if fair_units == NX_HY_OK { t2 = 1 }
72 gv_check("T2 NEG-CONTROL units floor ACCEPTS a genuinely balanced peer (not a wall)" as *u8, t2, ctr)
73
74 // The whole point: the count ruler cannot see what the units ruler sees. If these ever agree on
75 // the skewed peer, either the count rule was fixed in place (revisit this gate deliberately) or
76 // the units rule regressed to blindness.
77 var t3: i64 = 0
78 if skim_count == NX_HY_OK { if skim_units == NX_HY_ERR_RECIPROCITY_VIOLATION { t3 = 1 } }
79 gv_check("T3 DIFFERENTIAL: count ruler says OK where units ruler convicts (magnitude is doing work)" as *u8, t3, ctr)
80
81 // A newcomer must still be protected by the starter quota under the NEW ruler too -- extending a
82 // rule must not quietly delete the grace that made it humane.
83 let fresh: *NxPeerExchangeState = nx_hy_peer_state_new(43, 0, 1)
84 var t4: i64 = 0
85 if nx_hy_reciprocity_verdict_units(fresh, 0, UG_HUGE) == NX_HY_OK { t4 = 1 }
86 gv_check("T4 starter quota still protects a newcomer under the units ruler" as *u8, t4, ctr)
87
88 let rc: i64 = gv_verdict("COMMONS-UNITS" as *u8, ctr,
89 "reciprocity measured in quantities, not politeness" as *u8)
90 sys_exit(rc)
91 return rc
92}