code wiki / (root) / nx_commons_ledger_gate.nx

nx_commons_ledger_gate.nx source

↩ module page · 105 lines · 5327 B

1// nx_commons_ledger_gate.nx -- proves the ledger derives what the bench previously had to be TOLD, 2// and measures honestly where the derivation STOPS. 3// 4// The headline result here is a LIMIT, not a win: a 3-cycle sybil ring DEFEATS the flow-through rule. 5// Each member gives onward to someone it never received from, so its onward circulation looks perfect 6// and its retained value is zero. Flow-through catches a 2-cycle (return trips) and is blind to longer 7// cycles. That is measured below, not argued. 8// A RULE THAT CATCHES THE SHAPE YOU IMAGINED IS NOT A RULE THAT CATCHES THE BEHAVIOUR. 9// The ring is still convicted -- by the WITNESS layer, which it cannot satisfy at any cycle length -- 10// so the two layers are complementary and NEITHER IS SUFFICIENT ALONE. Shipping flow-through as a 11// sybil defence on its own would have been a false all-clear. 12// license_tier: ORIGINAL expect_exit: 0 13import "nx_gate_verdict.nx" 14import "nx_commons_ledger.nx" 15import "nx_commons_lib.nx" 16 17const LG_N: i64 = 7 18const LG_M: i64 = 6 19 20func main() -> i64 { 21 let ctr: *i64 = gv_ctr() 22 gv_head("nx_commons_ledger_gate -- what can transfer rows alone tell us?" as *u8) 23 24 // members: 1 JANITOR, 2 A, 3 B, 4 R1, 5 R2, 6 R3 (R* are a closed 3-cycle ring) 25 let ids: *i64 = sys_mmap(LG_M * 8) as *i64 26 ids[0]=1; ids[1]=2; ids[2]=3; ids[3]=4; ids[4]=5; ids[5]=6 27 28 let gv: *i64 = sys_mmap(LG_N * 8) as *i64 29 let rc2: *i64 = sys_mmap(LG_N * 8) as *i64 30 let un: *i64 = sys_mmap(LG_N * 8) as *i64 31 let at: *i64 = sys_mmap(LG_N * 8) as *i64 32 // JAN gives outward twice; A returns some to JAN; the ring circulates; row 6 REPEATS row 0. 33 gv[0]=1; rc2[0]=2; un[0]=100; at[0]=10 34 gv[1]=1; rc2[1]=3; un[1]=100; at[1]=11 35 gv[2]=2; rc2[2]=1; un[2]=50; at[2]=12 36 gv[3]=4; rc2[3]=5; un[3]=300; at[3]=13 37 gv[4]=5; rc2[4]=6; un[4]=300; at[4]=14 38 gv[5]=6; rc2[5]=4; un[5]=300; at[5]=15 39 gv[6]=1; rc2[6]=2; un[6]=100; at[6]=10 // EXACT duplicate of row 0 40 41 let keys: *i64 = sys_mmap(LG_N * 8) as *i64 42 var i: i64 = 0 43 while i < LG_N { keys[i] = cl_row_key(gv[i], rc2[i], 0, un[i], at[i]); i = i + 1 } 44 45 let gave: *i64 = sys_mmap(LG_M * 8) as *i64 46 let took: *i64 = sys_mmap(LG_M * 8) as *i64 47 let pas: *i64 = sys_mmap(LG_M * 8) as *i64 48 let ptn: *i64 = sys_mmap(LG_M * 8) as *i64 49 let counted: i64 = cl_aggregate(gv, rc2, un, keys, LG_N, ids, LG_M, gave, took, pas, ptn) 50 51 gv_puts(" member gave took passed partners\n" as *u8) 52 var k: i64 = 0 53 while k < LG_M { 54 gv_puts(" id=" as *u8); gv_num(ids[k]); gv_puts(" " as *u8); gv_num(gave[k]) 55 gv_puts(" " as *u8); gv_num(took[k]); gv_puts(" " as *u8); gv_num(pas[k]) 56 gv_puts(" " as *u8); gv_num(ptn[k]); gv_puts("\n" as *u8) 57 k = k + 1 58 } 59 gv_puts(" rows=" as *u8); gv_num(LG_N); gv_puts(" counted=" as *u8); gv_num(counted); gv_puts(" (1 duplicate)\n\n" as *u8) 60 61 var t1: i64 = 0 62 if cl_conserved(gave, took, LG_M) == 1 { t1 = 1 } 63 gv_check("T1 CONSERVATION every unit given is a unit taken (the parts SUM)" as *u8, t1, ctr) 64 65 var t2: i64 = 0 66 if counted == 6 { if gave[0] == 200 { t2 = 1 } } 67 gv_check("T2 IDEMPOTENT a repeated row is counted ONCE (law 10, no minting from a replay)" as *u8, t2, ctr) 68 69 // Derived, not labelled: JANITOR gave 100 to B (never a source) and 100 back to A (a source). 70 var t3: i64 = 0 71 if pas[0] == 100 { t3 = 1 } 72 gv_check("T3 DERIVED onward circulation separates a return trip from passing value on" as *u8, t3, ctr) 73 74 var t4: i64 = 0 75 if ptn[0] == 2 { if ptn[3] == 2 { t4 = 1 } } 76 gv_check("T4 DERIVED distinct counterparties come from the rows, not from a fixture" as *u8, t4, ctr) 77 78 // THE LIMIT. R1 took 300 and passed 300 onward, so retained is ZERO and flow-through sees a model 79 // citizen. A longer cycle costs the attacker one more identity and nothing else. 80 let r1_ret: i64 = nxc_retained(took[3], pas[3]) 81 gv_puts(" ring member R1: took=" as *u8); gv_num(took[3]); gv_puts(" passed=" as *u8); gv_num(pas[3]) 82 gv_puts(" retained=" as *u8); gv_num(r1_ret); gv_puts("\n" as *u8) 83 var t5: i64 = 0 84 if r1_ret == 0 { t5 = 1 } 85 gv_check("T5 MEASURED LIMIT a 3-cycle ring defeats flow-through (retained==0, looks exemplary)" as *u8, t5, ctr) 86 87 // ...and is convicted anyway, because it cannot manufacture independent witnesses at ANY cycle 88 // length. witn=0 for the ring, 900 for the janitor; everything else comes from the ledger. 89 let s_jan: i64 = nxc_standing(gave[0], took[0], pas[0], 900, 900, ptn[0]) 90 let s_r1: i64 = nxc_standing(gave[3], took[3], pas[3], 0, 900, ptn[3]) 91 gv_puts(" standing from ledger: JANITOR=" as *u8); gv_num(s_jan) 92 gv_puts(" RING-R1=" as *u8); gv_num(s_r1); gv_puts("\n\n" as *u8) 93 var t6: i64 = 0 94 if s_jan > s_r1 { t6 = 1 } 95 gv_check("T6 the WITNESS layer convicts the ring that flow-through cleared" as *u8, t6, ctr) 96 97 var t7: i64 = 0 98 if r1_ret == 0 { if s_r1 < s_jan { t7 = 1 } } 99 gv_check("T7 LAYERS ARE COMPLEMENTARY neither flow-through nor witness suffices alone" as *u8, t7, ctr) 100 101 let rc: i64 = gv_verdict("COMMONS-LEDGER" as *u8, ctr, 102 "transfer rows derive gave/took/passed/partners; the flow-through blind spot is named and covered" as *u8) 103 sys_exit(rc) 104 return rc 105}