Documentation

GaudisCrypt.Lib.RO.TransferConvert

Lazy/eager transfer #

This file is the bridge between the lazy and eager random oracles.

Convert #

Fill in undefined entries of the random oracle with a fresh uniform function. The bridge between lazy and eager: applied to a lazy state, convert produces the same distribution as an eager state.

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

    convert only reads and writes random_oracle_state (probabilistic footprint form; drives the countability-free transfer-reflexivity).

    Convert algebra #

    theorem convert_mass (σ : state) :
    convert.wp (fun (x : Unit × state) => 1) σ = 1

    convert is a probability measure: its total mass is 1. All pieces (get, uniform, set) preserve mass.

    Explicit convert.wp formula derived from the definition.

    Foundational lazy/eager equations (the claim_* family) #

    lazy_init then convert = random_oracle_init. The eager initialisation is exactly the lazy initialisation followed by a fresh uniform sampling that fills the cache.

    theorem sum_update_eq_card_mul_sum {α : Type u_1} {β : Type u_2} [DecidableEq α] [Fintype α] [Fintype β] (i : α) (G : (α → β) → ENNReal) :
    ∑ v : β, ∑ y : α → β, G (Function.update y i v) = ↑(Fintype.card β) * ∑ z : α → β, G z

    Sum-over-Function.update reorganization (would-be-generic). Used by lazy_query_convert_eq_convert_random_oracle_query. Cannot be moved out of this file as-is because the local sorry'd Fintype (a → b) instance in Basic.lean shadows Mathlib's Pi.instFintype, causing type-class instance mismatches at the call site if the lemma is elaborated in a module that doesn't see the local instance. Move once the duplicate Fintype instance is removed.

    Value-passing lazy/eager bridge for lazy_query: lazy_query followed by convert (passing the value through) equals convert followed by random_oracle_query. This is the workhorse equation; the continuation form lazy_query_convert_cont_eq_convert_random_oracle_query is a corollary.

    Factor convert out of an if: if the then-branch starts with convert and the else-branch IS convert, we can move convert outside.

    convert is absorbed by random_oracle_init: a fresh uniform sample overwrites any prior RO content.

    convert is absorbed by any program that starts with random_oracle_init: convert >>= (random_oracle_init >>= rest) = random_oracle_init >>= rest. Used by convert_*_experiment_eager lemmas (where the experiment starts with random_oracle_init) to absorb a preceding convert step.

    Lazy/eager transfer relation: p followed by convert produces the same joint α × state distribution as convert followed by q.

    Captures "convert slides past p, turning lazy operations into eager ones". The instance of the generic ProgramDenotation.transferBy calculus at c := convert: closed under bind; reflexive on RO-disjoint programs. Together with the base cases lazy_init ↦ random_oracle_init (lazy_init_convert_eq_random_oracle_init) and lazy_query x ↦ random_oracle_query x (lazy_query_convert_eq_convert_random_oracle_query), this lets us transfer any program built from these primitives.

    Equations
    Instances For

      Reflexivity on RO-disjoint programs — countability-free (subtask 4). The Footprint analogue of transfer_refl_of_inRange_compl: a program whose probabilistic footprint avoids the RO table commutes with convert (via commute_of_disjoint_footprint, no [Countable]), so transfers to itself. The ᶜ-form makes the disjointness le_refl.

      Any program in v.footprint, for a v disjoint from random_oracle_state, transfers to itself — the countability-free Footprint analogue of transfer_of_inRange_disjoint.

      ProgramDenotation.set v x transfers to itself when v is disjoint from random_oracle_state. Countability-free (subtask 4): via the Footprint transfer-reflexivity.

      ProgramDenotation.get v transfers to itself when v is disjoint from random_oracle_state. Countability-free (subtask 4).

      convert commutes with ProgramDenotation.set v x for any v disjoint from random_oracle_state: the bind form of transfer_set_of_disjoint_ro.

      convert commutes with ProgramDenotation.get v for any v disjoint from random_oracle_state, in continuation-passing form: the continuation form of transfer_get_of_disjoint_ro.

      ProgramDenotation.uniform transfers to itself (it doesn't touch state at all). Countability-free (subtask 4).

      theorem ProgramDenotation.transfer_bind {α β : Type} {p q : GaudisCrypt.ProgramDenotation state α} {p' q' : α → GaudisCrypt.ProgramDenotation state β} (h : transfer p q) (h' : ∀ (a : α), transfer (p' a) (q' a)) :
      transfer (p >>= p') (q >>= q')

      Bind closure: transfer chains under >>=.

      theorem ProgramDenotation.transfer_pure {α : Type} (a : α) :

      Pure transfers to itself.

      Transfer is preserved by while_loop. If the body transfers (lazy to eager) and the condition is RO-disjoint, then the lazy and eager while-loops transfer.

      Instance of the generic Kleene closure ProgramDenotation.transferBy_while_loop; the condition's self-transfer comes from its RO-disjointness via the footprint transfer-reflexivity. Any RO-based while-loop construction inherits the lazy = eager equivalence by this closure law plus the base-case body transfer.

      theorem ProgramDenotation.transfer_value_marginal {α : Type} {p q : GaudisCrypt.ProgramDenotation state α} (h_transfer : transfer p q) (h_absorb : (do convert q) = q) (σ₀ : state) :
      (do let aσ ← p σ₀ pure aσ.1) = do let aσ ← q σ₀ pure aσ.1

      Value marginal: SubProb-level statement of the transfer. (For the wp-level value-only bridge, use ProgramDenotation.transferBy_wp_value with convert_mass.)

      Enriched transfer: RO-invariant projections of state #

      The basic transfer_wp_value only delivers wp-equality for posts that ignore the state. But convert only writes random_oracle_state — so any projection of state that is invariant under random_oracle_state.set is automatically preserved by convert. This means we can transfer postconditions that depend on (value, RO-invariant state projection).

      These enriched lemmas recover the full strength of the wrapper-style oracle_loop_wp_lazy_eq_random_oracle and its marginal/compl/glob companions, without rebuilding the Kleene argument.

      theorem convert_wp_state_const_of_ro_invariant (G : state → ENNReal) (hG_inv : ∀ (σ : state) (x : input → Option output), G (random_oracle_state.set x σ) = G σ) (σ : state) :
      convert.wp (fun (aσ : Unit × state) => G aσ.2) σ = G σ

      convert preserves any state projection G : state → ENNReal that is invariant under writes to random_oracle_state. Because convert only samples a fresh RO function and writes it, an RO-invariant G is constant along the convert trajectory, and convert's total mass is 1.

      theorem ProgramDenotation.transfer_wp_ro_invariant {α : Type} {p q : GaudisCrypt.ProgramDenotation state α} (h_transfer : transfer p q) (h_absorb : (do convert q) = q) (F : α × state → ENNReal) (hF_inv : ∀ (a : α) (σ : state) (x : input → Option output), F (a, random_oracle_state.set x σ) = F (a, σ)) (σ₀ : state) :
      p.wp F σ₀ = q.wp F σ₀

      Transfer at the wp level for RO-invariant postconditions. Strict strengthening of transfer_wp_value: instead of requiring the post to ignore state entirely, only requires it to be invariant under writes to random_oracle_state.

      Captures the wrapper-style oracle_loop_wp_lazy_eq_random_oracle.

      theorem ProgramDenotation.transfer_marginal_ro_invariant {α β : Type} {p q : GaudisCrypt.ProgramDenotation state α} (h_transfer : transfer p q) (h_absorb : (do convert q) = q) (h : state → β) (h_inv : ∀ (σ : state) (x : input → Option output), h (random_oracle_state.set x σ) = h σ) (σ₀ : state) :
      (do let aσ ← p σ₀ pure (aσ.1, h aσ.2)) = do let aσ ← q σ₀ pure (aσ.1, h aσ.2)

      Marginal at the (value × RO-invariant projection) level.

      Strict strengthening of transfer_value_marginal: instead of projecting to just the value, we additionally include any RO-invariant projection h : state → β. Captures the wrapper-style oracle_loop_marginal_lazy_eq_random_oracle family.