code wiki / (root) / nx_legal_audit.nx

nx_legal_audit.nx source

↩ module page · 186 lines · 7082 B

1// nx_legal_audit.nx -- algorithmic-cleanliness + sovereignty audit. 2// 3// Per user 2026-05-15: "make sure we are avoiding any legal issues, 4// we want this all to be nishi bits up superior" + "i dont want to 5// use a third party just have something similar as i dont want 6// backdoors, pure nishi lang soverieng". 7// 8// HARD INVARIANTS (encoded in the verdict logic below): 9// 1. EVERY substrate component is licensed NX_LICENSE_NATIVE_NX. 10// The engine REFUSES to register anything else. No third-party 11// code linked, no third-party runtime, no third-party CRT. 12// 2. The (year, author) fields are HISTORICAL CITATION of the 13// ALGORITHM (the math), NOT dependency provenance. We 14// reimplemented from the public mathematical idea; the 15// implementation is 100% NishiLang. 16// 3. We only reimplement algorithms whose underlying math is 17// patent-clean: pre-1929 (Presburger and earlier), academic 18// publication with no patent claim, or expired (>20 yrs). 19// 4. Sovereignty check: nx_legal_verify_sovereign() asserts 20// ZERO non-native licenses across the audit. Returns 1 only 21// if every entry is NX_LICENSE_NATIVE_NX. 22 23// nx_safety_envelope: 24// intended_use: AUTO_APPLIED -- primitive-specific tuning queued 25// sil_target: SIL1 26// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail] 27// verdict: NOT_YET_EVALUATED 28 29import "nx_kernel_v2.nx" 30 31// ===== Sealed license enum ========================================= 32const NX_LICENSE_PUBLIC_DOMAIN: nx_int = 1 // > 95 years old or formally PD 33const NX_LICENSE_MIT: nx_int = 2 34const NX_LICENSE_APACHE2: nx_int = 3 35const NX_LICENSE_BSD3: nx_int = 4 36const NX_LICENSE_BSD2: nx_int = 5 37const NX_LICENSE_NATIVE_NX: nx_int = 6 // our own NishiLang code 38const NX_LICENSE_GPL2: nx_int = 100 // contaminating, REFUSED 39const NX_LICENSE_GPL3: nx_int = 101 // contaminating, REFUSED 40const NX_LICENSE_AGPL3: nx_int = 102 // contaminating, REFUSED 41const NX_LICENSE_PROPRIETARY: nx_int = 103 // contaminating, REFUSED 42 43// ===== Sealed patent-class enum ==================================== 44const NX_PATENT_EXPIRED: nx_int = 1 // published > 20 years ago 45const NX_PATENT_NEVER_PATENTED: nx_int = 2 // academic publication, no patent claim 46const NX_PATENT_OPEN_GRANT: nx_int = 3 // patented but open grant (e.g. AVX intrinsics) 47const NX_PATENT_LIVE: nx_int = 100 // active patent, REFUSED unless licensed 48 49// ===== Component entry ============================================= 50struct LegalEntry { 51 name: *u8, 52 name_len: nx_int, 53 method_year: nx_int, // year the algorithm was first published 54 author: *u8, 55 author_len: nx_int, 56 license: nx_int, // NX_LICENSE_* 57 patent_class: nx_int, // NX_PATENT_* 58 notes: *u8, 59} 60const NX_LEGAL_BYTES: nx_int = 56 61 62struct LegalAudit { 63 entries: *LegalEntry, 64 n: nx_int, 65 cap: nx_int, 66} 67const NX_LEGAL_AUDIT_BYTES: nx_int = 24 68 69func nx_legal_audit_new(cap: nx_int) -> *LegalAudit { 70 let a: *LegalAudit = (sys_mmap(NX_LEGAL_AUDIT_BYTES as i64)) as *LegalAudit 71 a.entries = (sys_mmap((cap * NX_LEGAL_BYTES) as i64)) as *LegalEntry 72 a.n = 0 73 a.cap = cap 74 return a 75} 76 77func nx_legal_at(a: *LegalAudit, i: nx_int) -> *LegalEntry { 78 return ((a.entries as nx_int) + (i * NX_LEGAL_BYTES)) as *LegalEntry 79} 80 81// Register one component. REFUSES any non-native license (returns -2) 82// per the sovereign-NishiLang invariant -- substrate code MUST be 83// NX_LICENSE_NATIVE_NX. REFUSES any live patent (returns -3) since 84// our reimplementation can't legally circumvent active patents. 85func nx_legal_register( 86 a: *LegalAudit, 87 name: *u8, name_len: nx_int, 88 method_year: nx_int, 89 author: *u8, author_len: nx_int, 90 license: nx_int, 91 patent_class: nx_int, 92 notes: *u8 93) -> nx_int { 94 if a.n >= a.cap { return -1 } 95 if license != NX_LICENSE_NATIVE_NX { return -2 } // sovereignty hard-stop 96 if patent_class == NX_PATENT_LIVE { return -3 } // no live patents 97 let e: *LegalEntry = nx_legal_at(a, a.n) 98 e.name = name 99 e.name_len = name_len 100 e.method_year = method_year 101 e.author = author 102 e.author_len = author_len 103 e.license = license 104 e.patent_class = patent_class 105 e.notes = notes 106 let idx: nx_int = a.n 107 a.n = a.n + 1 108 return idx 109} 110 111// Sovereignty assertion: returns 1 iff EVERY entry is NX_LICENSE_NATIVE_NX 112// AND no entry's algorithm carries a live patent. Use this as a 113// pre-release gate -- if it returns 0, we have a contamination. 114func nx_legal_verify_sovereign(a: *LegalAudit) -> nx_int { 115 var i: nx_int = 0 116 while i < a.n { 117 let e: *LegalEntry = nx_legal_at(a, i) 118 if e.license != NX_LICENSE_NATIVE_NX { return 0 } 119 if e.patent_class == NX_PATENT_LIVE { return 0 } 120 i = i + 1 121 } 122 return 1 123} 124 125// Verdict: is this component LEGAL_CLEAN, LEGAL_REVIEW, or LEGAL_REFUSED? 126const NX_LEGAL_CLEAN: nx_int = 1 127const NX_LEGAL_REVIEW: nx_int = 2 128const NX_LEGAL_REFUSED: nx_int = 3 129 130func nx_legal_verdict(e: *LegalEntry) -> nx_int { 131 // Refused licenses (contaminating) 132 if e.license == NX_LICENSE_GPL2 { return NX_LEGAL_REFUSED } 133 if e.license == NX_LICENSE_GPL3 { return NX_LEGAL_REFUSED } 134 if e.license == NX_LICENSE_AGPL3 { return NX_LEGAL_REFUSED } 135 if e.license == NX_LICENSE_PROPRIETARY { return NX_LEGAL_REFUSED } 136 // Active patent without grant -- refused 137 if e.patent_class == NX_PATENT_LIVE { return NX_LEGAL_REFUSED } 138 // Anything else is clean (public domain, MIT, Apache2, BSD, 139 // native NX, expired/never-patented, or open grant) 140 return NX_LEGAL_CLEAN 141} 142 143// Counters 144func nx_legal_count_clean(a: *LegalAudit) -> nx_int { 145 var n: nx_int = 0 146 var i: nx_int = 0 147 while i < a.n { 148 let e: *LegalEntry = nx_legal_at(a, i) 149 if nx_legal_verdict(e) == NX_LEGAL_CLEAN { n = n + 1 } 150 i = i + 1 151 } 152 return n 153} 154 155func nx_legal_count_refused(a: *LegalAudit) -> nx_int { 156 var n: nx_int = 0 157 var i: nx_int = 0 158 while i < a.n { 159 let e: *LegalEntry = nx_legal_at(a, i) 160 if nx_legal_verdict(e) == NX_LEGAL_REFUSED { n = n + 1 } 161 i = i + 1 162 } 163 return n 164} 165 166// Pretty-print one row. 167func nx_legal_emit_row(e: *LegalEntry) -> nx_int { 168 print(" " as *u8); print(e.name) 169 print(" (" as *u8); print(e.author); print(", " as *u8); print_i64(e.method_year); print(")" as *u8) 170 let v: nx_int = nx_legal_verdict(e) 171 if v == NX_LEGAL_CLEAN { print(" CLEAN " as *u8) } 172 if v == NX_LEGAL_REVIEW { print(" REVIEW " as *u8) } 173 if v == NX_LEGAL_REFUSED { print(" REFUSED" as *u8) } 174 println("" as *u8) 175 return v 176} 177 178func nx_legal_emit_all(a: *LegalAudit) -> nx_int { 179 var i: nx_int = 0 180 while i < a.n { 181 let e: *LegalEntry = nx_legal_at(a, i) 182 let _v: nx_int = nx_legal_emit_row(e) 183 i = i + 1 184 } 185 return a.n 186}