AlphaProof Code: Verifying Signal’s Security at the Machine-Code Level

Paper › arm64-semantics/ProofLib/Placed › Multi.leanTier 3 · arm64-semantics

Multi.lean🔗

Tier 3 · arm64-semantics used by the symbolic proof 2 headline theorems depend on it 6 of 2,803 lines trusted source ↗

Trusted, reviewed with the engine. The AArch64 model in arm64-semantics is Tier 3: it is reviewed in its own repository (check-trust-guards). The declarations that the headline statements use are shown for completeness.

Multi-Block Placed Libraries

Proof infrastructure for Obj.MultiPlacedLib: per-block symbol-resolution coherence (MultiPlacedLib.resolve_block), ELF loading and Program.pureMem transfer (codeLoaded_of_inElf, subroutineOk_toPureMem), cross-block stepping and call tactics (sepWP_call_block, subroutine_ok_of_block, wp_cut_codeLoaded, wp_call_block), kernel-checked Placeable, InElf, and DataDisjoint checkers (checkInElf_spec, Interned.checkMulti_spec, Interned.checkMultiDisjoint_spec), sub-library embedding (embedsAt, embed_subroutine_ok), and logarithmic tree-indexed symbol and data lookup (SymIndex, gen_multi_sym_index).

@[expose] public section
namespace Arm64.Obj
open Arm64.Process ProofLib ProofLib.ObjectLoad ProofLib.ProgramReflection
21 declarations not shown (lines 43–319): theorems, which Lean checks, or definitions that no headline statement uses

Arm64.Obj.mem_of_lookup_some, Arm64.Obj.lookup_none_of_not_mem_fst, Arm64.Obj.lookupBlockSymAux_some, Arm64.Obj.lookupBlockSym_some, Arm64.Obj.lookupBlockSymAux_of_lookup, Arm64.Obj.lookupBlockSym_of_lookup, Arm64.Obj.MultiPlacedLib.resolve_block, Arm64.Obj.MultiPlacedLib.resolve_block_fun, Arm64.Obj.MultiPlacedLib.blockLib_text, Arm64.Obj.MultiPlacedLib.blockLib_data, Arm64.Obj.MultiPlacedLib.hasWords_of_checkSegment, Arm64.Obj.MultiPlacedLib.sepWP_relaxablePair, Arm64.Obj.lookup_none_of_lookupBlockSymAux_none, Arm64.Obj.lookup_none_of_lookupBlockSym_none, Arm64.Obj.MultiPlacedLib.patchDataReloc_blockLib, Arm64.Obj.MultiPlacedLib.patchedData_blockLib, Arm64.Obj.MultiPlacedLib.placeable_blockLib, Arm64.Obj.MultiPlacedLib.inElf_blockLib_noExports, Arm64.Obj.MultiPlacedLib.CodeLoaded.of_keepsFrozen, Arm64.Obj.MultiPlacedLib.blockProgram_codeLoaded_of_inElf, Arm64.Obj.MultiPlacedLib.codeLoaded_of_inElf

def MultiPlacedLib.DataDisjointL321–326 ↗#

Writable data objects of lib under mpl share no byte with any other data object.

def MultiPlacedLib.DataDisjoint (lib : MultiPlacedLib) (mpl : MultiPlacement) : Prop := lib.data.Pairwise fun d₁ d₂ => (d₁.readOnly = true ∧ d₂.readOnly = true) ∨ ∀ a, InRegion (mpl.ρ d₁.sym) (lib.patchedData mpl d₁).length a → ¬ InRegion (mpl.ρ d₂.sym) (lib.patchedData mpl d₂).length a
21 declarations not shown (lines 328–715): theorems, which Lean checks, or definitions that no headline statement uses

