Docs

Trusted base

Everything a MojoProof theorem relies on that Lean does not check. Each item has its reason.

# Item Why it is trusted
T1 Lean 4 v4.36.0 kernel, Mathlib v4.36.0, FloatLib v4.1.0 (fc2fad1f), TorchLean v1.5 (6e4b6335) The proofs are checked by this kernel against these libraries; the axiom check (CONTRIBUTING.md) shows only propext, Classical.choice and Quot.sound for our theorems.
T2 Everything after the printed LLVM IR: Mojo's target finalization (finalizeModuleForTarget), LLVM's optimizer, the NVPTX backend, ptxas, the driver and the GPU The theorems are about the file mojo build --emit llvm prints, which is taken before these steps (Mojo/lib/Compiler/ObjectCompiler/ObjectCompiler.cpp:1597 at modular bbc13a71).
T3 Corpus provenance (tests/corpus/MANIFEST.tsv) That each file is what the recorded Mojo version emitted for the recorded source and flags is a record of how it was made; scripts/corpus.py check only compares each file (and each source kept in this repository) with its manifest row: the sha256 and what is read from the bytes (line count, kernel name, arch, PTX version). Nothing compiles the source again.
T4 The lexer, and the parser and printer together (MojoProof/LLVM/Lexer.lean, Parser.lean, Printer.lean), as a reading of LLVM's syntax Theorems are stated about the parsed AST. On every corpus file (the test runner) and at every mojo_import, printing the program gives exactly the file's tokens (printDiff; comments and whitespace are not tokens), and parse (print m) = m on every corpus file, so a parser error shows unless the printer makes the opposite error. That the printer writes each construct as LLVM reads it (so that the AST means what the file means) rests on LangRef's grammar, not on a check; the lexer is trusted to split text into tokens without merging or dropping any. The step from the program to the Lean term a theorem names (mojo_import, MojoProof/LLVM/Quote.lean) is checked at every import, not proved by the kernel: the term is evaluated by Lean's compiled evaluation (evalConst) and compared field by field with the importer's program (Program.diff), its digest is the manifest's (T3), and the evaluated term is the one printed. Trusted for that step: that evalConst gives the value the kernel's term denotes (Lean's compiler and interpreter) and the comparison code; no kernel-checked equality connects the importer's program to the term. The lexer refuses a quoted all-digit name (%"0", which LLVM tells from %0) and the parser a name defined twice (Module.twice), so a token's name string is one LLVM identifier. The parser interns local names (one table per function, Func.names; a local, label or destination is its index there) and the printer prints each index back from the table, so an interning error changes a printed token and shows in printDiff.
T5 The intrinsic table (MojoProof/LLVM/Intrinsic.lean) A declaration is accepted as an intrinsic when its name and signature are the ones the table generates for a family member. That the name denotes the LLVM or NVVM operation the semantics gives it rests on the LLVM LangRef and NVVM documentation cited there, not on a check.
T6 SHA-256 (MojoProof/Util/SHA256.lean) The digest the importer records is computed by this code. It is tested against the FIPS 180-4 vectors and, on every corpus file, against the manifest's digest, which scripts/corpus.py computes with Python's hashlib; it is not proved.
T7 The semantics (MojoProof/Sem/) as a reading of the LLVM Language Reference (https://llvm.org/docs/LangRef.html, the LLVM 24.0.0git version fetched 2026-11-17, sha256 a9a784ae9356999a2efaab744426204e773f8669723c265d654a97bc332b9ed4) and of the PTX ISA for the intrinsics and the grid (https://docs.nvidia.com/cuda/parallel-thread-execution/index.html, version 9.5, fetched 2026-11-17, sha256 3a4fe2a0dff0320a46e140b52d913839c8cd3dc0227b9809a46e116ab5b0a0a3; sections 9.7.10.6 shfl.sync, 9.7.15.1 barrier) Theorems are about this semantics. That it gives each instruction the meaning LLVM gives it rests on reading the cited sections (each rule names its section in the docstrings), not on a check against LLVM. The evaluator tests (MojoProofTest/Eval.lean) run it on two corpus kernels (vector_addition, tiled_matmul) and on small kernels written for single rules; they test the semantics, they do not check it against LLVM. Where LangRef leaves a choice, the semantics takes every choice through two functions that the statements quantify over: the addresses of blocks through the skeleton choices (T11), and the float freedoms (NaN results, contraction, maxnum, rsqrt.approx) through the oracle (Ctx.oracle). Any NaN result is any NaN (MojoProof.Sem.deliver), a superset of LangRef's NaN set. An operation on undef is unsupported, not a choice, so a run that ends normally never depends on an undef value.
T8 Alignment of types the data layout string does not list (MojoProof.Sem.Layout.align) Floats and vectors without an entry take natural alignment (store size rounded up to a power of two), integers the next larger listed integer's: our reading of LangRef's "Data Layout" and LLVM's DataLayout::getAlignment. The corpus has one datalayout string; the types of the corpus it (with LangRef's defaults) lacks entries for are the 256- and 512-bit vectors (<8 x i32>, <4 x i64>, <16 x half>, <4 x double>, <16 x float>).
T9 The reading of the contract flag (MojoProof.Sem.contract) An fadd contract / fsub contract may fuse with an operand an fmul contract computed in a register, into one FloatLib fma. Nothing is fused through phi, memory, fpext or other casts, and no other operation is contracted. LangRef gives only "e.g., fusing a multiply followed by an addition". LLVM's DAG combiner also fuses through fpext; a kernel with that pattern needs this item revisited. Any fusion the backend does without the flag (a global fp-contract option) is under T2.
T10 llvm.nvvm.rsqrt.approx.ftz.f is PTX's rsqrt.approx.ftz.f32 and meets its documented contract (MojoProof.Sem.rsqrtOk) NVPTX lowers the intrinsic to that instruction, and PTX ISA 9.5, section 9.7.3.16 (sha256 above) documents it only by its table of special inputs, a maximum relative error of 2^-22.9 over the positive finite range, and .ftz flushing of subnormal inputs and results. The semantics allows every word within the rational bound rsqrtErr (proved at least 2^-22.9, rpow_le_rsqrtErr) and any NaN where PTX says NaN: rsqrt returns the oracle's word when it meets the contract, else FloatLib's Model.rSqrt of the operand with subnormals flushed, which meets it (rsqrtOk_rSqrt), so its values are exactly the words that meet the contract (rsqrtOk_of_rsqrt, rsqrt_toNatBits). Hardware outside the documented bound is outside the semantics.
T11 Block addresses (MojoProof.Sem.Mem.alloc) Each block gets two addresses (its space, the generic space), multiples of its alignment, from the launch's skeleton choices ch (kernel byval copies and shared memory directly; an alloca through Ctx.addr, which Grid.start fills from ch, never from the float oracle); blocks may overlap in the address space. Every pair of aligned addresses in range is a choice (Mem.alloc_addr), so a kernel theorem whose admission is fun _ _ => True (Kernel.sound_ret_launch) includes the addresses of every real execution; trusted is only that a real execution gives each block aligned addresses in range. A kernel theorem covers only the executions its admission admits: Kernel.sound_of_paths and mojo_kernel's n.sound_of take any admission, and Kernel.sound_eval and kernel22 admit one address choice and one oracle, so they say nothing of the addresses of other executions. ptrtoint and pointer comparisons read them. Block numbers are not addresses: the start checks the caller's memory (Mem.checkClosed) and kernel theorems take the hypothesis that it is closed (Mem.Closed), so a pointer argument or pointer byte that names no block of it, or block 0 (null), points to no block for the whole run, never into a block the launch or an alloca makes; this is our reading of LangRef's "Pointer Aliasing Rules" ("Any memory access must be done through a pointer value associated with an address range of the memory access, otherwise the behavior is undefined"; an allocation's result is associated with the storage it allocates). Taking the address of a pointer to no block (ptrtoint, a comparison, nonnull, align) is undefined behavior here (Mem.addr), stricter than LangRef, which makes only the access undefined. This allows more results than LLVM (which keeps live blocks disjoint), so a property of all runs holds of LLVM's runs; a property that needs disjoint addresses cannot be proved.
T12 Attributes and metadata that add undefined behavior None is left unchecked: each is checked, made an obligation, or refused. norecurse on a defined function: a call of it while it is on the thread's stack is undefined behavior. On a parameter, argument or return value (withAttrs), each a poison-generating attribute: range on an integer or each element of an integer vector, a value outside it; nonnull, a pointer whose address (Mem.addr in the pointer type's space, so not only the null block) is 0; align n, an address not a multiple of n; then noundef makes poison undefined behavior. !invariant.load: the load is recorded in the trace, and Grid.Sound includes Grid.Kept, that no write of the run touches its bytes (stricter than LangRef's "same value"). A constant shared global is read-only (a store is undefined behavior); an external constant one is refused. Func.check, run on the kernel at the launch and on every callee at each call, intrinsic declarations included, refuses: function attributes other than convergent, nounwind and strings, plus norecurse and noinline on a definition; return attributes other than noundef, nonnull, range, align; parameter attributes other than those, byval (with readonly, noundef, nonnull), and on a declaration captures(none), readonly and immarg (an argument that is not a constant is unsupported). On an intrinsic declaration each promise is checked against the member's effects (Intrinsic.effects): nocallback and nofree always; nosync, willreturn and nocreateundeforpoison only on a member that completes alone (not the barrier, a shuffle, griddepcontrol, cp.async, ldmatrix, mma); speculatable only on one with no effect but its result; memory(...) only if it allows the member's accesses through its argument, and all memory for one that orders other memory (the barrier, griddepcontrol, cp.async); readonly on a parameter only if the member does not write through it; and the barrier and a shuffle must be convergent. A call of a nocreateundeforpoison declaration with defined arguments whose own result, before the call's nnan and ninf apply, is not defined is undefined behavior (LangRef: "the result of the function (prior to application of return attributes/metadata)"). Trusted: the table Intrinsic.effects, which says what each member does (for the members the semantics runs, as intrinsic and Grid.fire give them; for ldmatrix, mma, cp.async and griddepcontrol, from PTX ISA 9.5 sections 9.7.16.5.15, 9.7.16.5.14, 9.7.10.28.3.2-3, 9.7.15.14); that no member calls into the module, frees memory or keeps a pointer (nocallback, nofree, captures(none)); and the readings of LangRef above. noundef is checked wherever it occurs; call-site attributes other than noundef, and metadata other than !invariant.load and !noundef on a load, are refused, on phis and terminators too.
T13 Sequential consistency (MojoProof.Sem.Grid.Step) Thread steps interleave over one memory, so every load reads the last store of the interleaving. LLVM's memory model (LangRef, "Memory Model for Concurrent Operations") gives that only to runs without a data race: a non-atomic load that races with a store reads undef, and atomics weaker than seq_cst allow results no interleaving gives. The only atomic instruction the semantics admits is atomicrmw, seq_cst at system scope, with a commutative and associative operation and an unused result (Stmt.checkAtomic); the parser refuses atomic loads and stores, and other atomic instructions are not in the subset. With only those, a race-free run has LLVM's sequentially consistent behavior (the DRF-SC property of the C++-style model LLVM adopts; PTX's scoped model gives it to .sys strong operations). The evaluator does not detect races; the statements do: every access and barrier is recorded in a ghost trace, and Grid.Sound includes Grid.RaceFree (MojoProof/Sem/Spec.lean), race freedom of every reachable trace under a happens-before of program order and the barriers of one block of threads. That happens-before is contained in LLVM's and PTX's (bar.sync orders the memory accesses of the participating threads, PTX ISA 9.5, section 9.7.15.1), so a sound grid's runs are race free for LLVM too and have its sequentially consistent behavior. Trusted: DRF-SC itself, and that reading of the barrier.
T14 The fragment layouts (MojoProof.Sem.fragA, fragB, fragC, ldm, quadA, quadB, quadC) and the shapes of MojoProof.LLVM.Mma.table are the PTX ISA's; a given GPU's mma accumulation is the accumulation policy of the launch a theorem is applied to (MojoProof.Sem.Launch.acc, an MojoProof.Sem.MmaAcc, MojoProof.Sem.gridAcc by default), which the grid's mma (Grid.fire, through MojoProof.Sem.mmaGrid) runs for bf16 and f16 inputs with an f32 accumulator, and it meets the contract MojoProof.Sem.AccBy mag magC bnd (AccOk bnd is its case of the absolute products) that a theorem taking one states PTX ISA 9.5, section 9.7.16.5.14, specifies the fragments of mma but not its arithmetic: the accumulation is done with at least single precision, and its order, rounding and handling of subnormals are unspecified; the internal layout of .tf32 is implementation defined. So the semantics fixes no accumulation: a policy is a function of the input and accumulator formats, the input pairs and C (MmaAcc), each launch carries one, Grid.fire runs it on the words the registers decode to (MmaAcc.bits) at the shapes of Mma.table (the importer's Mma.ok and the layouts mmaFrags read the same list), and every theorem about a grid holds for every policy (Grid.fire_mma gives the D words as the policy's value). The ISA gives no error bound, so none is assumed: mma_contract takes AccBy mag magC bnd acc as a hypothesis for all magnitudes and every bnd, and covers a GPU only if the GPU's accumulation meets it. Two policies are defined, each proved to meet a contract: the measured policy gridAcc fi fc = fuseAcc fi fc 8 24 meets AccBy with the magnitudes wt a · wt b and |c| + 2^emin and the bound fuseBound fc 8 24 ⌈K / 8⌉ (gridAcc_ok, the case of fuseAcc_ok, MojoProof/Sem/TensorCoreAcc.lean: the fused truncating block accumulation fuseAcc fi fc n p, blocks of n products, each addend truncated toward zero to p bits below the largest one's leading power, the sum rounded by fuseRound fc: FloatLib's roundRat toward zero while its magnitude is at most the largest finite one M, M with the sum's sign beyond that and below 2^(emax + 1), and the infinity of the sum's sign from 2^(emax + 1) on, meets AccBy with the bound fuseBound fc n p ⌈K / n⌉ for every IEEE accumulator format fc, every input format, every block size n ≥ 1, width p and count K); the sequential policy seqAcc, the inputs cast to the accumulator's format and folded from C by dotLoop rounding to nearest, meets AccOk (dotBound fc K) (seqAcc_ok, the case of castDot_ok). The two differ: on one cell of m16n8k8 with f16 inputs, C = 2^24 and the products 1, -2^24, 0, …, gridAcc gives 1 and seqAcc gives +0 (MojoProofTest/TensorCore.lean, MojoProofTest/TensorCoreGrid.lean). Trusted: that a given GPU's accumulation is such a function, the same for every warp, call and shape of a launch, and that it meets the contract a caller uses (a reading of the ISA's precision text). On an NVIDIA A100, all 2,560 D words of 20 launches of mma.m16n8k16 with bfloat16 inputs are bit for bit those of gridAcc .bfloat16 .binary32 (tests/gpu/mma/record.txt), which meets its contract by fuse16_ok; that is a measurement on those inputs, not a proof, and it does not exclude other accumulations giving the same words; f16 inputs and other shapes are not measured. The A100 does not meet AccOk (dotBound .binary32 16), so it is not seqAcc there: one of those words is 1.11 times that bound from the exact sum. The fragment layouts are transcribed by hand from the ISA's tables of sections 9.7.16.5.1-4, 9.7.16.5.6-11, 9.7.16.5.14 and 9.7.16.5.15 and checked against those tables, written in their own form, by decide at m16n8k8 .tf32, m16n8k16 .bf16/.f16, the f32 and f16 accumulators, m8n8k4 .f64, m8n8k4 with f16 inputs (both majors, f16 and f32 accumulators), the 8-bit inputs of m8n8k16, m16n8k16 and m16n8k32, the 4-bit inputs of m8n8k32, m16n8k32 and m16n8k64, m16n8k4 and m16n8k16 .f64 (MojoProofTest/TensorCore.lean); the transcription of the tables, and of the shapes mma.sync.aligned lists into Mma.table, is trusted. Two runs on that A100 agree with the layouts: every D word of the exact launches of the mma run is mmaStep (fragA 2 2 2) (fragB 2 2) (fragC 2 1)'s, and all 4,096 elements of ldmatrix.x4 and .x4.trans are ldmatrix 4's (tests/gpu/ldmatrix/record.txt). Every other mma (another shape or type, tf32 and f64 among them), and operands that are not finite words, are unsupported; ldmatrix reaches no grid run.
T15 cp.async, cp.async.commit_group and cp.async.wait_group n for one thread are MojoProof.Sem.Async.Step A reading of PTX ISA 9.5, sections 9.7.10.28.3.1 to 9.7.10.28.3.3: a copy is pending from its issue, a commit closes the copies since the last commit into a group (empty if none), wait_group n waits until every group but the n most recent has completed, and a pending copy, committed or not, may complete at any time and in any order (Async.Step's landing steps; Async.Run is every interleaving of landings with the operations, and Async.lazyRun, where a wait lands its groups in issue order and nothing lands earlier, is one run, Async.Run.lazy). Each copy lands whole, in one step; the ISA does not say how the bytes of one copy become visible, which matters only for a byte that two possibly pending copies write, which the premises of Async.determined and Async.visible_bytes exclude. Race freedom of the destinations and sources while a copy is pending is the caller's premise. On an NVIDIA A100, every shared word read back after wait_group 1 and wait_group 0 in 6 launches is the lazy run's (tests/gpu/cp-async/record.txt). No grid run reaches this model yet.
T16 The layout model (MojoProof/Layout/Basic.lean, MojoProof/Layout/Algebra.lean, Lay.isAffine in MojoProof/Layout/Crd.lean, MojoProof/Layout/Bits.lean, MojoProof/Layout/TwoLevel.lean) is Mojo's layout library A reading of modular/modular bbc13a71 (max/kernels/src/layout/layout.mojo, swizzle.mojo, bit_layout.mojo, two_level_layout.mojo, Mojo/stdlib/std/utils/coord.mojo), transcribed by hand with each definition's docstring citing its source line (table: docs/proofs/layout-laws.md section 4). No proof connects the model to the source or to compiled IR. Bits.lean transcribes BitLayout, put, __call__, is_bit_linear, placement, _log2, _power_of_two and bits on natural numbers, where Mojo computes on UInt64, so it describes Mojo only while every image, span and offset lies below 2 ^ 64; kill, run and the dead mask are not modelled. TwoLevel.lean transcribes TwoLevelLayout.__call__ with a flat static outer layout, two_level_layout_from_swizzle and its two asserts on natural numbers, where Mojo computes on Int, so it describes Mojo only while every extent, stride and offset lies below 2 ^ 63; nested and runtime outer layouts, a nonzero x0, and the compile-time refusal of a nested or wrong-rank coordinate are not modelled. The model's remainder by an extent 0 keeps the dividend (a % 0 = a) where Mojo's is 0; no law about a scalar's offset reaches such a point, since each asks for the scalar below the size, but idx2crd_flat there describes the model and not Mojo. The model is checked only by tests. The values the compiler folds into a kernel's LLVM IR equal the model's on 43 cases (351 values) with static leaves, Mojo 1.3.0.dev2026111705, sm_80 (tests/layout/record.txt, MojoProofTest/LayoutConformance.lean). A CPU run of a compiled program on 9 layouts with runtime leaves gives the model's values on 8 (79 values) and differs on the ninth only at scalars past its size 0, by the remainder above (tests/layout/runtime/record.txt, MojoProofTest/LayoutRuntime.lean). Bit layouts and two-level layouts are in neither test, and nothing has run on a GPU. Mojo's static bounds asserts are not modelled; each law states its bound as a premise. No kernel theorem uses the model.
T17 ex2.approx.ftz.f32 meets MojoProof.Float.Ex2Close at the operands where the float bounds use it, and Mojo's float32 exp on NVPTX is that instruction applied to Model.mul (Model.sub x m) log2e Mojo's math.exp on a GPU for float16 and float32 is exp2(x * log2e) (Mojo/stdlib/std/math/math.mojo:550-552 at modular bbc13a71) and float32 exp2 is the inline assembly ex2.approx.ftz.f32 (Mojo/stdlib/std/_plugin/cuda/cuda_math.mojo:236); the LLVM IR Mojo 1.3.0.dev2026111705 prints for exp(a - b) on float32 at sm_80 is fsub contract, fmul contract by f0x3FB8AA3B and that asm call, read on one compiled file that is not in the corpus. PTX ISA 9.5, section 9.7.3.21 (the document of T7), documents a maximum error of 2 ulp from the correctly rounded result across the full range of inputs, and .ftz flushing of subnormal inputs and results to sign-preserving zero. Ex2Close a w (a finite word within 3 · 2^-23 · 2^a + 2^-126 of 2^a) is derived from those sentences by hand for a finite operand whose 2^a is below binary32's largest finite value (at most 1 in a max-subtracted softmax); the derivation is in MojoProof/Float/Ex2.lean and is not proved from a definition of ulp. The semantics runs no inline assembly, so no theorem connects the contract to a run: ex2_error and ex2Sum_error take it as a premise. Hardware outside the documented bound is outside the statements.