Documentation

CatCryptCore.Deep.PackageEquiv

Package Behavioral Equivalence #

This file defines behavioral equivalence for deep packages and proves that package linking preserves it.

Main definitions #

Main results #

Design #

Behavioral equivalence is defined semantically using evalWith, which interprets RawCode into SPComp given an oracle handler. Two packages are equivalent when, for every shared exported operation, evaluating their implementations with any oracle handler yields the same SPComp computation.

This is stronger than just comparing eval (which maps unresolved oracles to fail), because it captures how the packages behave when composed with arbitrary environments.

References #

Behavioral Equivalence #

Two deep packages are behaviorally equivalent if:

  1. They have the same export interface.
  2. For every exported operation and every oracle handler, their implementations produce the same SPComp computation.

This captures semantic equivalence: the packages are interchangeable in any context (linking environment). Using evalWith rather than eval ensures we account for how the code behaves when oracle calls are resolved by an arbitrary environment.

Instances For

    Behavioral equivalence is reflexive.

    theorem CatCrypt.Deep.DeepPackage.BehavEquiv.symm {p₁ p₂ : DeepPackage} (h : p₁.BehavEquiv p₂) :
    p₂.BehavEquiv p₁

    Behavioral equivalence is symmetric.

    theorem CatCrypt.Deep.DeepPackage.BehavEquiv.trans {p₁ p₂ p₃ : DeepPackage} (h₁₂ : p₁.BehavEquiv p₂) (h₂₃ : p₂.BehavEquiv p₃) :
    p₁.BehavEquiv p₃

    Behavioral equivalence is transitive.

    Linking Correctness #

    Linking Preserves Behavioral Equivalence #

    Advantage from Behavioral Equivalence #

    theorem CatCrypt.Deep.DeepPackage.BehavEquiv.evalOp_eq {p₁ p₂ : DeepPackage} (h : p₁.BehavEquiv p₂) (op : ) (dom codom : Type u) (h₁ : (op, dom, codom) p₁.exports.ops) (h₂ : (op, dom, codom) p₂.exports.ops) (x : dom) :
    p₁.evalOp op dom codom h₁ x = p₂.evalOp op dom codom h₂ x

    If two packages are behaviorally equivalent, evaluating any exported operation (with eval, i.e., unresolved oracles become fail) gives the same SPComp.

    Useful Derived Lemmas #

    theorem CatCrypt.Deep.DeepPackage.BehavEquiv.rHoare_evalOp {p₁ p₂ : DeepPackage} (h : p₁.BehavEquiv p₂) (op : ) (dom codom : Type u) (h₁ : (op, dom, codom) p₁.exports.ops) (h₂ : (op, dom, codom) p₂.exports.ops) (x : dom) :
    Relational.rHoare Relational.eqPre (p₁.evalOp op dom codom h₁ x) (p₂.evalOp op dom codom h₂ x) Relational.eqPost

    rHoare from behavioral equivalence: equivalent packages satisfy relational Hoare logic with eqPre/eqPost.