Arm64.Obj.MultiPlacedLib.dataDisjoint_of_sorted, Arm64.Obj.MultiPlacedLib.satisfies_dataRO_of_inElf, Arm64.Obj.MultiPlacedLib.satisfies_dataInit_of_inElf, Arm64.Obj.MultiPlacedLib.subroutineOk_toPureMem, Arm64.Obj.MultiPlacedLib.subroutineOk_toPureMem_outcome, ProofLib.SepWP.of_sameHooks, Arm64.Obj.MultiPlacedLib.externAt?_blockProgram_none, Arm64.Obj.PlacedLib.externAt?_program_none, Arm64.Obj.PlacedLib.externAt?_program_rebase_none, Arm64.Obj.MultiPlacedLib.externAt?_blockProgram_rebase_none, Arm64.Obj.PlacedLib.externAt?_mk_program_none, Arm64.Obj.MultiPlacedLib.externAt?_mk_blockProgram_none, Arm64.Obj.MultiPlacedLib.externAt?_blockProgram_eq_of_externs_eq, Arm64.Obj.MultiPlacedLib.sepWP_of_other_block_hooks, Arm64.Obj.MultiPlacedLib.sepWP_of_other_block, Arm64.Obj.MultiPlacedLib.sepWP_call_block, Arm64.Obj.MultiPlacedLib.subroutine_ok_of_block, Arm64.Obj.MultiPlacedLib.subroutine_ok_of_block_hooks, Arm64.Obj.MultiPlacedLib.subroutine_ok_of_block_unfetched, Arm64.Obj.MultiPlacedLib.subroutine_ok_of_pureMem, Arm64.Obj.MultiPlacedLib.seq_codeLoaded

end Arm64.Obj

Re-establish lib.CodeLoaded mpl sm.mem at an intermediate cut point mid across preceding instructions (including STR/STP memory stores). Pair with wp_steps; wp_call_block ....

syntax "wp_cut_codeLoaded" (ppSpace colGt term:max)? : tactic

macro_rulesL726–730 ↗#

macro_rules | `(tactic| wp_cut_codeLoaded) => `(tactic| apply Arm64.Obj.MultiPlacedLib.seq_codeLoaded ‹_›) | `(tactic| wp_cut_codeLoaded $hcl:term) => `(tactic| apply Arm64.Obj.MultiPlacedLib.seq_codeLoaded $hcl)
2 declarations not shown (lines 732–774): theorems, which Lean checks, or definitions that no headline statement uses

ProofLib.collectPlacementIdents, ProofLib.collectRhoEqs

Step a cross-block subroutine call in a MultiPlacedLib: closes any active wp_cut_codeLoaded (MultiPlacedLib.seq_codeLoaded) segment via SepWP.done to refresh lib.CodeLoaded mpl s.mem, infers the target block index j from hcall, proves s.pc = entry, and invokes wp_call (MultiPlacedLib.subroutine_ok_of_block (j := j) (by decide) hcall). Supports wp_call_block hcall, wp_call_block hcall arg, wp_call_block hcall (x := arg), and wp_call_block hcall ... (on_panic := term).

syntax "wp_call_block" ppSpace colGt term:max (ppSpace colGt wppCallOpt)* : tactic

elab_rulesL784–889 ↗#

