code wiki / (root) / nx_provenance_test.nx

nx_provenance_test.nx source

↩ module page · 51 lines · 2307 B

1// nx_provenance_test.nx -- gate semantics on the live allowlist. 2 3import "nx_syscalls.nx" 4import "nx_tier.nx" 5import "nx_provenance.nx" 6 7func main() -> nx_exit { 8 let reg: *NxProvenanceRegistry = nx_provenance_load( 9 "nxc2/specs/nx_source_allowlist.txt" as *u8) 10 11 // Registry should have at least the rows we shipped. 12 if nx_provenance_n_records(reg) < 10 { return 11 } 13 14 // ----- APPROVED classes return their license class ----- 15 let r_eu: nx_int = nx_provenance_check(reg, "euclid_elements" as *u8) 16 if r_eu != NX_LC_PD_CLASSICAL { return 21 } 17 if nx_provenance_is_allowed(reg, "euclid_elements" as *u8) != 1 { return 22 } 18 19 let r_fnv: nx_int = nx_provenance_check(reg, "fowler_noll_vo_1991" as *u8) 20 if r_fnv != NX_LC_PD_EXPLICIT { return 23 } 21 if nx_provenance_is_allowed(reg, "fowler_noll_vo_1991" as *u8) != 1 { return 24 } 22 23 let r_adler: nx_int = nx_provenance_check(reg, "rfc1950_adler32" as *u8) 24 if r_adler != NX_LC_PD_GOVDOC { return 25 } 25 if nx_provenance_is_allowed(reg, "rfc1950_adler32" as *u8) != 1 { return 26 } 26 27 // ----- FORBIDDEN sources are refused ----- 28 let r_ml: nx_int = nx_provenance_check(reg, "mathlib4" as *u8) 29 if r_ml != NX_LC_FORBIDDEN { return 31 } 30 if nx_provenance_is_allowed(reg, "mathlib4" as *u8) != 0 { return 32 } 31 32 let r_wolf: nx_int = nx_provenance_check(reg, "wolfram_anything" as *u8) 33 if r_wolf != NX_LC_FORBIDDEN { return 33 } 34 if nx_provenance_is_allowed(reg, "wolfram_anything" as *u8) != 0 { return 34 } 35 36 let r_hol: nx_int = nx_provenance_check(reg, "hol_light" as *u8) 37 if r_hol != NX_LC_FORBIDDEN { return 35 } 38 39 // ----- UNKNOWN sources are refused (default deny) ----- 40 let r_unk: nx_int = nx_provenance_check(reg, "some_random_source_id_xyz" as *u8) 41 if r_unk != NX_LC_UNKNOWN { return 41 } 42 if nx_provenance_is_allowed(reg, "some_random_source_id_xyz" as *u8) != 0 { return 42 } 43 44 // ----- by-class counts make sense ----- 45 if nx_provenance_n_by_class(reg, NX_LC_PD_CLASSICAL) < 5 { return 51 } 46 if nx_provenance_n_by_class(reg, NX_LC_PD_EXPLICIT) < 5 { return 52 } 47 if nx_provenance_n_by_class(reg, NX_LC_FORBIDDEN) < 5 { return 53 } 48 if nx_provenance_n_by_class(reg, NX_LC_UNKNOWN) != 0 { return 54 } // none EXPLICITLY unknown 49 50 return 0 51}