code wiki / _hdl_build / nx_trust_plurality_gate.nx
nx_trust_plurality_gate.nx source
↩ module page · 91 lines · 4495 B
1// nx_trust_plurality_gate.nx -- proves the sev-9 fix to the SPORE trust bootstrap (debt 1786068026).
2//
3// DEFECT: tc_admit_root counted agreement WITH SOURCE 0. Two colluding sources presenting identical
4// poison at indices 0-1 reached K=2 and were admitted while an honest majority was never consulted.
5// The soundness gate used the same measure, so it could never fire on it.
6//
7// The existing nx_trust_corroborate_test covers 4-honest, 1-source and 1-poison. It never covers a
8// poisoned MINORITY holding index 0 against an honest MAJORITY -- the one arrangement that breaks it.
9// A TEST THAT ONLY EXERCISES THE ARRANGEMENTS THE AUTHOR IMAGINED IS A RESTATEMENT OF THE AUTHOR'S
10// ASSUMPTIONS, NOT A CHECK ON THEM.
11// license_tier: ORIGINAL expect_exit: 0
12import "nx_gate_verdict.nx"
13import "nx_trust_corroborate.nx"
14import "nx_trust_store_corroborated.nx"
15
16const TG_STRIDE: i64 = 48
17const TG_DER: i64 = 32
18const TG_TRUE: i64 = 170
19const TG_POISON: i64 = 187
20const TG_K: i64 = 2
21
22func tg_fill(d: *u8, off: i64, n: i64, v: i64) -> i64 {
23 var i: i64 = 0
24 while i < n { d[off + i] = v as u8; i = i + 1 }
25 return 0
26}
27
28func main() -> i64 {
29 let ctr: *i64 = gv_ctr()
30 gv_head("nx_trust_plurality_gate -- can poison be admitted merely by holding index 0?" as *u8)
31
32 let a: *u8 = sys_mmap(4 * TG_STRIDE)
33 tg_fill(a, 0, TG_DER, TG_TRUE); tg_fill(a, TG_STRIDE, TG_DER, TG_TRUE)
34 tg_fill(a, 2 * TG_STRIDE, TG_DER, TG_TRUE); tg_fill(a, 3 * TG_STRIDE, TG_DER, TG_TRUE)
35 let admit_a: i64 = tc_admit_root(a, TG_STRIDE, TG_DER, 4, TG_K)
36 let str_a: i64 = tc_corroboration_strength(a, TG_STRIDE, TG_DER, 4)
37
38 // THE ATTACK: 2 identical poison presentations at indices 0,1; 3 honest after.
39 let c: *u8 = sys_mmap(5 * TG_STRIDE)
40 tg_fill(c, 0, TG_DER, TG_POISON); tg_fill(c, TG_STRIDE, TG_DER, TG_POISON)
41 tg_fill(c, 2 * TG_STRIDE, TG_DER, TG_TRUE); tg_fill(c, 3 * TG_STRIDE, TG_DER, TG_TRUE)
42 tg_fill(c, 4 * TG_STRIDE, TG_DER, TG_TRUE)
43 let str_c: i64 = tc_corroboration_strength(c, TG_STRIDE, TG_DER, 5)
44 let idx_c: i64 = tc_admit_root_index(c, TG_STRIDE, TG_DER, 5, TG_K)
45
46 let b: *u8 = sys_mmap(TG_STRIDE)
47 tg_fill(b, 0, TG_DER, TG_TRUE)
48 let admit_b: i64 = tc_admit_root(b, TG_STRIDE, TG_DER, 1, TG_K)
49
50 gv_puts(" A 4 honest : admit=" as *u8); gv_num(admit_a); gv_puts(" strength=" as *u8); gv_num(str_a); gv_puts("\n" as *u8)
51 gv_puts(" C 2 poison@0,1 vs 3 honest: strength=" as *u8); gv_num(str_c)
52 gv_puts(" majority_index=" as *u8); gv_num(idx_c); gv_puts(" (>=2 means an HONEST presentation)\n" as *u8)
53 gv_puts(" B lone source : admit=" as *u8); gv_num(admit_b); gv_puts("\n\n" as *u8)
54
55 var t1: i64 = 0
56 if admit_a == 1 { if str_a == 4 { t1 = 1 } }
57 gv_check("T1 NEG-CONTROL four honest sources still admit at full strength" as *u8, t1, ctr)
58
59 var t2: i64 = 0
60 if admit_b == 0 { t2 = 1 }
61 gv_check("T2 NEG-CONTROL a lone source is still hearsay" as *u8, t2, ctr)
62
63 var t3: i64 = 0
64 if str_c == 3 { t3 = 1 }
65 gv_check("T3 strength reports the HONEST MAJORITY (3), not the poison cluster (2)" as *u8, t3, ctr)
66
67 // Counting the majority but installing index 0 would admit the poison WITH a quorum's blessing --
68 // strictly worse than the original defect. The decision must NAME the bytes it admitted.
69 var t4: i64 = 0
70 if idx_c >= 2 { t4 = 1 }
71 gv_check("T4 majority_index names an HONEST presentation, never the poison at index 0" as *u8, t4, ctr)
72
73 var t5: i64 = 0
74 if tc_admit_root_index(a, TG_STRIDE, TG_DER, 4, 1) == (0 - 1) { t5 = 1 }
75 gv_check("T5 k=1 is refused by construction (hearsay floor not caller-overridable)" as *u8, t5, ctr)
76
77 // STORE-LEVEL adoption: a correct primitive buys nothing if the caller still picks its own bytes.
78 let aidx: *i64 = sys_mmap(2 * 8) as *i64
79 let asrc: *i64 = sys_mmap(2 * 8) as *i64
80 let n_adm: i64 = tsc_build_sourced(c, 1, 5, TG_STRIDE, TG_DER, TG_K, aidx, asrc)
81 gv_puts(" store: admitted=" as *u8); gv_num(n_adm); gv_puts(" root=" as *u8); gv_num(aidx[0])
82 gv_puts(" install_source=" as *u8); gv_num(asrc[0]); gv_puts("\n\n" as *u8)
83 var t6: i64 = 0
84 if n_adm == 1 { if asrc[0] >= 2 { t6 = 1 } }
85 gv_check("T6 ADOPTION store names an HONEST source to install, not index 0" as *u8, t6, ctr)
86
87 let rc: i64 = gv_verdict("TRUST-PLURALITY" as *u8, ctr,
88 "trust anchors admitted by majority agreement, and the admitted BYTES are named" as *u8)
89 sys_exit(rc)
90 return rc
91}