Deterministic Code Predicate #
This file provides the IsDeterministic predicate for RawCode,
identifying computations that never use sample or fail.
Main definitions #
IsDeterministic- Predicate: code never usessampleorfailDetCode- Bundled deterministic code with proof
Motivation #
CatCrypt code is defined in terms of RawCode, which supports probabilistic
sampling. However, many extracted programs (from hax) are purely deterministic:
they only use ret, bind, get, and put. This predicate identifies
such programs, enabling reasoning about determinism in cryptographic proofs.
IsDeterministic Predicate #
A RawCode computation is deterministic if it never uses sample or fail.
This is an inductive predicate that closely mirrors the structure of ValidCode
but without the location constraints and without the sample/fail cases.
A computation is deterministic if it only uses ret, bind, get, and put.
No probabilistic sampling or failure is allowed.
- ret {α : Type u} (a : α) : IsDeterministic (RawCode.ret a)
- bind {α β : Type u} (c : RawCode α) (k : α → RawCode β) (hc : IsDeterministic c) (hk : ∀ (a : α), IsDeterministic (k a)) : IsDeterministic (c.bind k)
- get (ℓ : Core.Location) : IsDeterministic (RawCode.get ℓ)
- put (ℓ : Core.Location) (v : ℓ.ty) : IsDeterministic (RawCode.put ℓ v)
Instances For
Properties of IsDeterministic #
Deterministic code never starts with fail.
Deterministic code never starts with sample.
Deterministic code never starts with oracleCall.
Deterministic code never starts with embed — an embedded SPComp may
be probabilistic, so we conservatively rule it out of the deterministic
fragment.
If bind c k is deterministic, then c is deterministic.
If bind c k is deterministic, then k a is deterministic for all a.
Deterministic code has a nonempty return type.
This follows because every deterministic code form produces a value:
ret a has a, get returns ULift ℓ.ty (inhabited), put returns ULift Unit,
and bind inherits from its continuation.
Combinators for Deterministic Code #
Helper combinators that maintain the IsDeterministic predicate.
A deterministic computation bundled with its proof.
- code : RawCode α
- isDet : IsDeterministic self.code
Instances For
Pure return is deterministic.
Equations
- CatCrypt.Deep.DetCode.ret a = { code := CatCrypt.Deep.RawCode.ret a, isDet := ⋯ }
Instances For
Get is deterministic.
Equations
- CatCrypt.Deep.DetCode.get ℓ = { code := CatCrypt.Deep.RawCode.get ℓ, isDet := ⋯ }
Instances For
Put is deterministic.
Equations
- CatCrypt.Deep.DetCode.put ℓ v = { code := CatCrypt.Deep.RawCode.put ℓ v, isDet := ⋯ }