One edge of a br i1 into blocks with phis (Block.sound_to)
Lean: MojoProof/Sym/Checker.lean (the checker) and MojoProof/Sym/Path.lean (the proof).
Tests: MojoProofTest/SymPhi.lean, the section "A br i1 into blocks with phis, one edge at a
time".
Scope. Every program P, function fn, block lbl, entry position p0, target d₀,
condition list ds and summary S that coversTo P fn lbl p0 d₀ ds S accepts, every context of
P and every thread whose innermost frame runs fn at block lbl's position p0, with any
memory, whenever the exit goes to d₀. Along a path: every path that coversPathWith contract
accepts, for either value of the flag, each block but the last by covers or by coversTo for the
edge into the next block (their coversWith forms with the flag).
Why one edge. SState.phiExit gives br i1 c, d, e into blocks with phis the obligations
of both edges (SState.phiConds fn lbl d ++ SState.phiConds fn lbl e). A phi operand of the
untaken edge that is outside the fragment (an undef, say) makes summarize none, and
one that faults makes the block's premises fail, although the run never reads it.
Statement
Definitions. summarizeWith P fn lbl p0 ex is summarize's body with the exit and its
obligations from ex σ b.term (ex : SState → Term → Option (Exit × List Cond)); coversWith is
covers's with summarizeWith. summarize and covers are their instances with
ex := fun σ tm => σ.exitAt fn lbl tm. SState.phiExitTo fn lbl
d₀ σ is SState.phiExit except on br i1 c, d, e: the exit .phi x d e with the obligations
.bool x :: SState.phiConds fn lbl d₀ (the edge into d₀ only); SState.exitTo is
SState.exit's exit, else SState.phiExitTo's; coversTo P fn lbl p0 d₀ := coversWith P fn lbl p0
(fun σ tm => σ.exitTo fn lbl d₀ tm). coversPathWith contract's step
(l, ds, S) :: (l', ds', S') :: ps checks coversWith with the flag at SState.exitAt or at
SState.exitTo the next label: without the flag, covers P fn l p0 ds S || coversTo P fn l p0 l'
ds S.
SState.exitTo_sound: underRelat the block's end (after its statements), ifσ.exitTo fe.fn fe.label d₀ b.term = some (x, cs), every condition ofcsholds andx.dest V vs = some d₀, thenx.next V vs rest k fe me = .ok rand the terminator's step is.ok r.Block.sound_withAt:Block.soundforcoversAtwith anyexwhose exit, at the block's end, is the terminator's step whenever its obligations hold (premisehex), and either value of the flagsallocaandcontract. It concludesEndsAt contract ∧ Ptrs; with the flagallocaoffEndsAt.endsmakes itEndsWith contract ∧ Ptrs, which isEnds ∧ Ptrswithoutcontract(docs/proofs/ptrs.md, docs/proofs/contract.md).Block.soundisBlock.sound_withAtwithSState.exitAt_sound(Block.sound_atWith), throughBlock.sound_ptrs(Ends ∧ Ptrs).Block.sound_to:Block.soundforcoversTo P fn lbl p0 d₀(Block.sound_toWithwithout the flag), with the extra premiseS.exit.dest (Valuation.entry c t.k m f) (vals … S.nodes) = some d₀; it concludesEnds ∧ Ptrs.Block.sound_pathWith_ptrsandBlock.sound_retWithfor the paths thatcoversPathWithaccepts; the first half ofBlock.sound_pathWith_ptrsis the last block'sEndsWith.
Proof
- If
SState.exitgives the exit,SState.exit_sound. OtherwiseSState.phiExitTo: onbr i1the obligation.bool xgives the wordbvand the condition's value (SState.op_eval); the premisex.dest = some d₀says(if bv.getLsbD 0 then d else e) = d₀, so the edge's obligations are those of the taken target, andSState.enter_okgivesenter's frame;stepandExit.nextboth enter it. On other terminatorsSState.phiExitToisSState.phiExit, soSState.exitAt_sound. Block.sound's proof with the call ofSState.exitAt_soundreplaced byhex.- and 4.
hexfrom items 1 andSState.exitAt_sound(Relgivesfe.fn = f.fnandfe.label = f.label). - In
Block.sound_pathWith_ptrs's step the head block'sEndsWithcomes fromBlock.sound_atWithor fromBlock.sound_toWithwith the premiseExit.dest = some l'thatWalkWithcontains;Ends.edgeWithenters the next block andEndsWith.preprepends the steps.
Dependencies
SState.exit_sound, SState.exitAt_sound, SState.op_eval, SState.enter_ok, Exit.dest,
Ends.edge, step and enter (MojoProof/Sem/Thread.lean).
Instances
MojoProofTest/SymPhi.lean, one program written in the test (edgeF, three blocks), one context
(ctxE), memory (mem0) and frame (frameE true): entryTo is the entry block's summary for the
edge into block 1, edge_covers accepts the path 0 → 1 (the entry block by coversTo),
edge_walk its premises, and edge_run (Block.sound_retWith) runs the thread to block 1's
ret.
entry_both: summarize accepts the entry block with both edges' obligations, block 2's float
constant 1.5 as its node 0 (SNode.flit), whose obligation holds at frameE true. Twins
(edge_twins): coversTo refuses the corrupted certificates entryTo without its first
obligation and with no obligations, the path 0 → 2 with entryTo is refused, and with %3 = 0
the premises fail.
Limits
A path fixes the edge, so a br i1 with both successors reached by different paths of a
certificate needs one path per edge. phi operands are registers, integer constants and float
constants only.
Cond has no implication (no constructor for it): the per-edge obligations
are the path's choice, not a condition under the branch.