elab_rules : tactic | `(tactic| wp_call_block $hcall:term $[$opts:wppCallOpt]*) => do let _ ← tryTactic do let g ← getMainGoal let isSeqCodeLoaded ← g.withContext do let ty := (← instantiateMVars (← g.getType)).consumeMData unless ty.isAppOfArity ``SepWP 6 do return false let postExpr := (ty.getArg! 4).consumeMData unless postExpr.isLambda && postExpr.bindingBody!.consumeMData.isLambda do return false let body2 := postExpr.bindingBody!.consumeMData.bindingBody!.consumeMData match body2 with | .forallE _ dom _ _ => return dom.consumeMData.isAppOfArity ``MultiPlacedLib.CodeLoaded 3 | _ => return false if isSeqCodeLoaded then let hclId ← freshIdent `hcl_m evalTactic (← `(tactic| ( apply SepWP.done · first | wp_norm_lhs | wp_norm_goal | rfl · wp_norm_lhs intro $hclId:ident ))) else throwError "not seq_codeLoaded" let g ← getMainGoal let (jIdx, entryStx?, plIdents, rhoEqs) ← g.withContext do let hcallExpr ← elabTerm hcall none let hcallTy ← inferType hcallExpr let (_, _, concl) ← forallMetaTelescopeReducing hcallTy let concl ← whnfR (← instantiateMVars concl) unless concl.isAppOfArity ``Arm64.subroutine_ok 4 do throwError "wp_call_block: expected `subroutine_ok` contract, got `{concl}`" let qProg := concl.getArg! 1 let entryE := concl.getArg! 2 let specE := concl.getArg! 3 unless specE.isAppOfArity ``MultiPlacedLib.withCodeLoaded 4 do throwError "wp_call_block: expected callee spec wrapped with `MultiPlacedLib.withCodeLoaded`, got `{specE}`" let libE := specE.getArg! 1 let mplE := specE.getArg! 2 let mut foundJ : Option Nat := none for j in [:64] do let jStx := Syntax.mkNumLit (toString j) let libStx ← Term.exprToSyntax libE let mplStx ← Term.exprToSyntax mplE let cand ← elabTerm (← `(Arm64.Obj.MultiPlacedLib.blockProgram $libStx $mplStx $jStx)) none if ← withTransparency .all (isDefEq qProg cand) then foundJ := some j break let some j := foundJ | throwError "wp_call_block: could not match callee program `{qProg}` to `lib.blockProgram mpl j` for any `j < 64`" let goalTy ← instantiateMVars (← g.getType) let scanExpr := mkApp3 (mkConst ``And) goalTy entryE libE let plIds ← collectPlacementIdents scanExpr let rhoPairs ← collectRhoEqs goalTy mplE let mut rhoEqs : Array (TSyntax `term × TSyntax `term) := #[] for (lhsE, rhsE) in rhoPairs do rhoEqs := rhoEqs.push (← Term.exprToSyntax lhsE, ← Term.exprToSyntax rhsE) let eStx ← Term.exprToSyntax entryE return (j, some eStx, plIds, rhoEqs) for (lhsStx, rhsStx) in rhoEqs do let _ ← tryTactic do let hRhoId ← freshIdent `h_rho evalTactic (← `(tactic| have $hRhoId:ident : $lhsStx = $rhsStx := rfl)) let jLit := Syntax.mkNumLit (toString jIdx) let gCur ← getMainGoal let (progStx, sStx, progIdents) ← gCur.withContext do let ty := (← instantiateMVars (← gCur.getType)).consumeMData let pE := ty.getArg! 0 let pIdsRef ← IO.mkRef (#[] : Array Ident) pE.forEach fun sub => do if sub.isConst then let nm := sub.constName! let sTy ← inferType sub if sTy.getForallBody.isConstOf ``Arm64.Program then let pIds ← pIdsRef.get if !pIds.any (fun i => i.getId == nm) then pIdsRef.set (pIds.push (mkIdent nm)) return (← Term.exprToSyntax pE, ← Term.exprToSyntax (ty.getArg! 2), ← pIdsRef.get) let dsimpIds : Array Ident := plIdents ++ #[ mkIdent ``MultiPlacedLib.blockPlacement, mkIdent ``MultiPlacedLib.fnAddr, mkIdent ``MultiPlacedLib.resolve, mkIdent ``lookupBlockSym, mkIdent ``lookupBlockSymAux, mkIdent ``lookup] if let some eStx := entryStx? then let _ ← tryTactic do let hpcCallId ← freshIdent `hpc_call evalTactic (← `(tactic| have $hpcCallId:ident : ($sStx : Arm64.State).pc = $eStx := by simp only [wp_norm, arm64_norm] try simp [$[$dsimpIds:ident],*] try bv_omega)) let hcallBlkId ← freshIdent `hcall_blk evalTactic (← `(tactic| have $hcallBlkId:ident := Arm64.Obj.MultiPlacedLib.subroutine_ok_of_block (P := $progStx) (j := $jLit) (by decide) $hcall (by intro pc; simp only [$[$progIdents:ident],*, Arm64.Obj.PlacedLib.externAt?_mk_program_none, Arm64.Obj.MultiPlacedLib.externAt?_mk_blockProgram_none, Arm64.Obj.PlacedLib.externAt?_program_rebase_none, Arm64.Obj.MultiPlacedLib.externAt?_blockProgram_rebase_none, Arm64.Obj.PlacedLib.externAt?_program_none, Arm64.Obj.MultiPlacedLib.externAt?_blockProgram_none]) (by simp [$[$progIdents:ident],*, Arm64.Obj.MultiPlacedLib.blockProgram, Arm64.Obj.PlacedLib.program, Arm64.Program.rebase]))) evalTactic (← `(tactic| wp_call $hcallBlkId:ident $[$opts]*)) let _ ← tryTactic do evalTactic (← `(tactic| clear $hcallBlkId:ident))
138 declarations not shown (lines 900–2568): theorems, which Lean checks, or definitions that no headline statement uses

