code wiki / (root) / nx_commons_witness_gate.nx

nx_commons_witness_gate.nx source

↩ module page · 129 lines · 6369 B

1// nx_commons_witness_gate.nx -- proves the witness producer against the rule it was matched from. 2// 3// Both improvements over nx_trust_corroborate are BITE-PROVEN, not asserted: each must FIRE on the 4// known-good rule and be SILENT on the new one. T1/T4 are the negative controls -- an attestation rule 5// that admits nothing is not a detector, it is a wall, and one that ignores the hearsay floor is not a 6// rule at all. 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_gate_verdict.nx" 9import "nx_commons_witness.nx" 10 11const WG_STRIDE: i64 = 64 12const WG_LEN: i64 = 32 13const WG_TRUE: i64 = 170 // 0xAA -- the honest view of the contribution record 14const WG_POISON: i64 = 187 // 0xBB -- a fabricated view 15const WG_GIVER: i64 = 7 16const WG_RECV: i64 = 9 17const WG_K: i64 = 2 18 19func wg_fill(dst: *u8, off: i64, len: i64, val: i64) -> i64 { 20 var i: i64 = 0 21 while i < len { dst[off + i] = val as u8; i = i + 1 } 22 return 0 23} 24 25func main() -> i64 { 26 let ctr: *i64 = gv_ctr() 27 gv_head("nx_commons_witness_gate -- can a contribution claim be corroborated without its beneficiaries?" as *u8) 28 29 // ---- SET A: three strangers, all presenting the true record -------------------------------- 30 let va: *u8 = sys_mmap(3 * WG_STRIDE) 31 wg_fill(va, 0, WG_LEN, WG_TRUE) 32 wg_fill(va, WG_STRIDE, WG_LEN, WG_TRUE) 33 wg_fill(va, 2 * WG_STRIDE, WG_LEN, WG_TRUE) 34 let ida: *i64 = sys_mmap(3 * 8) as *i64 35 ida[0] = 11; ida[1] = 12; ida[2] = 13 36 let agree_a: i64 = cwit_plurality_agreement(va, WG_STRIDE, WG_LEN, ida, 3, WG_GIVER, WG_RECV) 37 let permil_a: i64 = cwit_witnessed_permil(va, WG_STRIDE, WG_LEN, ida, 3, WG_GIVER, WG_RECV, WG_K) 38 39 // ---- SET B: the SKIMMER'S ATTACK -- the only attestor is the counterparty he billed --------- 40 let vb: *u8 = sys_mmap(1 * WG_STRIDE) 41 wg_fill(vb, 0, WG_LEN, WG_TRUE) 42 let idb: *i64 = sys_mmap(8) as *i64 43 idb[0] = WG_RECV 44 let permil_b: i64 = cwit_witnessed_permil(vb, WG_STRIDE, WG_LEN, idb, 1, WG_GIVER, WG_RECV, WG_K) 45 46 // ---- SET C: POISON AT INDEX 0 -- 2 identical fabrications first, 3 honest views after ------- 47 let vc: *u8 = sys_mmap(5 * WG_STRIDE) 48 wg_fill(vc, 0, WG_LEN, WG_POISON) 49 wg_fill(vc, WG_STRIDE, WG_LEN, WG_POISON) 50 wg_fill(vc, 2 * WG_STRIDE, WG_LEN, WG_TRUE) 51 wg_fill(vc, 3 * WG_STRIDE, WG_LEN, WG_TRUE) 52 wg_fill(vc, 4 * WG_STRIDE, WG_LEN, WG_TRUE) 53 let idc: *i64 = sys_mmap(5 * 8) as *i64 54 idc[0] = 21; idc[1] = 22; idc[2] = 23; idc[3] = 24; idc[4] = 25 55 let src0_c: i64 = cwit_source0_agreement(vc, WG_STRIDE, WG_LEN, 5) 56 let plur_c: i64 = cwit_plurality_agreement(vc, WG_STRIDE, WG_LEN, idc, 5, WG_GIVER, WG_RECV) 57 58 // ---- SET D: one attestor IS the receiver; all three present the true record ----------------- 59 let vd: *u8 = sys_mmap(3 * WG_STRIDE) 60 wg_fill(vd, 0, WG_LEN, WG_TRUE) 61 wg_fill(vd, WG_STRIDE, WG_LEN, WG_TRUE) 62 wg_fill(vd, 2 * WG_STRIDE, WG_LEN, WG_TRUE) 63 let idd: *i64 = sys_mmap(3 * 8) as *i64 64 idd[0] = WG_RECV; idd[1] = 12; idd[2] = 13 65 let src0_d: i64 = cwit_source0_agreement(vd, WG_STRIDE, WG_LEN, 3) 66 let plur_d: i64 = cwit_plurality_agreement(vd, WG_STRIDE, WG_LEN, idd, 3, WG_GIVER, WG_RECV) 67 68 // ---- SET E: a single INDEPENDENT attestor -- corroboration of one is hearsay ---------------- 69 let ide: *i64 = sys_mmap(8) as *i64 70 ide[0] = 31 71 let permil_e: i64 = cwit_witnessed_permil(va, WG_STRIDE, WG_LEN, ide, 1, WG_GIVER, WG_RECV, WG_K) 72 73 // ---- SET F: the giver attests his own gift ------------------------------------------------- 74 let idf: *i64 = sys_mmap(8) as *i64 75 idf[0] = WG_GIVER 76 let permil_f: i64 = cwit_witnessed_permil(va, WG_STRIDE, WG_LEN, idf, 1, WG_GIVER, WG_RECV, WG_K) 77 78 gv_puts(" A 3 strangers, true record : agreement=" as *u8); gv_num(agree_a) 79 gv_puts(" witnessed_permil=" as *u8); gv_num(permil_a); gv_puts("\n" as *u8) 80 gv_puts(" B only the billed counterparty : witnessed_permil=" as *u8); gv_num(permil_b); gv_puts("\n" as *u8) 81 gv_puts(" C 2 poison at index 0, 3 honest: source-0 rule=" as *u8); gv_num(src0_c) 82 gv_puts(" plurality rule=" as *u8); gv_num(plur_c); gv_puts("\n" as *u8) 83 gv_puts(" D receiver among 3 attestors : no-exclusion=" as *u8); gv_num(src0_d) 84 gv_puts(" with-exclusion=" as *u8); gv_num(plur_d); gv_puts("\n" as *u8) 85 gv_puts(" E one independent attestor : witnessed_permil=" as *u8); gv_num(permil_e); gv_puts("\n" as *u8) 86 gv_puts(" F giver attests his own gift : witnessed_permil=" as *u8); gv_num(permil_f); gv_puts("\n\n" as *u8) 87 88 var t1: i64 = 0 89 if permil_a > 0 { if agree_a == 3 { t1 = 1 } } 90 gv_check("T1 NEG-CONTROL three independent strangers DO corroborate (not a wall)" as *u8, t1, ctr) 91 92 var t2: i64 = 0 93 if permil_b == 0 { t2 = 1 } 94 gv_check("T2 the billed counterparty alone yields ZERO witness (hearsay, not evidence)" as *u8, t2, ctr) 95 96 // The known good anchors agreement on source 0, so 2 identical fabrications at the head are 97 // counted as the quorum while 3 honest views are never consulted. Plurality reports the majority. 98 var c_bad: i64 = 0 99 if src0_c == 2 { c_bad = 1 } 100 var c_good: i64 = 0 101 if plur_c == 2 { c_good = 1 } 102 gv_bite("T3 poison-at-index-0: source-0 anchoring reports the MINORITY, plurality does not" as *u8, 103 c_bad, c_good, ctr) 104 105 var t4: i64 = 0 106 if plur_c == 3 { t4 = 1 } 107 gv_check("T4 plurality finds the honest majority (3 of 5) despite poison holding index 0" as *u8, t4, ctr) 108 109 // Party exclusion: identical bytes from all three, but one attestor has a stake in the claim. 110 var d_bad: i64 = 0 111 if src0_d == 3 { d_bad = 1 } 112 var d_good: i64 = 0 113 if plur_d == 3 { d_good = 1 } 114 gv_bite("T5 party exclusion: counting a beneficiary inflates the quorum (fires), excluding does not" as *u8, 115 d_bad, d_good, ctr) 116 117 var t6: i64 = 0 118 if permil_e == 0 { t6 = 1 } 119 gv_check("T6 HEARSAY FLOOR one independent voice is not corroboration (K>=2 by construction)" as *u8, t6, ctr) 120 121 var t7: i64 = 0 122 if permil_f == 0 { t7 = 1 } 123 gv_check("T7 self-attestation by the giver yields ZERO" as *u8, t7, ctr) 124 125 let rc: i64 = gv_verdict("COMMONS-WITNESS" as *u8, ctr, 126 "witnessed_permil now has a producer: plurality corroboration with party exclusion" as *u8) 127 sys_exit(rc) 128 return rc 129}