Weakest Precondition Tactics #
This file provides tactics for weakest precondition reasoning in pRHL,
analogous to EasyCrypt's wp tactic.
Main tactics #
ssprove_wp- process deterministic suffix backwards, computing the WPssprove_wp_step- process one WP step from the tail
What EasyCrypt does #
EasyCrypt's wp processes the deterministic suffix of programs backwards,
computing the weakest precondition. For each assignment x <- e, it
substitutes e for x in the postcondition. It stops at random sampling,
procedure calls, or loops.
How it maps to SPComp #
In our monadic setting, the "deterministic suffix" consists of pure, get,
set operations chained by >>=. The wp computation:
| SPComp tail | WP transformation |
|---|---|
pure v | Substitute v for result in postcondition |
set l v >>= fun _ => k | Push heap update into postcondition |
get l >>= fun x => k | Push heap lookup into postcondition |
sample, fail | Stop — non-deterministic |
References #
- EasyCrypt: ecWp tactic
WP Rules: Absorbing Tail Operations into Postcondition #
These rules process the deterministic suffix of both programs simultaneously,
absorbing pure, get, and set operations into the postcondition.
WP for pure f(x) at the end of both programs.
Both programs end with c >>= fun x => pure (f x). We absorb the
pure map into the postcondition: instead of proving Ψ (f a) h₁ (f b) h₂,
we prove a judgment about c₁ and c₂ with a modified postcondition
that pre-applies f₁ and f₂.
WP for set l (g x) at the end of both programs.
Both programs end with c >>= fun x => set l₁ (g₁ x) and
c >>= fun x => set l₂ (g₂ x). We absorb the set into the
postcondition by requiring Ψ to hold after the heap updates.
WP for get l followed by pure (absorbs get into postcondition).
Both programs do c >>= fun x => get l >>= fun v => pure (f x v) at the tail.
We absorb this by substituting h.get l for v in the postcondition.
Note: γ, δ constrained to Type since l.ty : Type.
One-Sided WP Rules #
These rules process the deterministic suffix on only one side.
WP for pure f(x) on the left side only.
WP for pure f(x) on the right side only.
WP for set l (g x) on the left side only.
WP for set l (g x) on the right side only.
WP Tactics #
ssprove_wp processes the deterministic suffix of both programs
backwards, computing the weakest precondition.
It repeatedly peels off deterministic tail operations (pure, set, get)
from both sides, absorbing them into the postcondition.
The tactic stops at sample, fail, or any non-deterministic operation.
Example:
-- Before ssprove_wp:
-- rHoare Φ (do let k ← sample Bool; pure (xor k x))
-- (do let k ← sample Bool; pure k)
-- (fun a h₁ b h₂ => a = b)
-- After ssprove_wp:
-- rHoare Φ (sample Bool) (sample Bool)
-- (fun k₁ h₁ k₂ h₂ => xor k₁ x = k₂)
Equations
- CatCrypt.Tactics.tacticSsprove_wp = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_wp 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_wp" false)
Instances For
ssprove_wp_step processes exactly one wp step from the tail.
Equations
- CatCrypt.Tactics.tacticSsprove_wp_step = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_wp_step 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_wp_step" false)