Arm64.Obj.allIdx, Arm64.Obj.allIdx_spec, Arm64.Obj.CodeBlock.relocInRangeB, Arm64.Obj.CodeBlock.relocInRange_of, Arm64.Obj.CodeBlock.checkPlaceable, Arm64.Obj.CodeBlock.placeable_of_checkPlaceable, Arm64.Obj.checkRangesDisjoint, Arm64.Obj.rangesDisjoint_of_check, Arm64.Obj.sortedRangesB, Arm64.Obj.sortedRangesB_lo, Arm64.Obj.sortedRangesB_spec, Arm64.Obj.checkRangesDisjoint_of_sortedRangesB, Arm64.Obj.MultiPlacedLib.checkDataReloc, Arm64.Obj.MultiPlacedLib.checkBlocksPlaceable, Arm64.Obj.MultiPlacedLib.checkBlocksDisjoint, Arm64.Obj.MultiPlacedLib.checkBlockSymbolsNodup, Arm64.Obj.MultiPlacedLib.checkDataNodup, Arm64.Obj.MultiPlacedLib.checkDataPlaceable, Arm64.Obj.MultiPlacedLib.checkPlaceable, Arm64.Obj.MultiPlacedLib.placeable_of_split_checks, Arm64.Obj.MultiPlacedLib.exists_placeable_of_split_checks, Arm64.Obj.MultiPlacedLib.placeable_of_checkPlaceable, Arm64.Obj.checkElfMaps, Arm64.Obj.elfMaps_of_checkElfMaps, Arm64.Obj.blocksWalk, Arm64.Obj.blocksWalk_sound, Arm64.Obj.MultiPlacedLib.checkInElf, Arm64.Obj.MultiPlacedLib.checkInElf_spec, Arm64.Obj.Interned.Block.externs, Arm64.Obj.Interned.Block.weakRefs, Arm64.Obj.Interned.Block.align, Arm64.Obj.Interned.Block, Arm64.Obj.Interned.Block.code, Arm64.Obj.Interned.Block.relocs, Arm64.Obj.Interned.Block.symbols, Arm64.Obj.Interned.Block.toCodeBlock, Arm64.Obj.Interned.MultiLib.names, Arm64.Obj.Interned.MultiLib.exports, Arm64.Obj.Interned.MultiLib, Arm64.Obj.Interned.MultiLib.blocks, Arm64.Obj.Interned.MultiLib.name, Arm64.Obj.Interned.MultiLib.exportSyms, Arm64.Obj.Interned.MultiLib.data, Arm64.Obj.Interned.MultiLib.toMultiPlacedLib, Arm64.Obj.Interned.MultiLib.blockLib, Arm64.Obj.Interned.MultiLib.blockLib_block, Arm64.Obj.Interned.MultiLib.blockLib_names, Arm64.Obj.Interned.MultiLib.toMultiPlacedLib_blocks, Arm64.Obj.Interned.MultiLib.toMultiPlacedLib_data, Arm64.Obj.Interned.MultiLayout.b2b, Arm64.Obj.Interned.MultiLayout.undefWeak, Arm64.Obj.Interned.MultiLayout.addrs, Arm64.Obj.Interned.MultiLayout, Arm64.Obj.Interned.MultiLayout.bases, Arm64.Obj.Interned.MultiLayout.relax, Arm64.Obj.Interned.MultiLayout.blockLayout, Arm64.Obj.Interned.MultiLayout.dataLayout, Arm64.Obj.Interned.MultiLayout.toMultiPlacement, Arm64.Obj.Interned.Block.idsOk, Arm64.Obj.Interned.MultiLib.idsOk, …

end
5 declarations not shown (lines 2580–2639): theorems, which Lean checks, or definitions that no headline statement uses

Arm64.Obj.multiSymIndexExt, _private.0.Arm64.Obj.multiListElems, _private.0.Arm64.Obj.multiListElems.go, _private.0.Arm64.Obj.multiNatVal, _private.0.Arm64.Obj.multiStrVal, _private.0.Arm64.Obj.addPrebuiltTreeDef

syntax genMultiSymIndexL2641–2643 ↗#

gen_multi_sym_index <idxName> <lib>: precompute and kernel-certify an O(log B) / O(log S) MultiPlacedLib.SymIndex over <lib>.blocks and <lib>.data.

syntax (name := genMultiSymIndex) "gen_multi_sym_index " ident ppSpace ident : command
1 declaration not shown (lines 2645–2797): theorems, which Lean checks, or definitions that no headline statement uses

Arm64.Obj.elabGenMultiSymIndex