code wiki / _hdl_build / nx_tcratchet_gate.nx

nx_tcratchet_gate.nx source

↩ module page · 90 lines · 3938 B

1// nx_tcratchet_gate.nx -- proves the toolchain ratchet REFUSES a shrink and BLESSES a growth, then runs it 2// LIVE against the real toolchain artifacts. 3// 4// NON-VACUITY: T2 is the tooth that would have caught the 2026-07-30 incident -- it feeds the ACTUAL numbers 5// (live 520103 vs banked 543126, the regressed compiler that was found running on the hub) and asserts REFUSE. 6// If anyone loosens the floor, T2 goes RED with the real incident in its name. 7// T5/T6 are the matched pair that keeps the guard honest in BOTH directions: unbanked must never read OK, 8// and a legitimate GROWTH must never read REGRESSED (a ratchet that refuses everything is not a ratchet). 9// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 10import "nx_tcratchet_lib.nx" 11 12const TG_CC: *u8 = "buildroot/_offc/nx_cc_sovereign.elf" as *u8 13const TG_ASM: *u8 = "buildroot/_offc/nxasm_x86_main.elf" as *u8 14const TG_RUN: *u8 = "buildroot/_offc/nx_sov_build_run.elf" as *u8 15 16func tg_t(name: *u8, cond: i64, ctr: *i64) { 17 if cond == 1 { 18 tcr_puts(" ok " as *u8) 19 ctr[0] = ctr[0] + 1 20 } else { 21 tcr_puts(" FAIL " as *u8) 22 } 23 tcr_puts(name) 24 tcr_puts("\n" as *u8) 25 ctr[1] = ctr[1] + 1 26} 27 28func tg_report(label: *u8, path: *u8) { 29 let sz: i64 = tcr_size(path) 30 tcr_puts(" " as *u8) 31 tcr_puts(label) 32 tcr_puts(" live_bytes=" as *u8) 33 tcr_puti(sz) 34 tcr_puts(" " as *u8) 35 tcr_puts(path) 36 tcr_puts("\n" as *u8) 37} 38 39func main(argc: i64, argv: *i64) -> i64 { 40 var ctr: *i64 = sys_mmap(64) as *i64 41 ctr[0] = 0 42 ctr[1] = 0 43 44 tcr_puts("=== nx_tcratchet_gate -- does the toolchain ratchet refuse a REGRESSED compiler? ===\n" as *u8) 45 46 tg_t("T1 identical size -> OK" as *u8, tcr_verdict(543126, 543126, TCR_FLOOR_PERMIL) == TCR_OK, ctr) 47 48 tg_t("T2 THE REAL INCIDENT: live 520103 vs banked 543126 -> REFUSE (a 23023-byte shrink in the compiler)" as *u8, 49 tcr_verdict(520103, 543126, TCR_FLOOR_PERMIL) == TCR_REGRESSED, ctr) 50 51 tg_t("T3 one byte short still REFUSES (zero tolerance is the point)" as *u8, 52 tcr_verdict(543125, 543126, TCR_FLOOR_PERMIL) == TCR_REGRESSED, ctr) 53 54 tg_t("T4 GROWTH is blessed -- a ratchet that refuses everything is not a ratchet" as *u8, 55 tcr_verdict(543127, 543126, TCR_FLOOR_PERMIL) == TCR_OK, ctr) 56 57 tg_t("T5 FAIL-CLOSED: never banked -> UNBANKED, never OK" as *u8, 58 tcr_verdict(543126, 0, TCR_FLOOR_PERMIL) == TCR_UNBANKED, ctr) 59 60 tg_t("T6 FAIL-CLOSED: artifact absent -> MISSING, never OK" as *u8, 61 tcr_verdict(0 - 1, 543126, TCR_FLOOR_PERMIL) == TCR_MISSING, ctr) 62 63 tg_t("T7 a declared allowance is honoured (950 permil floor lets a 5pct shrink through, deliberately)" as *u8, 64 tcr_verdict(520103, 543126, 950) == TCR_OK, ctr) 65 66 tg_t("T8 NEG-CONTROL for T7: the SAME numbers at the default floor still REFUSE" as *u8, 67 tcr_verdict(520103, 543126, TCR_FLOOR_PERMIL) == TCR_REGRESSED, ctr) 68 69 let cc: i64 = tcr_size(TG_CC) 70 tg_t("T9 LIVE: the sovereign compiler artifact is readable on this host" as *u8, cc > 0, ctr) 71 tg_t("T10 LIVE NON-VACUITY: it is a real binary (>100KB), not a stub the ratchet would bless" as *u8, cc > 100000, ctr) 72 73 tcr_puts("\n-- LIVE TOOLCHAIN ARTIFACT SIZES (bank these; a later shrink is then REFUSED) --\n" as *u8) 74 tg_report("nx_cc_sovereign " as *u8, TG_CC) 75 tg_report("nxasm_x86_main " as *u8, TG_ASM) 76 tg_report("nx_sov_build_run " as *u8, TG_RUN) 77 tcr_puts(" NOTE: correctness and QUALITY are different axes. nx_tc_canary proves a compiler RUNS;\n" as *u8) 78 tcr_puts(" a worse-but-correct compiler passes it BY DESIGN. That is the hole this ratchet fills.\n" as *u8) 79 80 tcr_puts("\nTCRATCHET-GATE " as *u8) 81 tcr_puti(ctr[0]) 82 tcr_puts("/" as *u8) 83 tcr_puti(ctr[1]) 84 if ctr[0] == ctr[1] { 85 tcr_puts(" GREEN\n" as *u8) 86 return 0 87 } 88 tcr_puts(" RED\n" as *u8) 89 return 1 90}