Documentation

CatCryptCore.Deep.HybridDemo

Hybrid Argument Demonstration using Deep Embedding #

This file demonstrates how the deep embedding of CatCrypt enables cleaner and more structured hybrid argument proofs in cryptography.

Overview #

A hybrid argument is a proof technique where we show two games are equivalent by constructing a sequence of intermediate games:

Game0 ~ Game1 ~ Game2 ~ ... ~ GameN

where each adjacent pair differs in a small, analyzable way. The deep embedding provides several advantages for such proofs:

  1. Structural Induction: We can analyze games by their syntactic structure using RawCode.inductionOn, rather than semantic simulation.

  2. Separation Reasoning: The location set structure provides automatic reasoning about disjoint state through DeepPackage.sep.

  3. Compositional Reasoning: Package composition (link, par) preserves separation properties.

Comparison with Shallow Embedding #

In the shallow embedding (standard CatCrypt), games are represented as Lean functions. Proving equivalence requires manual tracking of state invariants, explicit coupling constructions, and complex simulation arguments.

In the deep embedding, games are syntax trees that allow structural induction on syntax, automatic support/disjointness reasoning, and compositional separation properties.

References #

Example Interfaces #

Simple interface with one operation: query : Unit -> Nat

Equations
Instances For

    Behavioral Equivalence #

    Behavioral equivalence of deep packages based on export interface equality.

    In a full development, this would compare implementations via denotational semantics. Here we use a simplified definition based on exports.

    Equations
    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Transitivity of Equivalence #

        Behavioral equivalence is reflexive

        theorem CatCrypt.Deep.HybridDemo.BehavioralEquiv.symm {p₁ p₂ : DeepPackage} (h : p₁ ≈ᵇ p₂) :
        p₂ ≈ᵇ p₁

        Behavioral equivalence is symmetric

        theorem CatCrypt.Deep.HybridDemo.BehavioralEquiv.trans {p₁ p₂ p₃ : DeepPackage} (h₁₂ : p₁ ≈ᵇ p₂) (h₂₃ : p₂ ≈ᵇ p₃) :
        p₁ ≈ᵇ p₃

        Behavioral equivalence is transitive

        Separation Properties Demo #

        theorem CatCrypt.Deep.HybridDemo.sep_of_disjoint_locs (p₁ : DeepPackage) (p₂ : DeepPackage) (h : Disjoint p₁.locs p₂.locs) :
        p₁.sep p₂

        Demonstration: two packages with disjoint location ids are separated.

        Hybrid Sequence Structure #

        A hybrid argument is a sequence of games with adjacent equivalences.

        Instances For
          theorem CatCrypt.Deep.HybridDemo.hybrid_transitivity (games : List DeepPackage) (h_nonempty : games []) (h_adj : ∀ (i : ), i + 1 < games.lengthgames.getD i DeepPackage.empty ≈ᵇ games.getD (i + 1) DeepPackage.empty) :
          games.head h_nonempty ≈ᵇ games.getLast h_nonempty

          The first and last games in a hybrid sequence are equivalent if all adjacent pairs are equivalent.

          This is the key theorem for hybrid arguments: we can chain together local equivalences to get global equivalence.

          Documentation: Benefits of Deep Embedding for Hybrid Arguments #

          Key Advantages #

          1. Explicit Syntax Trees

            • Games are data structures, not opaque functions
            • We can pattern match on code structure
            • Transformations are explicit and verifiable
          2. Structural Induction

            • RawCode.inductionOn provides a principled way to analyze all code paths
            • No need for complex simulation relations
            • Proof follows the syntax structure
          3. Separation via Location Sets

            • DeepPackage.sep p1 p2 captures state disjointness
            • Composition preserves separation (par_sep_left, par_sep_right)
          4. Compositional Reasoning

            • Link and parallel composition have algebraic properties
            • Separation is compositional

          Comparison: Shallow vs Deep #

          AspectShallowDeep
          GamesFunctionsSyntax trees
          EquivalenceCoupling/simulationStructural + semantic
          State separationManual invariantsAutomatic via sep
          InductionSemantic domainSyntax structure

          When to Use Deep Embedding #

          The deep embedding is particularly beneficial when:

          For simple proofs where semantic reasoning suffices, the shallow embedding may be more direct.