Basic CatCrypt Tactics #
This file provides basic tactic automation for CatCrypt proofs, including tactics for ValidCode goals and code simplification.
Main tactics #
ssprove_valid- tactic for proving ValidCode goalsssprove_code_simpl- tactic for simplifying code (normalize bind associativity)
Simp sets #
ssprove_simpl- named simp set for SPComp normalization (declared in SimpAttr.lean)ssprove_eval- named simp set for deep→shallow evaluation (declared in SimpAttr.lean)
References #
- SSProve: theories/Crypt/package/pkg_tactics.v
Simp Set Population #
The simp sets are declared in CatCrypt.Tactics.SimpAttr (separate file
required because register_simp_attr creates attributes that cannot be
used in the same file they are declared in).
ValidCode Tactics #
ssprove_valid is a tactic for proving ValidCode goals.
This tactic attempts to discharge ValidCode obligations by:
- Unfolding definitions
- Applying structural rules for bind, return, sample, etc.
- Checking that operations access only permitted locations
Example:
theorem mycode_valid : ValidCode L I (do
let x ← get loc
return x) := by
ssprove_valid
Equations
- CatCrypt.Tactics.tacticSsprove_valid = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_valid 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_valid" false)
Instances For
ssprove_code_simpl is a tactic for simplifying CatCrypt code.
This tactic normalizes code by:
- Associating binds to the right:
(x >>= f) >>= g→x >>= (fun a => f a >>= g) - Simplifying pure/return:
pure a >>= f→f a - Eliminating dead code (unused sample, get, pure)
- Contracting redundant operations (duplicate get/put, put-get)
- Copy propagation (set-get same location)
Example:
example : ((c >>= f) >>= g) = (c >>= fun x => f x >>= g) := by
ssprove_code_simpl
Equations
- CatCrypt.Tactics.tacticSsprove_code_simpl = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_code_simpl 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_code_simpl" false)
Instances For
ssprove_valid! is a more aggressive version of ssprove_valid
that uses additional automation.
Equations
- CatCrypt.Tactics.tacticSsprove_valid! = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_valid! 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_valid!" false)
Instances For
Distribution-Level Simplification #
The ssprove_distr_simp tactic normalizes terms at the SDistr level,
after SPComp definitions have been unfolded. This handles the common pattern:
simp only [SPComp.bind_def, SPComp.sample, SPComp.pure_def,
SDistr.bind_assoc, SDistr.pure_bind]
which appears 100+ times across shallow embedding proofs.
ssprove_distr_simp normalizes sub-distribution terms.
After unfolding SPComp to SDistr, this tactic reassociates binds, eliminates pure-bind pairs, and normalizes sampling definitions.
Example:
-- Goal involves (SDistr.uniform α).bind (fun a => (SDistr.pure (a, h)).bind ...)
ssprove_distr_simp
-- Goal is now normalized with bind_assoc and pure_bind applied
Equations
- CatCrypt.Tactics.tacticSsprove_distr_simp = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_distr_simp 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_distr_simp" false)
Instances For
Enhanced Monadic Normalization #
The ssprove_proc tactic normalizes SPComp programs at the monadic level,
analogous to EasyCrypt's proc; inline *; auto. It chains bind_assoc,
pure_bind, bind_pure, monad_bind_eq, and monad_pure_eq, then tries
congr/funext to push through binders, and rfl to close.
This replaces the common 5-10 line pattern:
simp only [SPComp.monad_bind_eq, SPComp.bind_assoc, SPComp.pure_bind, ...]
congr 1; funext _
simp only [...]
rfl
with a single ssprove_proc call.
ssprove_proc normalizes SPComp monadic programs.
Analogous to EasyCrypt's proc; inline *; auto:
- Simplify with
monad_bind_eq,bind_assoc,pure_bind,bind_pure - Try
rfl - If stuck, try
congr 1; funextto descend through binders
Equations
- CatCrypt.Tactics.tacticSsprove_proc = Lean.ParserDescr.node `CatCrypt.Tactics.tacticSsprove_proc 1024 (Lean.ParserDescr.nonReservedSymbol "ssprove_proc" false)
Instances For
ssprove_proc_unfold defs unfolds definitions then normalizes.
Usage: ssprove_proc_unfold my_real my_ideal
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bijection Coupling Tactic #
The ssprove_rnd tactic automates change-of-variables on sampling steps,
analogous to EasyCrypt's rnd f g; auto. Given a goal about SPComp.sample,
it applies a bijection to transform the distribution.
This replaces:
apply sdist_of_eq
congr 1; funext a
exact SPComp.sample_bind_equiv (Equiv.addRight k) (fun a => ...)
with ssprove_rnd (Equiv.addRight k).
ssprove_rnd e applies bijection e : α ≃ β to a sampling step.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Exponentiation Normalization Tactic #
The exp_simp tactic normalizes group exponentiation terms, analogous to
EasyCrypt's algebra tactic. It:
- Rewrites
groupExp (exp w) etoexp (w * e)viagroupExp_mul' - Combines
exp a * exp btoexp (a + b)viaexp_add' - Normalizes raw field accessors (
smul,sadd) to notation (*,+) - Tries
ringon remaining scalar goals insideexp - Tries
groupon remaining group goals
This closes goals like exp(a*b+c) * exp(d) = exp(b*a+c+d) in one step.
Equations
- CatCrypt.Tactics.tacticExp_simp = Lean.ParserDescr.node `CatCrypt.Tactics.tacticExp_simp 1024 (Lean.ParserDescr.nonReservedSymbol "exp_simp" false)