Documentation

CatCryptCore.Deep.Deterministic

Deterministic Code Predicate #

This file provides the IsDeterministic predicate for RawCode, identifying computations that never use sample or fail.

Main definitions #

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.

inductive CatCrypt.Deep.IsDeterministic {α : Type u} :
RawCode αProp

A computation is deterministic if it only uses ret, bind, get, and put. No probabilistic sampling or failure is allowed.

Instances For

    Properties of IsDeterministic #

    Deterministic code never starts with fail.

    Deterministic code never starts with sample.

    theorem CatCrypt.Deep.IsDeterministic.not_oracleCall {op : } {dom codom : Type u} {x : dom} :

    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.

    theorem CatCrypt.Deep.IsDeterministic.of_bind_left {α β : Type u} {c : RawCode α} {k : αRawCode β} (h : IsDeterministic (c.bind k)) :

    If bind c k is deterministic, then c is deterministic.

    theorem CatCrypt.Deep.IsDeterministic.of_bind_right {α β : Type u} {c : RawCode α} {k : αRawCode β} (h : IsDeterministic (c.bind k)) (a : α) :

    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.

    structure CatCrypt.Deep.DetCode (α : Type u) :
    Type (u + 1)

    A deterministic computation bundled with its proof.

    Instances For
      def CatCrypt.Deep.DetCode.ret {α : Type u} (a : α) :

      Pure return is deterministic.

      Equations
      Instances For
        def CatCrypt.Deep.DetCode.bind {α β : Type u} (x : DetCode α) (f : αDetCode β) :

        Bind preserves determinism.

        Equations
        Instances For

          Get is deterministic.

          Equations
          Instances For

            Put is deterministic.

            Equations
            Instances For