omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / protocol / uor-gpu / proofs / UorGpuWorld.lean
| 1 | -- SPDX-License-Identifier: Apache-2.0 |
| 2 | -- Machine-checked Lean 4 specification for hologram:gpu/omega-om2@1 (UOR-GPU-1). |
| 3 | -- Core Lean 4 only (no Mathlib), zero `sorry`, zero `native_decide`, standard axioms only. |
| 4 | -- |
| 5 | -- Model-to-system link (repo omega-mv): |
| 6 | -- * protocol/uor-gpu/canonical.om — 384-byte UOR-GPU-1 header, u32 LE codec, SHA-256 + BLAKE3 seal, |
| 7 | -- reason codes 0..20. |
| 8 | -- * protocol/uor-gpu/payload_vm.om — 896-byte SM121 payload (512B SASS + 384B QMD v05.00), |
| 9 | -- SKEDCHECK05 checks, SM121 SASS decoder, canary-guarded replay. |
| 10 | -- * protocol/uor-gpu/verify.om — UORTRST1 local trust anchors (104B + 32*k keys, auth != signer), |
| 11 | -- P0..P3 policy order, honest policy level & signature rules. |
| 12 | -- * protocol/uor-gpu/gate.om — Pre-dispatch admission gate (P2 + authority-signed live grant). |
| 13 | -- * om/gpu/bw_vecadd.om — 512B Blackwell SM121 u32 vecadd machine code. |
| 14 | -- * om/gpu/bw_qmd.om — 96-word (384B) QMD v05.00 packer, smem_cfg_for, bw_qmd_verify. |
| 15 | -- |
| 16 | -- Theorem family alignment: |
| 17 | -- * Recent AIEN Lean 4 proofs (AienGpuGb20b, AienReceipt, AienCap, NgA64Vec, CodebookProof, |
| 18 | -- TicketLock, interplane-forge Ledger, BtWaveProofs): wire-layout contiguity/disjointness, |
| 19 | -- BitVec round-trip/injectivity/opcode-disjointness, multi-thread loop + canary preservation, |
| 20 | -- collision-resistant hash tamper evidence, trust separation + check-order equivalence + |
| 21 | -- monotonicity, inductive lifecycle reachability, and load-bearing negative controls. |
| 22 | -- * UOR Foundation / Prism group (uor-framework, LexLean, PrismPM, uor-comms, mnist): |
| 23 | -- Z/(2^32)Z ring critical identity & involutions, contract-satisfaction theorem, |
| 24 | -- domain-separated framed content IDs, refusal-reason soundness/completeness, and |
| 25 | -- PrismPM Foundation.Proof.V1.Statement axiom-policy & replay verdict enforcement. |
| 26 | -- |
| 27 | -- Honest scope boundary: |
| 28 | -- Proves the explicit model below. Does NOT prove hardware equivalence on physical GB10 silicon |
| 29 | -- (hardware status: NOT_RUN). |
| 30 | |
| 31 | namespace UorGpuWorld |
| 32 | |
| 33 | /-! ## 1. Wire-Layout Contiguity, Disjointness, and Exact Tiling -/ |
| 34 | |
| 35 | /-- Interval `[lo, hi)` disjointness check (matches AienGpuGb20b / AienReceipt). -/ |
| 36 | def ivDisjoint (a b : Nat × Nat) : Bool := |
| 37 | a.2 ≤ b.1 || b.2 ≤ a.1 |
| 38 | |
| 39 | def allPairwiseDisjoint : List (Nat × Nat) → Bool |
| 40 | | [] => true |
| 41 | | x :: xs => xs.all (ivDisjoint x) && allPairwiseDisjoint xs |
| 42 | |
| 43 | def allValidIn (bound : Nat) (fs : List (Nat × Nat)) : Bool := |
| 44 | fs.all (fun p => p.1 < p.2 && p.2 ≤ bound) |
| 45 | |
| 46 | /-- Contiguous `(offset, width)` tiling checker from starting offset `n`. -/ |
| 47 | def contiguousFrom : Nat → List (Nat × Nat) → Option Nat |
| 48 | | n, [] => some n |
| 49 | | n, (o, w) :: rest => if o == n && 0 < w then contiguousFrom (n + w) rest else none |
| 50 | |
| 51 | def toIntervals (ow : List (Nat × Nat)) : List (Nat × Nat) := |
| 52 | ow.map (fun p => (p.1, p.1 + p.2)) |
| 53 | |
| 54 | /-- Canonical 384-byte UOR-GPU-1 header fields (canonical.om + README.md). -/ |
| 55 | def uorHdrLayout : List (Nat × Nat) := |
| 56 | [ (0, 8), -- magic "UORGPU1\0" |
| 57 | (8, 4), -- version (1) |
| 58 | (12, 4), -- isa (1=SM121, 2=SPIRV) |
| 59 | (16, 4), -- math (1=RN, 2=FTZ) |
| 60 | (20, 4), -- claimed level (0..3) |
| 61 | (24, 4), -- payload_len |
| 62 | (28, 4), -- block_x (1..1024) |
| 63 | (32, 32), -- omc_sha256 |
| 64 | (64, 32), -- source_sha256 |
| 65 | (96, 32), -- payload_sha256 |
| 66 | (128, 32), -- lean_proof_sha256 |
| 67 | (160, 32), -- replay_sha256 |
| 68 | (192, 32), -- mlbom_sha256 |
| 69 | (224, 32), -- uor_id_sha256 = SHA-256(hdr[0..224)) |
| 70 | (256, 32), -- holo_blake3 = BLAKE3(hdr[0..256) || payload) |
| 71 | (288, 32), -- signer_pubkey |
| 72 | (320, 64) -- attest_sig = Ed25519(hdr[224..288)) |
| 73 | ] |
| 74 | |
| 75 | /-- Local trust anchors UORTRST1 fixed prefix (104 bytes before 1..16 x 32B signer keys). -/ |
| 76 | def uorTrstBaseLayout : List (Nat × Nat) := |
| 77 | [ (0, 8), -- magic "UORTRST1" |
| 78 | (8, 32), -- omc_sha256 pin |
| 79 | (40, 32), -- lean_proof_sha256 pin |
| 80 | (72, 32) -- authority_pubkey |
| 81 | ] |
| 82 | |
| 83 | /-- Authority-signed capability grant wire layout (128 bytes: 8 x u64 LE + 64B Ed25519 sig). -/ |
| 84 | def uorGrantLayout : List (Nat × Nat) := |
| 85 | [ (0, 8), (8, 8), (16, 8), (24, 8), (32, 8), (40, 8), (48, 8), (56, 8), (64, 64) ] |
| 86 | |
| 87 | /-- SM121 payload layout: 512B SASS machine code + 384B (96 x u32) QMD v05.00 = 896 bytes. -/ |
| 88 | def sm121PayloadLayout : List (Nat × Nat) := |
| 89 | [ (0, 512), (512, 384) ] |
| 90 | |
| 91 | theorem uorHdrLayout_tiles_384 : |
| 92 | contiguousFrom 0 uorHdrLayout = some 384 ∧ |
| 93 | allPairwiseDisjoint (toIntervals uorHdrLayout) = true ∧ |
| 94 | allValidIn 384 (toIntervals uorHdrLayout) = true := by |
| 95 | decide |
| 96 | |
| 97 | theorem uorTrstBaseLayout_tiles_104 : |
| 98 | contiguousFrom 0 uorTrstBaseLayout = some 104 ∧ |
| 99 | allPairwiseDisjoint (toIntervals uorTrstBaseLayout) = true ∧ |
| 100 | allValidIn 104 (toIntervals uorTrstBaseLayout) = true := by |
| 101 | decide |
| 102 | |
| 103 | theorem uorTrst_size_bounds (k : Nat) (h1 : 1 ≤ k) (h16 : k ≤ 16) : |
| 104 | 136 ≤ 104 + 32 * k ∧ 104 + 32 * k ≤ 616 ∧ (104 + 32 * k - 104) % 32 = 0 := by |
| 105 | omega |
| 106 | |
| 107 | theorem uorGrantLayout_tiles_128 : |
| 108 | contiguousFrom 0 uorGrantLayout = some 128 ∧ |
| 109 | allPairwiseDisjoint (toIntervals uorGrantLayout) = true ∧ |
| 110 | allValidIn 128 (toIntervals uorGrantLayout) = true := by |
| 111 | decide |
| 112 | |
| 113 | theorem sm121PayloadLayout_tiles_896 : |
| 114 | contiguousFrom 0 sm121PayloadLayout = some 896 ∧ |
| 115 | allPairwiseDisjoint (toIntervals sm121PayloadLayout) = true ∧ |
| 116 | allValidIn 896 (toIntervals sm121PayloadLayout) = true := by |
| 117 | decide |
| 118 | |
| 119 | /-- Negative control: overlapping header fields are caught by `allPairwiseDisjoint` and `contiguousFrom`. -/ |
| 120 | def brokenOverlapLayout : List (Nat × Nat) := [(0, 8), (6, 4), (10, 4)] |
| 121 | |
| 122 | theorem neg_overlapping_layout_detected : |
| 123 | allPairwiseDisjoint (toIntervals brokenOverlapLayout) = false ∧ |
| 124 | contiguousFrom 0 brokenOverlapLayout = none := by |
| 125 | decide |
| 126 | |
| 127 | /-! ## 2. Bit-Exact `BitVec` Encodings, Round-Trips, Injectivity & Opcode Disjointness -/ |
| 128 | |
| 129 | /-- Little-endian 32-bit pack/unpack (matches `uor_put_u32` / `uor_get_u32` in canonical.om). -/ |
| 130 | def le32Pack (b0 b1 b2 b3 : BitVec 8) : BitVec 32 := |
| 131 | b0.zeroExtend 32 ||| (b1.zeroExtend 32 <<< 8) ||| (b2.zeroExtend 32 <<< 16) ||| (b3.zeroExtend 32 <<< 24) |
| 132 | |
| 133 | def le32Byte (w : BitVec 32) (i : Fin 4) : BitVec 8 := |
| 134 | match i with |
| 135 | | ⟨0, _⟩ => w.extractLsb' 0 8 |
| 136 | | ⟨1, _⟩ => w.extractLsb' 8 8 |
| 137 | | ⟨2, _⟩ => w.extractLsb' 16 8 |
| 138 | | ⟨3, _⟩ => w.extractLsb' 24 8 |
| 139 | |
| 140 | theorem le32_byte_roundtrip (b0 b1 b2 b3 : BitVec 8) : |
| 141 | le32Byte (le32Pack b0 b1 b2 b3) ⟨0, by decide⟩ = b0 ∧ |
| 142 | le32Byte (le32Pack b0 b1 b2 b3) ⟨1, by decide⟩ = b1 ∧ |
| 143 | le32Byte (le32Pack b0 b1 b2 b3) ⟨2, by decide⟩ = b2 ∧ |
| 144 | le32Byte (le32Pack b0 b1 b2 b3) ⟨3, by decide⟩ = b3 := by |
| 145 | refine ⟨?_, ?_, ?_, ?_⟩ |
| 146 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 147 | simp [le32Byte, le32Pack, hi, show i < 32 by omega, |
| 148 | show i < 16 by omega, show i < 24 by omega] |
| 149 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 150 | simp [le32Byte, le32Pack, hi, show 8 + i < 32 by omega, |
| 151 | show ¬(8 + i < 8) by omega, show 8 + i < 16 by omega, show 8 + i < 24 by omega] |
| 152 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 153 | have h0 : b0.getLsbD (16 + i) = false := BitVec.getLsbD_of_ge b0 (16 + i) (by omega) |
| 154 | have h1 : b1.getLsbD (16 + i - 8) = false := BitVec.getLsbD_of_ge b1 (16 + i - 8) (by omega) |
| 155 | simp [le32Byte, le32Pack, hi, h0, h1, show 16 + i < 32 by omega, |
| 156 | show ¬(16 + i < 8) by omega, show ¬(16 + i < 16) by omega, show 16 + i < 24 by omega] |
| 157 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 158 | have h0 : b0.getLsbD (24 + i) = false := BitVec.getLsbD_of_ge b0 (24 + i) (by omega) |
| 159 | have h1 : b1.getLsbD (24 + i - 8) = false := BitVec.getLsbD_of_ge b1 (24 + i - 8) (by omega) |
| 160 | have h2 : b2.getLsbD (24 + i - 16) = false := BitVec.getLsbD_of_ge b2 (24 + i - 16) (by omega) |
| 161 | simp [le32Byte, le32Pack, hi, h0, h1, h2, show 24 + i < 32 by omega, |
| 162 | show ¬(24 + i < 8) by omega, show ¬(24 + i < 16) by omega, show ¬(24 + i < 24) by omega] |
| 163 | |
| 164 | theorem le32Pack_injective {a0 a1 a2 a3 b0 b1 b2 b3 : BitVec 8} |
| 165 | (h : le32Pack a0 a1 a2 a3 = le32Pack b0 b1 b2 b3) : |
| 166 | a0 = b0 ∧ a1 = b1 ∧ a2 = b2 ∧ a3 = b3 := by |
| 167 | have ha := le32_byte_roundtrip a0 a1 a2 a3 |
| 168 | have hb := le32_byte_roundtrip b0 b1 b2 b3 |
| 169 | refine ⟨?_, ?_, ?_, ?_⟩ |
| 170 | · rw [← ha.1, ← hb.1, h] |
| 171 | · rw [← ha.2.1, ← hb.2.1, h] |
| 172 | · rw [← ha.2.2.1, ← hb.2.2.1, h] |
| 173 | · rw [← ha.2.2.2, ← hb.2.2.2, h] |
| 174 | |
| 175 | /-- Blackwell QMD v5 Word 34 (`threads_x | (threads_y << 16)`, matches om/gpu/bw_qmd.om:122). -/ |
| 176 | def packQmdW34 (tx ty : BitVec 16) : BitVec 32 := |
| 177 | tx.zeroExtend 32 ||| (ty.zeroExtend 32 <<< 16) |
| 178 | |
| 179 | def decQmdTx (w34 : BitVec 32) : BitVec 16 := w34.extractLsb' 0 16 |
| 180 | def decQmdTy (w34 : BitVec 32) : BitVec 16 := w34.extractLsb' 16 16 |
| 181 | |
| 182 | theorem dec_packQmdW34 (tx ty : BitVec 16) : |
| 183 | decQmdTx (packQmdW34 tx ty) = tx ∧ decQmdTy (packQmdW34 tx ty) = ty := by |
| 184 | constructor |
| 185 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 186 | simp [decQmdTx, packQmdW34, hi, show i < 32 by omega] |
| 187 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 188 | simp [decQmdTy, packQmdW34, hi, show 16 + i < 32 by omega, show ¬(16 + i < 16) by omega] |
| 189 | |
| 190 | theorem packQmdW34_injective {tx1 ty1 tx2 ty2 : BitVec 16} |
| 191 | (h : packQmdW34 tx1 ty1 = packQmdW34 tx2 ty2) : tx1 = tx2 ∧ ty1 = ty2 := by |
| 192 | have h1 := dec_packQmdW34 tx1 ty1 |
| 193 | have h2 := dec_packQmdW34 tx2 ty2 |
| 194 | exact ⟨by rw [← h1.1, ← h2.1, h], by rw [← h1.2, ← h2.2, h]⟩ |
| 195 | |
| 196 | /-- Blackwell QMD v5 Word 35 (`1 | (gpr << 8) | (1 << 17)`, matches om/gpu/bw_qmd.om:123). -/ |
| 197 | def packQmdW35 (gpr : BitVec 9) : BitVec 32 := |
| 198 | 1#32 ||| (gpr.zeroExtend 32 <<< 8) ||| (1#32 <<< 17) |
| 199 | |
| 200 | def decQmdGpr (w35 : BitVec 32) : BitVec 9 := w35.extractLsb' 8 9 |
| 201 | |
| 202 | theorem dec_packQmdW35 (gpr : BitVec 9) : decQmdGpr (packQmdW35 gpr) = gpr := by |
| 203 | have h17all : ∀ j : Fin 9, (131072#32).getLsbD (8 + j.val) = false := by decide |
| 204 | apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 205 | have h17 : (131072#32)[8 + i] = false := h17all ⟨i, hi⟩ |
| 206 | simp [decQmdGpr, packQmdW35, hi, h17, show 8 + i < 32 by omega, show ¬(8 + i < 8) by omega] |
| 207 | |
| 208 | /-- Blackwell QMD v5 Word 36 SMEM config (`(sc<<23) | (26<<17) | (sc<<11) | s7`, om/gpu/bw_qmd.om:143). -/ |
| 209 | def packQmdW36 (sc : BitVec 5) (s7 : BitVec 11) : BitVec 32 := |
| 210 | (sc.zeroExtend 32 <<< 23) ||| (26#32 <<< 17) ||| (sc.zeroExtend 32 <<< 11) ||| s7.zeroExtend 32 |
| 211 | |
| 212 | def smemCfgFor (sb : Nat) : Nat := |
| 213 | if sb ≤ 32768 then 9 else if sb ≤ 65536 then 17 else 26 |
| 214 | |
| 215 | theorem smemCfgFor_bounds (sb : Nat) : |
| 216 | (sb ≤ 32768 → smemCfgFor sb = 9) ∧ |
| 217 | (32768 < sb ∧ sb ≤ 65536 → smemCfgFor sb = 17) ∧ |
| 218 | (65536 < sb → smemCfgFor sb = 26) ∧ |
| 219 | smemCfgFor sb ≤ 26 := by |
| 220 | by_cases h1 : sb ≤ 32768 <;> by_cases h2 : sb ≤ 65536 <;> |
| 221 | simp [smemCfgFor, h1, h2] <;> omega |
| 222 | |
| 223 | /-- Exact Blackwell QMD v05.00 hardware constants verified against om/gpu/bw_qmd.om. -/ |
| 224 | theorem qmd_reference_words : |
| 225 | ((0x2f5003a4#32).extractLsb' 20 4 = 5#4) ∧ -- word 14: VERSION_MAJOR == 5 |
| 226 | ((0x013f0000#32).extractLsb' 23 3 = 2#3) ∧ -- word 4: QMD_TYPE == 2 (GRID_CTA) |
| 227 | ((0x10300011#32).extractLsb' 0 1 = 1#1) ∧ -- word 58: CB0 valid bit |
| 228 | (packQmdW36 9#5 8#11 = 0x04b44808#32) ∧ -- word 36 for shared_bytes = 0 (bw_qmd.om:6) |
| 229 | (packQmdW34 256#16 1#16 = 0x00010100#32) ∧ -- word 34 for block_x = 256, ty = 1 |
| 230 | (packQmdW35 16#9 = 0x00021001#32) := by -- word 35 for gpr_count = 16 |
| 231 | decide |
| 232 | |
| 233 | /-- SM121 SASS word 0 bitfield layout: `[11:0]=op12, [15:12]=pred, [23:16]=rd, [31:24]=ra`. -/ |
| 234 | def packSassW0 (op12 : BitVec 12) (pred : BitVec 4) (rd ra : BitVec 8) : BitVec 32 := |
| 235 | op12.zeroExtend 32 ||| (pred.zeroExtend 32 <<< 12) ||| |
| 236 | (rd.zeroExtend 32 <<< 16) ||| (ra.zeroExtend 32 <<< 24) |
| 237 | |
| 238 | def decSassOp12 (w0 : BitVec 32) : BitVec 12 := w0.extractLsb' 0 12 |
| 239 | def decSassPred (w0 : BitVec 32) : BitVec 4 := w0.extractLsb' 12 4 |
| 240 | def decSassRd (w0 : BitVec 32) : BitVec 8 := w0.extractLsb' 16 8 |
| 241 | def decSassRa (w0 : BitVec 32) : BitVec 8 := w0.extractLsb' 24 8 |
| 242 | |
| 243 | theorem dec_packSassW0 (op12 : BitVec 12) (pred : BitVec 4) (rd ra : BitVec 8) : |
| 244 | decSassOp12 (packSassW0 op12 pred rd ra) = op12 ∧ |
| 245 | decSassPred (packSassW0 op12 pred rd ra) = pred ∧ |
| 246 | decSassRd (packSassW0 op12 pred rd ra) = rd ∧ |
| 247 | decSassRa (packSassW0 op12 pred rd ra) = ra := by |
| 248 | refine ⟨?_, ?_, ?_, ?_⟩ |
| 249 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 250 | simp [decSassOp12, packSassW0, hi, show i < 32 by omega, |
| 251 | show i < 16 by omega, show i < 24 by omega] |
| 252 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 253 | simp [decSassPred, packSassW0, hi, show 12 + i < 32 by omega, |
| 254 | show ¬(12 + i < 12) by omega, show 12 + i < 16 by omega, show 12 + i < 24 by omega] |
| 255 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 256 | have hop : op12.getLsbD (16 + i) = false := BitVec.getLsbD_of_ge op12 (16 + i) (by omega) |
| 257 | have hpr : pred.getLsbD (16 + i - 12) = false := BitVec.getLsbD_of_ge pred (16 + i - 12) (by omega) |
| 258 | simp [decSassRd, packSassW0, hi, hop, hpr, show 16 + i < 32 by omega, |
| 259 | show ¬(16 + i < 12) by omega, show ¬(16 + i < 16) by omega, show 16 + i < 24 by omega] |
| 260 | · apply BitVec.eq_of_getLsbD_eq; intro i hi |
| 261 | have hop : op12.getLsbD (24 + i) = false := BitVec.getLsbD_of_ge op12 (24 + i) (by omega) |
| 262 | have hpr : pred.getLsbD (24 + i - 12) = false := BitVec.getLsbD_of_ge pred (24 + i - 12) (by omega) |
| 263 | have hrd : rd.getLsbD (24 + i - 16) = false := BitVec.getLsbD_of_ge rd (24 + i - 16) (by omega) |
| 264 | simp [decSassRa, packSassW0, hi, hop, hpr, hrd, show 24 + i < 32 by omega, |
| 265 | show ¬(24 + i < 12) by omega, show ¬(24 + i < 16) by omega, show ¬(24 + i < 24) by omega] |
| 266 | |
| 267 | theorem packSassW0_injective {o1 o2 : BitVec 12} {p1 p2 : BitVec 4} {d1 d2 a1 a2 : BitVec 8} |
| 268 | (h : packSassW0 o1 p1 d1 a1 = packSassW0 o2 p2 d2 a2) : |
| 269 | o1 = o2 ∧ p1 = p2 ∧ d1 = d2 ∧ a1 = a2 := by |
| 270 | have h1 := dec_packSassW0 o1 p1 d1 a1 |
| 271 | have h2 := dec_packSassW0 o2 p2 d2 a2 |
| 272 | exact ⟨by rw [← h1.1, ← h2.1, h], by rw [← h1.2.1, ← h2.2.1, h], |
| 273 | by rw [← h1.2.2.1, ← h2.2.2.1, h], by rw [← h1.2.2.2, ← h2.2.2.2, h]⟩ |
| 274 | |
| 275 | /-- Spot-check exact `w0` encodings emitted by `om/gpu/bw_vecadd.om` and decoded by `payload_vm.om`. -/ |
| 276 | theorem sass_vecadd_reference_w0 : |
| 277 | packSassW0 0xb82#12 7#4 1#8 0xff#8 = 0xff017b82#32 ∧ -- LDC R1, c[0x0][0x37c] |
| 278 | packSassW0 0x919#12 7#4 9#8 0#8 = 0x00097919#32 ∧ -- S2R R9, SR_CTAID.X |
| 279 | packSassW0 0x7ac#12 7#4 4#8 0xff#8 = 0xff0477ac#32 ∧ -- LDCU UR4, c[0x0][0x360] |
| 280 | packSassW0 0x919#12 7#4 0#8 0#8 = 0x00007919#32 ∧ -- S2R R0, SR_TID.X |
| 281 | packSassW0 0xc24#12 7#4 9#8 9#8 = 0x09097c24#32 ∧ -- IMAD R9, R9, UR4, R0 |
| 282 | packSassW0 0xc0c#12 7#4 0#8 9#8 = 0x09007c0c#32 ∧ -- ISETP.GE.U32 P0, PT, R9, UR5, PT |
| 283 | packSassW0 0x94d#12 0#4 0#8 0#8 = 0x0000094d#32 ∧ -- @P0 EXIT |
| 284 | packSassW0 0x825#12 7#4 2#8 9#8 = 0x09027825#32 ∧ -- IMAD.WIDE.U32 R2, R9, 0x4, R2 |
| 285 | packSassW0 0x981#12 7#4 2#8 2#8 = 0x02027981#32 ∧ -- LDG.E R2, desc[UR4][R2.64] |
| 286 | packSassW0 0x210#12 7#4 9#8 2#8 = 0x02097210#32 ∧ -- IADD3 R9, PT, PT, R2, R5, RZ |
| 287 | packSassW0 0x986#12 7#4 0#8 6#8 = 0x06007986#32 ∧ -- STG.E desc[UR4][R6.64], R9 |
| 288 | packSassW0 0x94d#12 7#4 0#8 0#8 = 0x0000794d#32 ∧ -- EXIT |
| 289 | packSassW0 0x918#12 7#4 0#8 0#8 = 0x00007918#32 := by -- NOP |
| 290 | decide |
| 291 | |
| 292 | /-- All 13 SM121 opcodes dispatched by `payload_vm.om` are pairwise distinct. -/ |
| 293 | def sm121Opcodes : List (BitVec 12) := |
| 294 | [0x918#12, 0x94d#12, 0x947#12, 0x919#12, 0xb82#12, 0x7ac#12, |
| 295 | 0x981#12, 0x986#12, 0xc24#12, 0x825#12, 0xc0c#12, 0x210#12, 0x221#12] |
| 296 | |
| 297 | def allDistinctBv12 : List (BitVec 12) → Bool |
| 298 | | [] => true |
| 299 | | x :: xs => xs.all (fun y => x != y) && allDistinctBv12 xs |
| 300 | |
| 301 | theorem sm121_opcodes_pairwise_disjoint : allDistinctBv12 sm121Opcodes = true := by |
| 302 | decide |
| 303 | |
| 304 | /-- Negative control: unmasked 32-bit `tx` in QMD word 34 overflows into `ty` bits [31:16]. -/ |
| 305 | def brokenPackQmdW34 (tx ty : BitVec 32) : BitVec 32 := tx ||| (ty <<< 16) |
| 306 | |
| 307 | theorem neg_unmasked_qmd_w34_corrupts_ty : |
| 308 | ∃ tx ty : BitVec 32, decQmdTy (brokenPackQmdW34 tx ty) ≠ ty.extractLsb' 0 16 := by |
| 309 | exact ⟨0x00010100#32, 0#32, by decide⟩ |
| 310 | |
| 311 | /-! ## 3. Multi-Thread Bounded GPU Kernel Model & Canary Preservation -/ |
| 312 | |
| 313 | def vecaddStep (n tid : Nat) (a b out : Nat → Nat) : Nat → Nat := |
| 314 | if tid < n then |
| 315 | fun i => if i = tid then a tid + b tid else out i |
| 316 | else |
| 317 | out |
| 318 | |
| 319 | theorem vecadd_in_bounds_writes_sum (n tid : Nat) (a b out : Nat → Nat) (h : tid < n) : |
| 320 | vecaddStep n tid a b out tid = a tid + b tid := by |
| 321 | simp [vecaddStep, h] |
| 322 | |
| 323 | theorem vecadd_preserves_other_indices (n tid i : Nat) (a b out : Nat → Nat) (hne : i ≠ tid) : |
| 324 | vecaddStep n tid a b out i = out i := by |
| 325 | unfold vecaddStep |
| 326 | split |
| 327 | · simp [hne] |
| 328 | · rfl |
| 329 | |
| 330 | theorem vecadd_oob_noop (n tid i : Nat) (a b out : Nat → Nat) (hoob : ¬ tid < n) : |
| 331 | vecaddStep n tid a b out i = out i := by |
| 332 | simp [vecaddStep, hoob] |
| 333 | |
| 334 | theorem vecadd_comm (n tid i : Nat) (a b out : Nat → Nat) : |
| 335 | vecaddStep n tid a b out i = vecaddStep n tid b a out i := by |
| 336 | unfold vecaddStep |
| 337 | split |
| 338 | · dsimp |
| 339 | split |
| 340 | · exact Nat.add_comm (a tid) (b tid) |
| 341 | · rfl |
| 342 | · rfl |
| 343 | |
| 344 | /-- Multi-thread CTA launch executing threads `0, 1, ..., k - 1` (models `UOR_REPLAY_THREADS = 12` |
| 345 | over `UOR_REPLAY_N = 8` elements + 4 OOB threads). -/ |
| 346 | def runVecadd (n : Nat) : Nat → (Nat → Nat) → (Nat → Nat) → (Nat → Nat) → (Nat → Nat) |
| 347 | | 0, _, _, init => init |
| 348 | | k + 1, a, b, init => vecaddStep n k a b (runVecadd n k a b init) |
| 349 | |
| 350 | theorem runVecadd_result (n k : Nat) (a b init : Nat → Nat) (i : Nat) : |
| 351 | runVecadd n k a b init i = if i < k ∧ i < n then a i + b i else init i := by |
| 352 | induction k with |
| 353 | | zero => simp [runVecadd] |
| 354 | | succ k ih => |
| 355 | unfold runVecadd vecaddStep |
| 356 | by_cases hkn : k < n |
| 357 | · simp only [hkn, ↓reduceIte] |
| 358 | by_cases hik : i = k |
| 359 | · subst hik; simp [hkn] |
| 360 | · simp only [hik, ↓reduceIte, ih] |
| 361 | have hiff : (i < k ∧ i < n) ↔ (i < k + 1 ∧ i < n) := by omega |
| 362 | simp [hiff] |
| 363 | · simp only [hkn, ↓reduceIte, ih] |
| 364 | have hiff : (i < k ∧ i < n) ↔ (i < k + 1 ∧ i < n) := by omega |
| 365 | simp [hiff] |
| 366 | |
| 367 | /-- Every in-bounds output slot holds `a[i] + b[i]` once `k ≥ n` threads run. -/ |
| 368 | theorem runVecadd_in_bounds (n k : Nat) (a b init : Nat → Nat) (i : Nat) |
| 369 | (hi : i < n) (hk : n ≤ k) : |
| 370 | runVecadd n k a b init i = a i + b i := by |
| 371 | rw [runVecadd_result] |
| 372 | have : i < k ∧ i < n := ⟨by omega, hi⟩ |
| 373 | simp [this] |
| 374 | |
| 375 | /-- Every OOB guard canary slot (`i ≥ n`) stays untouched regardless of how many OOB threads run. -/ |
| 376 | theorem runVecadd_preserves_canaries (n k : Nat) (a b init : Nat → Nat) (i : Nat) (hoob : n ≤ i) : |
| 377 | runVecadd n k a b init i = init i := by |
| 378 | rw [runVecadd_result] |
| 379 | have : ¬ (i < k ∧ i < n) := by omega |
| 380 | simp [this] |
| 381 | |
| 382 | /-- Negative control: an unguarded kernel writes out-of-bounds and clobbers canary slot `tid = n`. -/ |
| 383 | def brokenVecaddStep (tid : Nat) (a b out : Nat → Nat) : Nat → Nat := |
| 384 | fun i => if i = tid then a tid + b tid else out i |
| 385 | |
| 386 | theorem broken_vecadd_violates_oob : |
| 387 | ∃ n tid a b out, ¬ tid < n ∧ brokenVecaddStep tid a b out tid ≠ out tid := by |
| 388 | refine ⟨4, 4, (fun _ => 1), (fun _ => 1), (fun _ => 0), by decide, by decide⟩ |
| 389 | |
| 390 | theorem neg_unguarded_clobbers_canary : |
| 391 | ∃ a b, brokenVecaddStep 8 a b (fun _ => 0xdeadbeef) 8 ≠ 0xdeadbeef := by |
| 392 | refine ⟨fun _ => 10, fun _ => 20, by decide⟩ |
| 393 | |
| 394 | /-! ## 4. Two-Stage Hash-Commitment Tamper Evidence (canonical.om `uor_hdr_seal`) -/ |
| 395 | |
| 396 | /-- Abstract bundle commitment matching `uor_hdr_seal`: |
| 397 | `uorId = hSha (meta, hShaPay pay)` and `holo = hB3 (meta, uorId, pay)`. |
| 398 | Collision resistance of SHA-256 and BLAKE3 is stated explicitly as a hypothesis (Ledger.lean style). -/ |
| 399 | structure SealedBundle (M P D : Type) where |
| 400 | metaFields : M -- header[0..96) + header[128..224): meta, omc_pin, source, lean, replay, mlbom |
| 401 | payload : P -- emitted SM121 SASS+QMD v5 or SPIR-V bytes |
| 402 | payHash : D -- header[96..128) |
| 403 | uorId : D -- header[224..256) |
| 404 | holoSeal : D -- header[256..288) |
| 405 | |
| 406 | def ValidSeal {M P D : Type} (hPay : P → D) (hUor : M → D → D) (hHolo : M → D → P → D) |
| 407 | (b : SealedBundle M P D) : Prop := |
| 408 | b.payHash = hPay b.payload ∧ |
| 409 | b.uorId = hUor b.metaFields b.payHash ∧ |
| 410 | b.holoSeal = hHolo b.metaFields b.uorId b.payload |
| 411 | |
| 412 | /-- Equal `uor_id_sha256` fixes both all canonical metadata fields and the exact payload bytes. -/ |
| 413 | theorem uor_id_tamper_evident {M P D : Type} |
| 414 | (hPay : P → D) (hUor : M → D → D) (hHolo : M → D → P → D) |
| 415 | (hPayInj : ∀ p1 p2, hPay p1 = hPay p2 → p1 = p2) |
| 416 | (hUorInj : ∀ m1 d1 m2 d2, hUor m1 d1 = hUor m2 d2 → m1 = m2 ∧ d1 = d2) |
| 417 | (b1 b2 : SealedBundle M P D) |
| 418 | (v1 : ValidSeal hPay hUor hHolo b1) (v2 : ValidSeal hPay hUor hHolo b2) |
| 419 | (heq : b1.uorId = b2.uorId) : |
| 420 | b1.metaFields = b2.metaFields ∧ b1.payload = b2.payload := by |
| 421 | rw [v1.2.1, v2.2.1] at heq |
| 422 | obtain ⟨hm, hd⟩ := hUorInj _ _ _ _ heq |
| 423 | rw [v1.1, v2.1] at hd |
| 424 | exact ⟨hm, hPayInj _ _ hd⟩ |
| 425 | |
| 426 | /-- Equal `.holo` BLAKE3 seal fixes metadata, `uor_id_sha256`, and payload bytes simultaneously. -/ |
| 427 | theorem holo_seal_tamper_evident {M P D : Type} |
| 428 | (hPay : P → D) (hUor : M → D → D) (hHolo : M → D → P → D) |
| 429 | (hHoloInj : ∀ m1 u1 p1 m2 u2 p2, hHolo m1 u1 p1 = hHolo m2 u2 p2 → m1 = m2 ∧ u1 = u2 ∧ p1 = p2) |
| 430 | (b1 b2 : SealedBundle M P D) |
| 431 | (v1 : ValidSeal hPay hUor hHolo b1) (v2 : ValidSeal hPay hUor hHolo b2) |
| 432 | (heq : b1.holoSeal = b2.holoSeal) : |
| 433 | b1.metaFields = b2.metaFields ∧ b1.uorId = b2.uorId ∧ b1.payload = b2.payload := by |
| 434 | rw [v1.2.2, v2.2.2] at heq |
| 435 | exact hHoloInj _ _ _ _ _ _ heq |
| 436 | |
| 437 | /-! ## 5. Blackwell QMD v5 SKEDCHECK05, Trust-Anchor Separation & Reason-Coded Admission -/ |
| 438 | |
| 439 | structure QmdV5 where |
| 440 | versionMajor : Nat -- (q[14] >> 20) & 0xf == 5 |
| 441 | qmdType : Nat -- (q[4] >> 23) & 0x7 == 2 (GRID_CTA) |
| 442 | word37 : Nat -- q[37] == 0 |
| 443 | semEnable : Nat -- q[17] != 0 |
| 444 | prefetchTag : Nat -- (q[33] >> 21) & 0x1ff == 0xa |
| 445 | cb0Valid : Bool -- (q[58] & 1) != 0 |
| 446 | threadsX : Nat -- q[34] & 0xffff == hdr.block_x |
| 447 | threadsY : Nat -- (q[34] >> 16) & 0xffff >= 1 |
| 448 | gridX : Nat -- q[39] >= 1 |
| 449 | gridY : Nat -- q[40] >= 1 |
| 450 | gridZ : Nat -- q[41] >= 1 |
| 451 | gprCount : Nat -- (q[35] >> 8) & 0x1ff >= 16 |
| 452 | codeVaNonZero : Bool -- q[32] != 0 |
| 453 | cbankVaNonZero : Bool -- q[42] != 0 |
| 454 | deriving DecidableEq |
| 455 | |
| 456 | def qmdV5Valid (hdrBlockX : Nat) (q : QmdV5) : Bool := |
| 457 | decide (q.versionMajor = 5) && |
| 458 | decide (q.qmdType = 2) && |
| 459 | decide (q.word37 = 0) && |
| 460 | decide (q.semEnable ≠ 0) && |
| 461 | decide (q.prefetchTag = 10) && |
| 462 | q.cb0Valid && |
| 463 | decide (q.threadsX = hdrBlockX) && |
| 464 | decide (q.threadsY ≥ 1) && |
| 465 | decide (q.gridX ≥ 1) && |
| 466 | decide (q.gridY ≥ 1) && |
| 467 | decide (q.gridZ ≥ 1) && |
| 468 | decide (q.gprCount ≥ 16) && |
| 469 | q.codeVaNonZero && |
| 470 | q.cbankVaNonZero |
| 471 | |
| 472 | theorem qmd_valid_enforces_skedcheck05 (bx : Nat) (q : QmdV5) |
| 473 | (h : qmdV5Valid bx q = true) : |
| 474 | q.versionMajor = 5 ∧ q.qmdType = 2 ∧ q.word37 = 0 ∧ |
| 475 | q.prefetchTag = 10 ∧ q.cb0Valid = true ∧ q.threadsX = bx ∧ q.gprCount ≥ 16 := by |
| 476 | unfold qmdV5Valid at h |
| 477 | simp only [Bool.and_eq_true, decide_eq_true_eq] at h |
| 478 | exact ⟨h.1.1.1.1.1.1.1.1.1.1.1.1.1, h.1.1.1.1.1.1.1.1.1.1.1.1.2, |
| 479 | h.1.1.1.1.1.1.1.1.1.1.1.2, h.1.1.1.1.1.1.1.1.1.2, |
| 480 | h.1.1.1.1.1.1.1.1.2, h.1.1.1.1.1.1.1.2, h.1.1.2⟩ |
| 481 | |
| 482 | theorem qmd_wrong_version_refused (bx : Nat) (q : QmdV5) (hv : q.versionMajor ≠ 5) : |
| 483 | qmdV5Valid bx q = false := by |
| 484 | simp [qmdV5Valid, hv] |
| 485 | |
| 486 | theorem qmd_blockx_mismatch_refused (bx : Nat) (q : QmdV5) (hm : q.threadsX ≠ bx) : |
| 487 | qmdV5Valid bx q = false := by |
| 488 | simp [qmdV5Valid, hm] |
| 489 | |
| 490 | /-- Local trust anchors model (verify.om `uor_anchors_nkeys`): non-zero pins, 1..16 non-zero signer |
| 491 | keys, and strict separation of privilege (`authorityKey ≠ signerKey` for every trusted signer). -/ |
| 492 | structure TrustAnchors where |
| 493 | omcPin : Nat |
| 494 | leanPin : Nat |
| 495 | authorityKey : Nat |
| 496 | signerKeys : List Nat |
| 497 | deriving DecidableEq |
| 498 | |
| 499 | def anchorsWellFormed (a : TrustAnchors) : Bool := |
| 500 | decide (a.omcPin ≠ 0) && |
| 501 | decide (a.leanPin ≠ 0) && |
| 502 | decide (1 ≤ a.signerKeys.length) && |
| 503 | decide (a.signerKeys.length ≤ 16) && |
| 504 | a.signerKeys.all (fun k => decide (k ≠ 0) && decide (k ≠ a.authorityKey)) |
| 505 | |
| 506 | /-- Separation of privilege: a bundle signer key in valid trust anchors can never equal the |
| 507 | capability authority key (so a bundle signer can never mint its own capability grant). -/ |
| 508 | theorem anchors_separate_authority_and_signer (a : TrustAnchors) (k : Nat) |
| 509 | (hwf : anchorsWellFormed a = true) (hmem : k ∈ a.signerKeys) : |
| 510 | k ≠ 0 ∧ k ≠ a.authorityKey := by |
| 511 | unfold anchorsWellFormed at hwf |
| 512 | simp only [Bool.and_eq_true, List.all_eq_true, decide_eq_true_eq] at hwf |
| 513 | exact hwf.2 k hmem |
| 514 | |
| 515 | /-- Negative control: anchors where the authority key appears as a bundle signer are refused. -/ |
| 516 | theorem neg_shared_auth_signer_refused : |
| 517 | anchorsWellFormed ⟨1, 2, 42, [42]⟩ = false := by |
| 518 | decide |
| 519 | |
| 520 | /-- Exact reason codes matching `protocol/uor-gpu/canonical.om` constants 0..20. -/ |
| 521 | inductive ReasonCode where |
| 522 | | pass -- 0 |
| 523 | | badMagic -- 1 |
| 524 | | badTarget -- 2 |
| 525 | | payloadTamper -- 3 |
| 526 | | uorIdTamper -- 4 |
| 527 | | holoTamper -- 5 |
| 528 | | omcPin -- 6 |
| 529 | | levelLow -- 7 |
| 530 | | noLeanProof -- 8 |
| 531 | | noReplay -- 9 |
| 532 | | capDenied -- 10 |
| 533 | | badSig -- 11 |
| 534 | | replayMismatch -- 12 |
| 535 | | untrustedSigner -- 13 |
| 536 | | leanUnpinned -- 14 |
| 537 | | badAnchors -- 15 |
| 538 | | badGrant -- 16 |
| 539 | | unsignedLevel -- 17 |
| 540 | | badQmd -- 18 |
| 541 | | badSpirv -- 19 |
| 542 | | replayFault -- 20 |
| 543 | deriving DecidableEq, Repr |
| 544 | |
| 545 | def ReasonCode.code : ReasonCode → Nat |
| 546 | | .pass => 0 |
| 547 | | .badMagic => 1 |
| 548 | | .badTarget => 2 |
| 549 | | .payloadTamper => 3 |
| 550 | | .uorIdTamper => 4 |
| 551 | | .holoTamper => 5 |
| 552 | | .omcPin => 6 |
| 553 | | .levelLow => 7 |
| 554 | | .noLeanProof => 8 |
| 555 | | .noReplay => 9 |
| 556 | | .capDenied => 10 |
| 557 | | .badSig => 11 |
| 558 | | .replayMismatch => 12 |
| 559 | | .untrustedSigner => 13 |
| 560 | | .leanUnpinned => 14 |
| 561 | | .badAnchors => 15 |
| 562 | | .badGrant => 16 |
| 563 | | .unsignedLevel => 17 |
| 564 | | .badQmd => 18 |
| 565 | | .badSpirv => 19 |
| 566 | | .replayFault => 20 |
| 567 | |
| 568 | structure BundleVerdict where |
| 569 | anchorsValid : Bool |
| 570 | payloadNonEmpty : Bool |
| 571 | blockXValid : Bool |
| 572 | payloadStructOk : Bool |
| 573 | payloadOk : Bool |
| 574 | uorIdOk : Bool |
| 575 | holoBlake3Ok : Bool |
| 576 | omcPinOk : Bool |
| 577 | level : Nat |
| 578 | hasLeanProof : Bool |
| 579 | leanProofPinned : Bool |
| 580 | hasReplay : Bool |
| 581 | replayExecOk : Bool |
| 582 | replayMatch : Bool |
| 583 | hasSig : Bool |
| 584 | sigSlotZero : Bool |
| 585 | signerTrusted : Bool |
| 586 | sigValid : Bool |
| 587 | deriving DecidableEq |
| 588 | |
| 589 | structure CapGrant where |
| 590 | grantSigValid : Bool |
| 591 | live : Bool |
| 592 | genNonZero : Bool |
| 593 | genMatch : Bool |
| 594 | epochMatch : Bool |
| 595 | leaseNonZero : Bool |
| 596 | notExpired : Bool |
| 597 | subjectMatch : Bool |
| 598 | resourceMatch : Bool |
| 599 | hasEffectRight : Bool |
| 600 | deriving DecidableEq |
| 601 | |
| 602 | /-- Exact check-order evaluator matching `verify.om` (`uor_verify_policy` + `uor_verify_replay_real`). -/ |
| 603 | def evalPolicy (minLevel : Nat) (v : BundleVerdict) : ReasonCode := |
| 604 | if !v.anchorsValid then .badAnchors |
| 605 | else if !v.payloadNonEmpty then .payloadTamper |
| 606 | else if !v.blockXValid then .badTarget |
| 607 | else if !v.payloadOk then .payloadTamper |
| 608 | else if !v.uorIdOk then .uorIdTamper |
| 609 | else if !v.holoBlake3Ok then .holoTamper |
| 610 | else if !v.payloadStructOk then .badQmd |
| 611 | else if !v.omcPinOk then .omcPin |
| 612 | else if !(v.level ≤ 3) then .badTarget |
| 613 | else if !(minLevel ≤ v.level) then .levelLow |
| 614 | else if minLevel ≥ 2 ∧ !v.hasLeanProof then .noLeanProof |
| 615 | else if minLevel ≥ 2 ∧ !v.leanProofPinned then .leanUnpinned |
| 616 | else if minLevel ≥ 3 ∧ !v.hasReplay then .noReplay |
| 617 | else if !v.hasSig then |
| 618 | if minLevel ≥ 1 then .badSig |
| 619 | else if v.level ≠ 0 then .unsignedLevel |
| 620 | else if !v.sigSlotZero then .badSig |
| 621 | else .pass |
| 622 | else if !v.signerTrusted then .untrustedSigner |
| 623 | else if !v.sigValid then .badSig |
| 624 | else if minLevel ≥ 3 ∧ !v.replayExecOk then .replayFault |
| 625 | else if minLevel ≥ 3 ∧ !v.replayMatch then .replayMismatch |
| 626 | else .pass |
| 627 | |
| 628 | def verifyPolicy (minLevel : Nat) (v : BundleVerdict) : Bool := |
| 629 | v.anchorsValid && |
| 630 | v.payloadNonEmpty && v.blockXValid && v.payloadStructOk && |
| 631 | v.payloadOk && v.uorIdOk && v.holoBlake3Ok && v.omcPinOk && |
| 632 | decide (v.level ≤ 3) && |
| 633 | decide (minLevel ≤ v.level) && |
| 634 | (if minLevel ≥ 2 then v.hasLeanProof && v.leanProofPinned else true) && |
| 635 | (if minLevel ≥ 3 then v.hasReplay && v.replayExecOk && v.replayMatch else true) && |
| 636 | (if v.hasSig then |
| 637 | v.signerTrusted && v.sigValid |
| 638 | else |
| 639 | decide (minLevel = 0) && decide (v.level = 0) && v.sigSlotZero) |
| 640 | |
| 641 | def capAdmit (g : CapGrant) : Bool := |
| 642 | g.grantSigValid && g.live && g.genNonZero && g.genMatch && g.epochMatch && |
| 643 | g.leaseNonZero && g.notExpired && g.subjectMatch && g.resourceMatch && g.hasEffectRight |
| 644 | |
| 645 | def evalAdmit (v : BundleVerdict) (g : CapGrant) : ReasonCode := |
| 646 | match evalPolicy 2 v with |
| 647 | | .pass => |
| 648 | if !g.grantSigValid then .badGrant |
| 649 | else if !capAdmit g then .capDenied |
| 650 | else .pass |
| 651 | | rc => rc |
| 652 | |
| 653 | def gpuAdmitDefault (v : BundleVerdict) (g : CapGrant) : Bool := |
| 654 | verifyPolicy 2 v && capAdmit g |
| 655 | |
| 656 | /-- Exact equivalence between the reason-coded evaluator and the boolean policy predicate. -/ |
| 657 | theorem evalPolicy_pass_iff (minLevel : Nat) (v : BundleVerdict) : |
| 658 | evalPolicy minLevel v = .pass ↔ verifyPolicy minLevel v = true := by |
| 659 | cases ha : v.anchorsValid |
| 660 | · simp [evalPolicy, verifyPolicy, ha] |
| 661 | cases hne : v.payloadNonEmpty |
| 662 | · simp [evalPolicy, verifyPolicy, ha, hne] |
| 663 | cases hbx : v.blockXValid |
| 664 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx] |
| 665 | cases hp : v.payloadOk |
| 666 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp] |
| 667 | cases hu : v.uorIdOk |
| 668 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu] |
| 669 | cases hb : v.holoBlake3Ok |
| 670 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb] |
| 671 | cases hst : v.payloadStructOk |
| 672 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst] |
| 673 | cases ho : v.omcPinOk |
| 674 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho] |
| 675 | by_cases hl3 : v.level ≤ 3 |
| 676 | · by_cases hml : minLevel ≤ v.level |
| 677 | · by_cases hm2 : minLevel ≥ 2 |
| 678 | · cases hlp : v.hasLeanProof |
| 679 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp] |
| 680 | cases hlpin : v.leanProofPinned |
| 681 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin] |
| 682 | by_cases hm3 : minLevel ≥ 3 |
| 683 | · cases hr : v.hasReplay |
| 684 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hr] |
| 685 | cases hs : v.hasSig |
| 686 | · have hm1 : minLevel ≥ 1 := by omega |
| 687 | have hm0 : minLevel ≠ 0 := by omega |
| 688 | simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hr, hs, hm1, hm0] |
| 689 | cases htr : v.signerTrusted |
| 690 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hr, hs, htr] |
| 691 | cases hsv : v.sigValid |
| 692 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hr, hs, htr, hsv] |
| 693 | cases hre : v.replayExecOk |
| 694 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hr, hs, htr, hsv, hre] |
| 695 | cases hrm : v.replayMatch <;> |
| 696 | simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hr, hs, htr, hsv, hre, hrm] |
| 697 | · cases hs : v.hasSig |
| 698 | · have hm1 : minLevel ≥ 1 := by omega |
| 699 | have hm0 : minLevel ≠ 0 := by omega |
| 700 | simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hs, hm1, hm0] |
| 701 | cases htr : v.signerTrusted |
| 702 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hs, htr] |
| 703 | cases hsv : v.sigValid <;> |
| 704 | simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hlp, hlpin, hm3, hs, htr, hsv] |
| 705 | · have hm3 : ¬(minLevel ≥ 3) := by omega |
| 706 | cases hs : v.hasSig |
| 707 | · by_cases hm1 : minLevel ≥ 1 |
| 708 | · have hm0 : minLevel ≠ 0 := by omega |
| 709 | simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hm3, hs, hm1, hm0] |
| 710 | · have hm0 : minLevel = 0 := by omega |
| 711 | by_cases hl0 : v.level = 0 |
| 712 | · cases hsz : v.sigSlotZero <;> |
| 713 | simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hs, hm0, hl0, hsz] |
| 714 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hs, hm0, hl0] |
| 715 | · cases htr : v.signerTrusted |
| 716 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hm3, hs, htr] |
| 717 | cases hsv : v.sigValid <;> |
| 718 | simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml, hm2, hm3, hs, htr, hsv] |
| 719 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3, hml] |
| 720 | · simp [evalPolicy, verifyPolicy, ha, hne, hbx, hp, hu, hb, hst, ho, hl3] |
| 721 | |
| 722 | theorem evalAdmit_pass_iff (v : BundleVerdict) (g : CapGrant) : |
| 723 | evalAdmit v g = .pass ↔ gpuAdmitDefault v g = true := by |
| 724 | unfold evalAdmit gpuAdmitDefault |
| 725 | have hp := evalPolicy_pass_iff 2 v |
| 726 | cases h : evalPolicy 2 v with |
| 727 | | pass => |
| 728 | have hv : verifyPolicy 2 v = true := hp.mp h |
| 729 | cases hgs : g.grantSigValid <;> cases hc : capAdmit g <;> |
| 730 | simp_all [capAdmit] |
| 731 | | _ => |
| 732 | have hv : verifyPolicy 2 v = false := by |
| 733 | cases hv' : verifyPolicy 2 v |
| 734 | · rfl |
| 735 | · exfalso; have := hp.mpr hv'; rw [h] at this; cases this |
| 736 | simp [hv] |
| 737 | |
| 738 | /-- Policy-level monotonicity: passing a higher minimum level implies passing every lower level. -/ |
| 739 | theorem verifyPolicy_monotone {m1 m2 : Nat} {v : BundleVerdict} |
| 740 | (hle : m1 ≤ m2) (h : verifyPolicy m2 v = true) : |
| 741 | verifyPolicy m1 v = true := by |
| 742 | unfold verifyPolicy at h ⊢ |
| 743 | simp only [Bool.and_eq_true, decide_eq_true_eq] at h ⊢ |
| 744 | obtain ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨ha, hne⟩, hbx⟩, hst⟩, hp⟩, hu⟩, hb⟩, ho⟩, hl3⟩, hm2⟩, hlp⟩, hrep⟩, hsig⟩ := h |
| 745 | refine ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨ha, hne⟩, hbx⟩, hst⟩, hp⟩, hu⟩, hb⟩, ho⟩, hl3⟩, by omega⟩, ?_⟩, ?_⟩, ?_⟩ |
| 746 | · split |
| 747 | · rename_i hm1_2 |
| 748 | have hm2_2 : m2 ≥ 2 := by omega |
| 749 | simp only [hm2_2, ↓reduceIte] at hlp |
| 750 | exact hlp |
| 751 | · rfl |
| 752 | · split |
| 753 | · rename_i hm1_3 |
| 754 | have hm2_3 : m2 ≥ 3 := by omega |
| 755 | simp only [hm2_3, ↓reduceIte] at hrep |
| 756 | exact hrep |
| 757 | · rfl |
| 758 | · cases hsf : v.hasSig |
| 759 | · simp only [hsf, Bool.false_eq_true, ↓reduceIte, Bool.and_eq_true, decide_eq_true_eq] at hsig ⊢ |
| 760 | exact ⟨⟨by omega, hsig.1.2⟩, hsig.2⟩ |
| 761 | · simp only [hsf, ↓reduceIte] at hsig ⊢ |
| 762 | exact hsig |
| 763 | |
| 764 | /-- "Nothing raises a level except signing": an unsigned bundle can NEVER pass any level >= P1. -/ |
| 765 | theorem unsigned_never_above_p0 (minLevel : Nat) (v : BundleVerdict) |
| 766 | (hm : 1 ≤ minLevel) (hu : v.hasSig = false) : |
| 767 | verifyPolicy minLevel v = false := by |
| 768 | unfold verifyPolicy |
| 769 | have hne : minLevel ≠ 0 := by omega |
| 770 | simp [hu, hne] |
| 771 | |
| 772 | theorem admit_requires_pinned_lean_proof (v : BundleVerdict) (g : CapGrant) |
| 773 | (h : gpuAdmitDefault v g = true) : |
| 774 | v.hasLeanProof = true ∧ v.leanProofPinned = true := by |
| 775 | unfold gpuAdmitDefault verifyPolicy at h |
| 776 | cases hlp : v.hasLeanProof <;> cases hpin : v.leanProofPinned <;> simp [hlp, hpin] at h |
| 777 | exact ⟨rfl, rfl⟩ |
| 778 | |
| 779 | theorem admit_requires_intact_digests_and_struct (v : BundleVerdict) (g : CapGrant) |
| 780 | (h : gpuAdmitDefault v g = true) : |
| 781 | v.payloadNonEmpty = true ∧ v.blockXValid = true ∧ v.payloadStructOk = true ∧ |
| 782 | v.payloadOk = true ∧ v.uorIdOk = true ∧ v.holoBlake3Ok = true ∧ v.omcPinOk = true := by |
| 783 | unfold gpuAdmitDefault verifyPolicy at h |
| 784 | cases hne : v.payloadNonEmpty <;> cases hbx : v.blockXValid <;> |
| 785 | cases hst : v.payloadStructOk <;> cases hp : v.payloadOk <;> |
| 786 | cases hu : v.uorIdOk <;> cases hb : v.holoBlake3Ok <;> cases ho : v.omcPinOk <;> |
| 787 | simp [hne, hbx, hst, hp, hu, hb, ho] at h |
| 788 | exact ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ |
| 789 | |
| 790 | theorem admit_requires_trusted_valid_sig (v : BundleVerdict) (g : CapGrant) |
| 791 | (h : gpuAdmitDefault v g = true) : |
| 792 | v.anchorsValid = true ∧ v.hasSig = true ∧ v.signerTrusted = true ∧ v.sigValid = true := by |
| 793 | unfold gpuAdmitDefault verifyPolicy at h |
| 794 | cases ha : v.anchorsValid <;> cases hs : v.hasSig <;> |
| 795 | cases ht : v.signerTrusted <;> cases hv : v.sigValid <;> |
| 796 | simp [ha, hs, ht, hv] at h |
| 797 | exact ⟨rfl, rfl, rfl, rfl⟩ |
| 798 | |
| 799 | theorem admit_requires_authority_live_cap (v : BundleVerdict) (g : CapGrant) |
| 800 | (h : gpuAdmitDefault v g = true) : |
| 801 | g.grantSigValid = true ∧ g.live = true ∧ g.genNonZero = true ∧ |
| 802 | g.leaseNonZero = true ∧ g.notExpired = true ∧ |
| 803 | g.hasEffectRight = true ∧ g.resourceMatch = true := by |
| 804 | unfold gpuAdmitDefault capAdmit at h |
| 805 | cases hgs : g.grantSigValid <;> cases hl : g.live <;> cases hgz : g.genNonZero <;> |
| 806 | cases hlz : g.leaseNonZero <;> cases hex : g.notExpired <;> |
| 807 | cases he : g.hasEffectRight <;> cases hr : g.resourceMatch <;> |
| 808 | simp [hgs, hl, hgz, hlz, hex, he, hr] at h |
| 809 | exact ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ |
| 810 | |
| 811 | theorem invalid_payload_struct_refused (v : BundleVerdict) (g : CapGrant) |
| 812 | (hbad : v.payloadStructOk = false) : gpuAdmitDefault v g = false := by |
| 813 | simp [gpuAdmitDefault, verifyPolicy, hbad] |
| 814 | |
| 815 | theorem unsigned_p2_refused (v : BundleVerdict) (g : CapGrant) |
| 816 | (hu : v.hasSig = false) : gpuAdmitDefault v g = false := by |
| 817 | simp [gpuAdmitDefault, verifyPolicy, hu] |
| 818 | |
| 819 | theorem unsigned_nonzero_claim_refused (v : BundleVerdict) |
| 820 | (hu : v.hasSig = false) (hl : v.level ≠ 0) : verifyPolicy 0 v = false := by |
| 821 | simp [verifyPolicy, hu, hl] |
| 822 | |
| 823 | theorem unsigned_smuggled_sig_refused (v : BundleVerdict) |
| 824 | (hu : v.hasSig = false) (hsm : v.sigSlotZero = false) : verifyPolicy 0 v = false := by |
| 825 | simp [verifyPolicy, hu, hsm] |
| 826 | |
| 827 | theorem untrusted_signer_refused (v : BundleVerdict) (minLevel : Nat) |
| 828 | (hs : v.hasSig = true) (hut : v.signerTrusted = false) : verifyPolicy minLevel v = false := by |
| 829 | simp [verifyPolicy, hs, hut] |
| 830 | |
| 831 | theorem bad_sig_refused (v : BundleVerdict) (g : CapGrant) |
| 832 | (hs : v.hasSig = true) (hb : v.sigValid = false) : gpuAdmitDefault v g = false := by |
| 833 | simp [gpuAdmitDefault, verifyPolicy, hs, hb] |
| 834 | |
| 835 | theorem unpinned_lean_proof_refused (v : BundleVerdict) (g : CapGrant) |
| 836 | (hup : v.leanProofPinned = false) : gpuAdmitDefault v g = false := by |
| 837 | simp [gpuAdmitDefault, verifyPolicy, hup] |
| 838 | |
| 839 | theorem p3_replay_fault_refused (v : BundleVerdict) |
| 840 | (hf : v.replayExecOk = false) : verifyPolicy 3 v = false := by |
| 841 | simp [verifyPolicy, hf] |
| 842 | |
| 843 | theorem p3_replay_mismatch_refused (v : BundleVerdict) |
| 844 | (hrm : v.replayMatch = false) : verifyPolicy 3 v = false := by |
| 845 | simp [verifyPolicy, hrm] |
| 846 | |
| 847 | theorem missing_lean_proof_refused (v : BundleVerdict) (g : CapGrant) |
| 848 | (hno : v.hasLeanProof = false) : gpuAdmitDefault v g = false := by |
| 849 | simp [gpuAdmitDefault, verifyPolicy, hno] |
| 850 | |
| 851 | theorem tampered_payload_refused (v : BundleVerdict) (g : CapGrant) |
| 852 | (htamp : v.payloadOk = false) : gpuAdmitDefault v g = false := by |
| 853 | simp [gpuAdmitDefault, verifyPolicy, htamp] |
| 854 | |
| 855 | theorem forged_grant_refused (v : BundleVerdict) (g : CapGrant) |
| 856 | (hfg : g.grantSigValid = false) : gpuAdmitDefault v g = false := by |
| 857 | simp [gpuAdmitDefault, capAdmit, hfg] |
| 858 | |
| 859 | theorem revoked_cap_refused (v : BundleVerdict) (g : CapGrant) |
| 860 | (hrev : g.live = false) : gpuAdmitDefault v g = false := by |
| 861 | simp [gpuAdmitDefault, capAdmit, hrev] |
| 862 | |
| 863 | theorem zero_gen_cap_refused (v : BundleVerdict) (g : CapGrant) |
| 864 | (hzg : g.genNonZero = false) : gpuAdmitDefault v g = false := by |
| 865 | simp [gpuAdmitDefault, capAdmit, hzg] |
| 866 | |
| 867 | theorem zero_lease_cap_refused (v : BundleVerdict) (g : CapGrant) |
| 868 | (hzl : g.leaseNonZero = false) : gpuAdmitDefault v g = false := by |
| 869 | simp [gpuAdmitDefault, capAdmit, hzl] |
| 870 | |
| 871 | /-! ## 6. Inductive Pre-Dispatch Lifecycle State Machine (AienGpuGb20b / TicketLock Style) -/ |
| 872 | |
| 873 | inductive Phase where |
| 874 | | init | compiled | verifiedP2 | replayedP3 | admitted | dispatched | failed |
| 875 | deriving DecidableEq |
| 876 | |
| 877 | structure TraceState where |
| 878 | phase : Phase |
| 879 | omcPinned : Bool |
| 880 | p2Passed : Bool |
| 881 | p3Replayed : Bool |
| 882 | capVerified : Bool |
| 883 | gpuTouched : Bool |
| 884 | deriving DecidableEq |
| 885 | |
| 886 | def initTrace : TraceState := |
| 887 | { phase := .init, omcPinned := false, p2Passed := false, |
| 888 | p3Replayed := false, capVerified := false, gpuTouched := false } |
| 889 | |
| 890 | inductive Step : TraceState → TraceState → Prop |
| 891 | | compile_ok {s} (hp : s.phase = .init) : |
| 892 | Step s { s with phase := .compiled, omcPinned := true } |
| 893 | | verify_p2_ok {s} (v : BundleVerdict) (hp : s.phase = .compiled) |
| 894 | (hok : verifyPolicy 2 v = true) : |
| 895 | Step s { s with phase := .verifiedP2, p2Passed := true } |
| 896 | | replay_p3_ok {s} (v : BundleVerdict) (hp : s.phase = .verifiedP2) |
| 897 | (hok : verifyPolicy 3 v = true) : |
| 898 | Step s { s with phase := .replayedP3, p3Replayed := true } |
| 899 | | admit_from_p2 {s} (v : BundleVerdict) (g : CapGrant) (hp : s.phase = .verifiedP2) |
| 900 | (hok : gpuAdmitDefault v g = true) : |
| 901 | Step s { s with phase := .admitted, capVerified := true } |
| 902 | | admit_from_p3 {s} (v : BundleVerdict) (g : CapGrant) (hp : s.phase = .replayedP3) |
| 903 | (hok : gpuAdmitDefault v g = true) : |
| 904 | Step s { s with phase := .admitted, capVerified := true } |
| 905 | | dispatch_gpu {s} (hp : s.phase = .admitted) : |
| 906 | Step s { s with phase := .dispatched, gpuTouched := true } |
| 907 | | fail_closed {s} : |
| 908 | Step s { s with phase := .failed } |
| 909 | |
| 910 | inductive Reachable : TraceState → Prop |
| 911 | | init : Reachable initTrace |
| 912 | | step {s s'} : Reachable s → Step s s' → Reachable s' |
| 913 | |
| 914 | /-- Fail-closed lifecycle invariant: GPU dispatch is reachable ONLY after pinned compilation, |
| 915 | P2 policy verification (pinned Lean 4 proof + QMD v5/SPIR-V + trusted Ed25519 signature), |
| 916 | and authority-signed live capability admission. -/ |
| 917 | def SafeInv (s : TraceState) : Prop := |
| 918 | (s.phase = .init → s.gpuTouched = false) ∧ |
| 919 | (s.phase = .compiled → s.omcPinned = true ∧ s.gpuTouched = false) ∧ |
| 920 | (s.phase = .verifiedP2 → s.omcPinned = true ∧ s.p2Passed = true ∧ s.gpuTouched = false) ∧ |
| 921 | (s.phase = .replayedP3 → s.omcPinned = true ∧ s.p2Passed = true ∧ s.p3Replayed = true ∧ s.gpuTouched = false) ∧ |
| 922 | (s.phase = .admitted → s.omcPinned = true ∧ s.p2Passed = true ∧ s.capVerified = true) ∧ |
| 923 | (s.gpuTouched = true → s.omcPinned = true ∧ s.p2Passed = true ∧ s.capVerified = true) |
| 924 | |
| 925 | theorem safeInv_init : SafeInv initTrace := by |
| 926 | simp [SafeInv, initTrace] |
| 927 | |
| 928 | theorem safeInv_step {s s'} (hinv : SafeInv s) (hst : Step s s') : SafeInv s' := by |
| 929 | rcases hinv with ⟨h0, h1, h2, h3, h4, h5⟩ |
| 930 | cases hst with |
| 931 | | compile_ok hp => |
| 932 | have hg := h0 hp |
| 933 | refine ⟨by simp, by simp [hg], by simp, by simp, by simp, by simp [hg]⟩ |
| 934 | | verify_p2_ok _ hp _ => |
| 935 | have hc := h1 hp |
| 936 | refine ⟨by simp, by simp, by simp [hc.1, hc.2], by simp, by simp, by simp [hc.2]⟩ |
| 937 | | replay_p3_ok _ hp _ => |
| 938 | have hv := h2 hp |
| 939 | refine ⟨by simp, by simp, by simp, by simp [hv.1, hv.2.1, hv.2.2], by simp, by simp [hv.2.2]⟩ |
| 940 | | admit_from_p2 _ _ hp _ => |
| 941 | have hv := h2 hp |
| 942 | refine ⟨by simp, by simp, by simp, by simp, by simp [hv.1, hv.2.1], by simp [hv.2.2]⟩ |
| 943 | | admit_from_p3 _ _ hp _ => |
| 944 | have hr := h3 hp |
| 945 | refine ⟨by simp, by simp, by simp, by simp, by simp [hr.1, hr.2.1], by simp [hr.2.2.2]⟩ |
| 946 | | dispatch_gpu hp => |
| 947 | have ha := h4 hp |
| 948 | refine ⟨by simp, by simp, by simp, by simp, by simp, by intro _; exact ha⟩ |
| 949 | | fail_closed => |
| 950 | refine ⟨by simp, by simp, by simp, by simp, by simp, h5⟩ |
| 951 | |
| 952 | theorem safeInv_reachable {s : TraceState} (hr : Reachable s) : SafeInv s := by |
| 953 | induction hr with |
| 954 | | init => exact safeInv_init |
| 955 | | step _ hst ih => exact safeInv_step ih hst |
| 956 | |
| 957 | /-- Corollary: no reachable execution can ever touch the GPU without passing all three gates. -/ |
| 958 | theorem no_unverified_gpu_touch {s : TraceState} (hr : Reachable s) (ht : s.gpuTouched = true) : |
| 959 | s.omcPinned = true ∧ s.p2Passed = true ∧ s.capVerified = true := |
| 960 | (safeInv_reachable hr).2.2.2.2.2 ht |
| 961 | |
| 962 | /-- Negative control: a shortcut dispatching straight from `compiled` without P2/cap admission violates `SafeInv`. -/ |
| 963 | theorem neg_shortcut_dispatch_violates_safeInv : |
| 964 | let bad : TraceState := { initTrace with phase := .dispatched, omcPinned := true, gpuTouched := true } |
| 965 | ¬ SafeInv bad := by |
| 966 | intro bad h |
| 967 | have := h.2.2.2.2.2 rfl |
| 968 | simp [bad, initTrace] at this |
| 969 | |
| 970 | /-! ## 7. Prism Group Alignment (`uor-framework`, `LexLean`, `PrismPM`, `uor-comms`, `mnist`) -/ |
| 971 | |
| 972 | /-! ### 7a. UOR Ring `Z/(2^32)Z` Critical Identity & Word Arithmetic (`uor-framework`) -/ |
| 973 | |
| 974 | /-- Foundational UOR ring identity over `BitVec 32` (`Z/(2^32)Z`), matching 32-bit GPU words |
| 975 | in `om/gpu/bw_vecadd.om` (`IADD3`) and `protocol/uor-gpu/canonical.om`: `neg (bnot x) = succ x`. -/ |
| 976 | theorem uor_ring_critical_identity (x : BitVec 32) : |
| 977 | -~~~x = x + 1#32 := by |
| 978 | apply BitVec.eq_of_toNat_eq |
| 979 | have hx := x.isLt |
| 980 | simp [BitVec.toNat_neg, BitVec.toNat_not, BitVec.toNat_add] |
| 981 | omega |
| 982 | |
| 983 | theorem uor_ring_neg_involution (x : BitVec 32) : |
| 984 | -(-x) = x := by |
| 985 | bv_omega |
| 986 | |
| 987 | theorem uor_ring_bnot_involution (x : BitVec 32) : |
| 988 | ~~~(~~~x) = x := |
| 989 | BitVec.not_not |
| 990 | |
| 991 | theorem uor_u32_add_comm_assoc (x y z : BitVec 32) : |
| 992 | x + y = y + x ∧ (x + y) + z = x + (y + z) := |
| 993 | ⟨BitVec.add_comm x y, BitVec.add_assoc x y z⟩ |
| 994 | |
| 995 | /-! ### 7b. Contract Satisfaction (`UOR-Foundation/mnist` `satisfies_contract` pattern) -/ |
| 996 | |
| 997 | /-- Precondition / postcondition boundary contract for bounded GPU vecadd launch. -/ |
| 998 | def VecaddPrecond (n k : Nat) : Prop := n ≤ k |
| 999 | |
| 1000 | def VecaddPostcond (n : Nat) (a b init out : Nat → Nat) : Prop := |
| 1001 | (∀ i, i < n → out i = a i + b i) ∧ (∀ i, n ≤ i → out i = init i) |
| 1002 | |
| 1003 | /-- Universal contract theorem: every launch satisfying `VecaddPrecond` satisfies `VecaddPostcond` |
| 1004 | (discharging the postcondition by proof, matching `Mnist.Model.satisfies_contract`). -/ |
| 1005 | theorem vecadd_satisfies_contract (n k : Nat) (a b init : Nat → Nat) |
| 1006 | (hpre : VecaddPrecond n k) : |
| 1007 | VecaddPostcond n a b init (runVecadd n k a b init) := |
| 1008 | ⟨fun i hi => runVecadd_in_bounds n k a b init i hi hpre, |
| 1009 | fun i hoob => runVecadd_preserves_canaries n k a b init i hoob⟩ |
| 1010 | |
| 1011 | /-! ### 7c. Domain-Separated Framed Content IDs (`LexLeanBoot.ContentId` pattern) -/ |
| 1012 | |
| 1013 | /-- Domain-separated framed input `(domain, body)` matching `LexLeanBoot.ContentId.framedHash` |
| 1014 | and `uor-gpu`'s distinct domain tags (`UORGPU1\0`, `mlbom:v2:...`, `UORTRST1`). -/ |
| 1015 | structure FramedInput (D B : Type) where |
| 1016 | domain : D |
| 1017 | body : B |
| 1018 | deriving DecidableEq |
| 1019 | |
| 1020 | /-- Under an injective hash over `(domain, body)`, distinct domains can never collide. -/ |
| 1021 | theorem framed_domain_disjoint {D B H : Type} |
| 1022 | (hHash : FramedInput D B → H) |
| 1023 | (hInj : ∀ x y, hHash x = hHash y → x = y) |
| 1024 | (d1 d2 : D) (b1 b2 : B) (hd : d1 ≠ d2) : |
| 1025 | hHash ⟨d1, b1⟩ ≠ hHash ⟨d2, b2⟩ := by |
| 1026 | intro heq |
| 1027 | have h := hInj _ _ heq |
| 1028 | cases h |
| 1029 | exact hd rfl |
| 1030 | |
| 1031 | /-- Negative control: unframed concatenation allows cross-domain ambiguity (`"ab" ++ "c" = "a" ++ "bc"`). -/ |
| 1032 | theorem neg_unframed_concat_ambiguity : |
| 1033 | ∃ d1 b1 d2 b2 : String, d1 ≠ d2 ∧ d1 ++ b1 = d2 ++ b2 := by |
| 1034 | exact ⟨"ab", "c", "a", "bc", by decide, by decide⟩ |
| 1035 | |
| 1036 | /-! ### 7d. Exact Refusal-Reason Soundness & Completeness (`uor-comms` `ReasonProofs` pattern) -/ |
| 1037 | |
| 1038 | private theorem ite_ne {α : Type} {c : Prop} [Decidable c] {a b t : α} |
| 1039 | (ha : a ≠ t) (hb : b ≠ t) : (if c then a else b) ≠ t := by |
| 1040 | by_cases hc : c <;> simp [hc, ha, hb] |
| 1041 | |
| 1042 | /-- Forward & converse characterization: `.badAnchors` is returned iff `anchorsValid = false`. -/ |
| 1043 | theorem reason_badAnchors_iff (minLevel : Nat) (v : BundleVerdict) : |
| 1044 | evalPolicy minLevel v = .badAnchors ↔ v.anchorsValid = false := by |
| 1045 | cases ha : v.anchorsValid |
| 1046 | · simp [evalPolicy, ha] |
| 1047 | · simp only [Bool.true_eq_false, iff_false] |
| 1048 | change evalPolicy minLevel v ≠ .badAnchors |
| 1049 | unfold evalPolicy |
| 1050 | simp only [ha, Bool.not_true, Bool.false_eq_true, ↓reduceIte] |
| 1051 | repeat (first | decide | apply ite_ne) |
| 1052 | |
| 1053 | /-- Every refused verdict carries a non-zero reason code in `1..20` (`everyRefusalHasAName`). -/ |
| 1054 | theorem every_refusal_has_nonzero_code (rc : ReasonCode) (hne : rc ≠ .pass) : |
| 1055 | 1 ≤ rc.code ∧ rc.code ≤ 20 := by |
| 1056 | cases rc <;> simp [ReasonCode.code] at hne ⊢ |
| 1057 | |
| 1058 | theorem evalPolicy_ne_badGrant (minLevel : Nat) (v : BundleVerdict) : |
| 1059 | evalPolicy minLevel v ≠ .badGrant := by |
| 1060 | unfold evalPolicy |
| 1061 | repeat (first | decide | apply ite_ne) |
| 1062 | |
| 1063 | /-- Forward & converse for `evalAdmit`: `.badGrant` is returned iff policy passed and `grantSigValid = false`. -/ |
| 1064 | theorem reason_badGrant_iff (v : BundleVerdict) (g : CapGrant) : |
| 1065 | evalAdmit v g = .badGrant ↔ (verifyPolicy 2 v = true ∧ g.grantSigValid = false) := by |
| 1066 | unfold evalAdmit |
| 1067 | have hp := evalPolicy_pass_iff 2 v |
| 1068 | cases h : evalPolicy 2 v with |
| 1069 | | pass => |
| 1070 | have hv : verifyPolicy 2 v = true := hp.mp h |
| 1071 | cases hgs : g.grantSigValid |
| 1072 | · simp [hv] |
| 1073 | · cases hc : capAdmit g <;> simp [hv] |
| 1074 | | badGrant => |
| 1075 | exact absurd h (evalPolicy_ne_badGrant 2 v) |
| 1076 | | _ => |
| 1077 | have hv : verifyPolicy 2 v = false := by |
| 1078 | cases hv' : verifyPolicy 2 v |
| 1079 | · rfl |
| 1080 | · exfalso; have := hp.mpr hv'; rw [h] at this; cases this |
| 1081 | simp [hv] |
| 1082 | |
| 1083 | /-! ### 7e. PrismPM Proof-Statement Axiom Policy & Replay Gate (`Foundation.Proof.V1.Statement`) -/ |
| 1084 | |
| 1085 | inductive AxiomPolicyKind where |
| 1086 | | none | allow | exact |
| 1087 | deriving DecidableEq |
| 1088 | |
| 1089 | def allIn (xs ys : List String) : Bool := |
| 1090 | xs.all (fun x => ys.contains x) |
| 1091 | |
| 1092 | /-- Exact mirror of `Foundation.Proof.V1.Statement.withinPolicy` in `UOR-Foundation/prismpm`. -/ |
| 1093 | def withinAxiomPolicy (kind : AxiomPolicyKind) (allowed observed : List String) : Bool := |
| 1094 | match kind with |
| 1095 | | .none => observed.isEmpty |
| 1096 | | .allow => allIn observed allowed |
| 1097 | | .exact => allIn observed allowed && allIn allowed observed |
| 1098 | |
| 1099 | structure ProofTheoremRec where |
| 1100 | resultOk : Bool |
| 1101 | policyKind : AxiomPolicyKind |
| 1102 | policyAxioms : List String |
| 1103 | observed : List String |
| 1104 | deriving DecidableEq |
| 1105 | |
| 1106 | def theoremPassed (t : ProofTheoremRec) : Bool := |
| 1107 | t.resultOk && withinAxiomPolicy t.policyKind t.policyAxioms t.observed |
| 1108 | |
| 1109 | def allTheoremsPassed (ts : List ProofTheoremRec) : Bool := |
| 1110 | ts.all theoremPassed |
| 1111 | |
| 1112 | def replaysClean (exits : List Nat) : Bool := |
| 1113 | exits.all (fun c => c == 0) |
| 1114 | |
| 1115 | def prismStatementPassed (ts : List ProofTheoremRec) (exits : List Nat) : Bool := |
| 1116 | allTheoremsPassed ts && replaysClean exits |
| 1117 | |
| 1118 | def standardLeanAxioms : List String := |
| 1119 | ["propext", "Classical.choice", "Quot.sound"] |
| 1120 | |
| 1121 | theorem withinAxiomPolicy_none_iff_empty (allowed observed : List String) : |
| 1122 | withinAxiomPolicy .none allowed observed = true ↔ observed = [] := by |
| 1123 | cases observed <;> simp [withinAxiomPolicy] |
| 1124 | |
| 1125 | theorem allIn_contains_false {x : String} {xs ys : List String} |
| 1126 | (hmem : x ∈ xs) (hnot : ys.contains x = false) : |
| 1127 | allIn xs ys = false := by |
| 1128 | unfold allIn |
| 1129 | cases h : xs.all (fun y => ys.contains y) |
| 1130 | · rfl |
| 1131 | · exfalso |
| 1132 | rw [List.all_eq_true] at h |
| 1133 | have hx := h x hmem |
| 1134 | rw [hnot] at hx |
| 1135 | cases hx |
| 1136 | |
| 1137 | /-- Any theorem depending on `sorryAx` is ALWAYS rejected under PrismPM's standard axiom policy. -/ |
| 1138 | theorem withinAxiomPolicy_standard_rejects_sorry (kind : AxiomPolicyKind) (observed : List String) |
| 1139 | (hsorry : "sorryAx" ∈ observed) : |
| 1140 | withinAxiomPolicy kind standardLeanAxioms observed = false := by |
| 1141 | have hnot : standardLeanAxioms.contains "sorryAx" = false := by decide |
| 1142 | have hall : allIn observed standardLeanAxioms = false := allIn_contains_false hsorry hnot |
| 1143 | cases kind with |
| 1144 | | none => |
| 1145 | cases observed with |
| 1146 | | nil => cases hsorry |
| 1147 | | cons _ _ => rfl |
| 1148 | | allow => exact hall |
| 1149 | | exact => simp [withinAxiomPolicy, hall] |
| 1150 | |
| 1151 | theorem replaysClean_iff_all_zero (exits : List Nat) : |
| 1152 | replaysClean exits = true ↔ ∀ c ∈ exits, c = 0 := by |
| 1153 | simp [replaysClean, List.all_eq_true] |
| 1154 | |
| 1155 | /-- Negative control: a proof statement containing a theorem with `sorryAx` or a non-zero replay exit |
| 1156 | is refused by `prismStatementPassed`. -/ |
| 1157 | theorem neg_sorryAx_or_replay_fail_refused_by_prism_statement : |
| 1158 | prismStatementPassed |
| 1159 | [⟨true, .allow, standardLeanAxioms, ["propext", "sorryAx"]⟩] [0] = false ∧ |
| 1160 | prismStatementPassed |
| 1161 | [⟨true, .allow, standardLeanAxioms, ["propext"]⟩] [0, 1] = false := by |
| 1162 | decide |
| 1163 | |
| 1164 | /-! ## 8. Axiom Audit (must be empty or subset of `[propext, Classical.choice, Quot.sound]`) -/ |
| 1165 | |
| 1166 | #print axioms uorHdrLayout_tiles_384 |
| 1167 | #print axioms uorTrstBaseLayout_tiles_104 |
| 1168 | #print axioms uorGrantLayout_tiles_128 |
| 1169 | #print axioms sm121PayloadLayout_tiles_896 |
| 1170 | #print axioms neg_overlapping_layout_detected |
| 1171 | #print axioms le32Pack_injective |
| 1172 | #print axioms packQmdW34_injective |
| 1173 | #print axioms dec_packQmdW35 |
| 1174 | #print axioms smemCfgFor_bounds |
| 1175 | #print axioms qmd_reference_words |
| 1176 | #print axioms packSassW0_injective |
| 1177 | #print axioms sass_vecadd_reference_w0 |
| 1178 | #print axioms sm121_opcodes_pairwise_disjoint |
| 1179 | #print axioms neg_unmasked_qmd_w34_corrupts_ty |
| 1180 | #print axioms runVecadd_in_bounds |
| 1181 | #print axioms runVecadd_preserves_canaries |
| 1182 | #print axioms neg_unguarded_clobbers_canary |
| 1183 | #print axioms uor_id_tamper_evident |
| 1184 | #print axioms holo_seal_tamper_evident |
| 1185 | #print axioms qmd_valid_enforces_skedcheck05 |
| 1186 | #print axioms anchors_separate_authority_and_signer |
| 1187 | #print axioms neg_shared_auth_signer_refused |
| 1188 | #print axioms evalPolicy_pass_iff |
| 1189 | #print axioms evalAdmit_pass_iff |
| 1190 | #print axioms verifyPolicy_monotone |
| 1191 | #print axioms unsigned_never_above_p0 |
| 1192 | #print axioms safeInv_reachable |
| 1193 | #print axioms no_unverified_gpu_touch |
| 1194 | #print axioms neg_shortcut_dispatch_violates_safeInv |
| 1195 | #print axioms uor_ring_critical_identity |
| 1196 | #print axioms uor_ring_neg_involution |
| 1197 | #print axioms uor_ring_bnot_involution |
| 1198 | #print axioms uor_u32_add_comm_assoc |
| 1199 | #print axioms vecadd_satisfies_contract |
| 1200 | #print axioms framed_domain_disjoint |
| 1201 | #print axioms neg_unframed_concat_ambiguity |
| 1202 | #print axioms reason_badAnchors_iff |
| 1203 | #print axioms every_refusal_has_nonzero_code |
| 1204 | #print axioms reason_badGrant_iff |
| 1205 | #print axioms withinAxiomPolicy_none_iff_empty |
| 1206 | #print axioms withinAxiomPolicy_standard_rejects_sorry |
| 1207 | #print axioms replaysClean_iff_all_zero |
| 1208 | #print axioms neg_sorryAx_or_replay_fail_refused_by_prism_statement |
| 1209 | |
| 1210 | end UorGpuWorld |