code wiki / _hdl_build / nx_trust_corroborate.nx
nx_trust_corroborate.nx source
↩ module page · 112 lines · 6006 B
1// nx_trust_corroborate.nx -- the SPORE's sovereign trust bootstrap (operator 2026-06-05: "how do we build from
2// the hardware layer up so the spore can get this -- thats the approach vs shortcuts or hacks"). A sovereign
3// system cannot derive trust from nothing, but it must NOT trust a downloaded blob (certdata.txt) or the
4// substrate's store. The spore carries a RULE, not a trusted file: a root CA is admitted ONLY IF >= K
5// INDEPENDENT sources present the EXACT SAME bytes -- verified by the team's OWN SHA-256, never a source's
6// self-claimed hash. This is the team's own >=2-source research-corroboration gate applied to trust anchors:
7// trust EMERGES from independent agreement, hardware-up. A single tampered/poisoned source cannot reach K alone.
8// After bootstrap the spore self-updates over its OWN now-trusted HTTPS. license_tier: ORIGINAL
9import "nx_sha256.nx"
10import "nx_syscalls.nx"
11
12const TC_HASHLEN: i64 = 32
13
14// the team's OWN fingerprint of a presented root -- WE hash the bytes, we never trust a source's claimed hash.
15func tc_fingerprint(der: *u8, n: i64, out32: *u8) -> i64 { return sha256_digest(der, n, out32) }
16
17// equal 32-byte fingerprints? (constant structure; trust decisions are on bytes WE computed)
18func tc_hash_eq(a: *u8, b: *u8) -> i64 {
19 var i: i64 = 0
20 while i < TC_HASHLEN { if a[i] != b[i] { return 0 } i = i + 1 }
21 return 1
22}
23
24// how many of n_sources independently presented a root whose TEAM-COMPUTED fingerprint equals target_fp?
25// source_fps = n_sources * 32 bytes, each = the team's own hash of THAT source's view of the root.
26func tc_agreement_count(target_fp: *u8, source_fps: *u8, n_sources: i64) -> i64 {
27 var c: i64 = 0; var s: i64 = 0
28 while s < n_sources {
29 if tc_hash_eq(target_fp, source_fps + s * TC_HASHLEN) == 1 { c = c + 1 }
30 s = s + 1
31 }
32 return c
33}
34
35// ADMIT a root iff >= K independent sources agree on its exact bytes. K is the spore's carried RULE (the only
36// axiom -- and it's a threshold, not a trusted blob). K=1 is hearsay (forbidden); K>=2 is corroboration.
37func tc_admit(agreement: i64, k: i64) -> i64 {
38 if k < 2 { return 0 } // hearsay floor: a lone source is never trust (matches the research gate)
39 if agreement >= k { return 1 }
40 return 0
41}
42
43// LARGEST AGREEMENT CLUSTER among the presented fingerprints -- the MAJORITY view, not source 0's.
44// FIX 2026-08-06 (debt 1786068026, sev9). The original computed
45// let agree = tc_agreement_count(fps, fps, n_sources)
46// whose target IS fps[0]. Two colluding sources presenting identical poison at indices 0 and 1 reached
47// K=2 and were ADMITTED, while any number of honest sources presenting the true DER were never
48// consulted. Poison had only to OCCUPY INDEX 0 -- it never had to out-number the truth.
49// AN AGREEMENT COUNT ANCHORED ON ONE PARTICULAR SOURCE IS NOT A MAJORITY,
50// IT IS THAT SOURCE'S OPINION WEARING A QUORUM'S CLOTHES.
51// The soundness gate tsc_all_corroborated called tc_corroboration_strength, which used the SAME
52// source-0 measure -- so the guard shared the exact defect it existed to catch and could never fire.
53func tc_plurality_size(fps: *u8, n_sources: i64) -> i64 {
54 var best: i64 = 0
55 var a: i64 = 0
56 while a < n_sources {
57 let c: i64 = tc_agreement_count(fps + a * TC_HASHLEN, fps, n_sources)
58 if c > best { best = c }
59 a = a + 1
60 }
61 return best
62}
63
64// Index of a source holding the majority view -- the presentation whose BYTES the caller must parse
65// and install. Counting the majority but still installing source 0's DER would admit the poison with
66// a quorum's blessing, which is STRICTLY WORSE than the original defect. -1 = admit nothing.
67func tc_majority_index(fps: *u8, n_sources: i64, k: i64) -> i64 {
68 var best: i64 = 0
69 var bi: i64 = 0 - 1
70 var a: i64 = 0
71 while a < n_sources {
72 let c: i64 = tc_agreement_count(fps + a * TC_HASHLEN, fps, n_sources)
73 if c > best { best = c; bi = a }
74 a = a + 1
75 }
76 if best < k { return 0 - 1 }
77 return bi
78}
79
80// full decision for one candidate root: hash each source's view with OUR sha256, count agreement, admit iff >=K.
81// sources = n_sources * der_stride bytes (each source's presented DER of this root, fixed stride); der_len = the
82// real DER length to hash. Returns 1 = admit into the trust store, 0 = reject (uncorroborated or poisoned).
83func tc_admit_root(sources: *u8, der_stride: i64, der_len: i64, n_sources: i64, k: i64) -> i64 {
84 let fps: *u8 = sys_mmap(n_sources * TC_HASHLEN)
85 var s: i64 = 0
86 while s < n_sources {
87 tc_fingerprint(sources + s * der_stride, der_len, fps + s * TC_HASHLEN) // WE hash each source
88 s = s + 1
89 }
90 // the candidate fingerprint is the MAJORITY cluster's, never index 0's (debt 1786068026)
91 let agree: i64 = tc_plurality_size(fps, n_sources)
92 return tc_admit(agree, k)
93}
94
95// the count of sources that AGREE with the majority view of source 0 (for reporting how strong the corroboration is).
96func tc_corroboration_strength(sources: *u8, der_stride: i64, der_len: i64, n_sources: i64) -> i64 {
97 let fps: *u8 = sys_mmap(n_sources * TC_HASHLEN)
98 var s: i64 = 0
99 while s < n_sources { tc_fingerprint(sources + s * der_stride, der_len, fps + s * TC_HASHLEN); s = s + 1 }
100 return tc_plurality_size(fps, n_sources)
101}
102
103// WHICH presentation should the caller parse and install? -1 = admit nothing. This is the byte-selection
104// half of the fix: an admission decision that does not also name the bytes it admitted is only half a
105// decision, and the caller will reach for index 0 by default -- which is the poison.
106func tc_admit_root_index(sources: *u8, der_stride: i64, der_len: i64, n_sources: i64, k: i64) -> i64 {
107 if k < 2 { return 0 - 1 }
108 let fps: *u8 = sys_mmap(n_sources * TC_HASHLEN)
109 var s: i64 = 0
110 while s < n_sources { tc_fingerprint(sources + s * der_stride, der_len, fps + s * TC_HASHLEN); s = s + 1 }
111 return tc_majority_index(fps, n_sources, k)
112}