Documentation

CslibFrontier.Crypto.Protocols.UC.AdaptiveStorage

Write-once non-erasing storage and coin exposure for adaptive UC #

This module wraps an AdaptiveProtocol in an explicit append-only per-party log and honest-coin exposure layer (AdaptiveProtocol.withWriteOnce), motivated by the non-erasing party model of [Can20a], Section 7.1.1 (p. 28:71, as cited in CslibFrontier.Crypto.Protocols.UC.Adaptive).

In the base snapshot model of UC.Adaptive, AdaptiveProtocol.view is an arbitrary caller-supplied projection that may hide stored secrets (View := Unit) or omit coins drawn and discarded within a single activation, while recordSnapshot appends snapshots for every party after every activation (including .net calls and other parties' activations).

AdaptiveProtocol.withWriteOnce P mem augments P's state to WriteOnceState by recording per-party tapes i: an append-only oldest-first list of PartyActivationRecords containing the input, output, every intra-activation ProbComp.unifFin draw (coins : OracleComp.Transcript unifSpec), and post-activation P.view snapshot for every .inl (i, x) activation of party i.

Scope #

This module extends the library's snapshot, call-bounded, fixed-n-party port model (UC.Adaptive; #6043) and is not a formalization of full PPT interactive Turing machines with write-once worktapes from [Can20a] §7.1.1:

Main definitions #

Main results #

References #

Non-intrusive coin-tape instrumentation #

Execute an OracleSpec.empty-imported private-coin program starting from an initial coin tape, appending every ProbComp.unifFin k draw ⟨k, r⟩ in oldest-first order.

Execute an OracleSpec.empty-imported private-coin program while logging every ProbComp.unifFin draw in oldest-first order.

theorem Cslib.Crypto.Protocols.UC.recordCoinsFrom_bind {α β : Type} (tape : OracleComp.Transcript unifSpec) (program : ProbOracleComp OracleSpec.empty α) (next : α → ProbOracleComp OracleSpec.empty β) :
recordCoinsFrom tape (program >>= next) = do let p ← recordCoinsFrom tape program recordCoinsFrom p.2 (next p.1)

Forgetting the recorded coin tape from recordCoins recovers the original program identically.

recordCoins preserves query budgets with zero overhead.

Write-once storage wrapper and monotonicity invariants #

Single party activation record appended to party i's write-once tape: input, optional output, all ProbComp.unifFin draws sampled during that activation (coins), and party i's post-activation P.view snapshot (postView).

  • input : In

    Input passed to party i for this activation.

  • output : Option Out

    Output returned by party i for this activation, if any.

  • Oldest-first list of ProbComp.unifFin draws consumed during this activation.

  • postView : View

    Inner protocol's view of party i immediately after this activation.

Instances For
    @[instance_reducible]
    instance Cslib.Crypto.Protocols.UC.instDecidableEqPartyActivationRecord {In✝ Out✝ View✝ : Type} [DecidableEq In✝] [DecidableEq Out✝] [DecidableEq View✝] :
    DecidableEq (PartyActivationRecord In✝ Out✝ View✝)
    def Cslib.Crypto.Protocols.UC.instDecidableEqPartyActivationRecord.decEq {In✝ Out✝ View✝ : Type} [DecidableEq In✝] [DecidableEq Out✝] [DecidableEq View✝] (x✝ x✝¹ : PartyActivationRecord In✝ Out✝ View✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    instance Cslib.Crypto.Protocols.UC.instReprPartyActivationRecord {In✝ Out✝ View✝ : Type} [Repr In✝] [Repr Out✝] [Repr View✝] :
    Repr (PartyActivationRecord In✝ Out✝ View✝)
    def Cslib.Crypto.Protocols.UC.instReprPartyActivationRecord.repr {In✝ Out✝ View✝ : Type} [Repr In✝] [Repr Out✝] [Repr View✝] :
    PartyActivationRecord In✝ Out✝ View✝ → ℕ → Std.Format
    structure Cslib.Crypto.Protocols.UC.WriteOnceState (S In Out View : Type) (n : ℕ) :

    Write-once, append-only state wrapper for P.machine κ.

    View exposed upon corrupting party i under AdaptiveProtocol.withWriteOnce: combines the inner protocol's current view with party i's complete write-once activation and coin tape (some when .nonErasing, none when .erasing).

    • current : View

      Current inner-protocol view at corruption time.

    • tape : Option (List (PartyActivationRecord In Out View))

      Complete append-only activation and coin tape (some iff .nonErasing).

    Instances For
      def Cslib.Crypto.Protocols.UC.instDecidableEqWriteOnceView.decEq {In✝ Out✝ View✝ : Type} [DecidableEq In✝] [DecidableEq Out✝] [DecidableEq View✝] (x✝ x✝¹ : WriteOnceView In✝ Out✝ View✝) :
      Decidable (x✝ = x✝¹)
      @[instance_reducible]
      instance Cslib.Crypto.Protocols.UC.instDecidableEqWriteOnceView {In✝ Out✝ View✝ : Type} [DecidableEq In✝] [DecidableEq Out✝] [DecidableEq View✝] :
      DecidableEq (WriteOnceView In✝ Out✝ View✝)
      def Cslib.Crypto.Protocols.UC.instReprWriteOnceView.repr {In✝ Out✝ View✝ : Type} [Repr In✝] [Repr Out✝] [Repr View✝] :
      WriteOnceView In✝ Out✝ View✝ → ℕ → Std.Format
      @[instance_reducible]
      instance Cslib.Crypto.Protocols.UC.instReprWriteOnceView {In✝ Out✝ View✝ : Type} [Repr In✝] [Repr Out✝] [Repr View✝] :
      Repr (WriteOnceView In✝ Out✝ View✝)
      def Cslib.Crypto.Protocols.UC.WriteOnceState.TapePrefix {n : ℕ} {In Out View S : Type} (s₁ s₂ : WriteOnceState S In Out View n) :

      Per-party prefix monotonicity relation on WriteOnceState: every party's tape in s₁ is a prefix of its tape in s₂.

      theorem Cslib.Crypto.Protocols.UC.WriteOnceState.TapePrefix.refl {n : ℕ} {In Out View S : Type} (s : WriteOnceState S In Out View n) :
      theorem Cslib.Crypto.Protocols.UC.WriteOnceState.TapePrefix.trans {n : ℕ} {In Out View S : Type} {s₁ s₂ s₃ : WriteOnceState S In Out View n} (h₁₂ : s₁.TapePrefix s₂) (h₂₃ : s₂.TapePrefix s₃) :
      s₁.TapePrefix s₃
      def Cslib.Crypto.Protocols.UC.AdaptiveProtocol.withWriteOnce {n : ℕ} {In Out NetQ NetR View : Type} (P : AdaptiveProtocol n In Out NetQ NetR View) (mem : PartyMemory) :
      AdaptiveProtocol n In Out NetQ NetR (WriteOnceView In Out View)

      Wrap an AdaptiveProtocol in explicit Canetti §7.1.1-inspired write-once per-party execution and coin-exposure storage. Each .inl (i, x) party activation logs { input, output, coins, postView } to tapes i without modifying tapes j (j ≠ i); .inr q network/backdoor calls leave all tapes unchanged; onCorrupt forwards to P.onCorrupt on inner while preserving all tapes.

      theorem Cslib.Crypto.Protocols.UC.withWriteOnce_handle_inl_tapePrefix {n : ℕ} {In Out NetQ NetR View : Type} (P : AdaptiveProtocol n In Out NetQ NetR View) (mem : PartyMemory) (κ : ℕ) (i : Fin n) (x : In) (s : WriteOnceState (P.machine κ).State In Out View n) {out : Option Out} {s' : WriteOnceState (P.machine κ).State In Out View n} (hs : (out, s') ∈ (Machine.closeEval ((((P.withWriteOnce mem).machine κ).handle (Sum.inl (i, x))).run s)).support) :
      s.TapePrefix s' ∧ (∃ (r : PartyActivationRecord In Out View), s'.tapes i = s.tapes i ++ [r]) ∧ ∀ (j : Fin n), j ≠ i → s'.tapes j = s.tapes j

      Every reachable post-state of an .inl (i, x) activation of P.withWriteOnce mem extends only party i's tape by appending one PartyActivationRecord, preserves all other parties' tapes, and satisfies TapePrefix.

      theorem Cslib.Crypto.Protocols.UC.withWriteOnce_handle_inr_tapes_eq {n : ℕ} {In Out NetQ NetR View : Type} (P : AdaptiveProtocol n In Out NetQ NetR View) (mem : PartyMemory) (κ : ℕ) (q : NetQ) (s : WriteOnceState (P.machine κ).State In Out View n) {r : NetR} {s' : WriteOnceState (P.machine κ).State In Out View n} (hs : (r, s') ∈ (Machine.closeEval ((((P.withWriteOnce mem).machine κ).handle (Sum.inr q)).run s)).support) :

      Every .inr q (backdoor / network) activation of P.withWriteOnce mem leaves all per-party write-once tapes unchanged.

      @[simp]
      theorem Cslib.Crypto.Protocols.UC.withWriteOnce_onCorrupt_tapes_eq {n : ℕ} {In Out NetQ NetR View : Type} (P : AdaptiveProtocol n In Out NetQ NetR View) (mem : PartyMemory) (κ : ℕ) (i : Fin n) (s : WriteOnceState (P.machine κ).State In Out View n) :
      ((P.withWriteOnce mem).onCorrupt κ i s).tapes = s.tapes

      Corrupting party i via (P.withWriteOnce mem).onCorrupt leaves all per-party write-once tapes unchanged.

      theorem Cslib.Crypto.Protocols.UC.withWriteOnce_applyInitialCorruptions_eq {n : ℕ} {In Out NetQ NetR View : Type} (P : AdaptiveProtocol n In Out NetQ NetR View) (mem : PartyMemory) (κ : ℕ) (C₀ : Finset (Fin n)) (s : WriteOnceState (P.machine κ).State In Out View n) :
      (P.withWriteOnce mem).applyInitialCorruptions κ C₀ s = { inner := P.applyInitialCorruptions κ C₀ s.inner, tapes := s.tapes }

      Applying initial corruptions C₀ to P.withWriteOnce mem modifies only inner and keeps all per-party write-once tapes unchanged.

      theorem Cslib.Crypto.Protocols.UC.mem_support_closeEval_adaptiveRouter_withWriteOnce_tapePrefix {n : ℕ} {In Out NetQ NetR View : Type} (mode : CorruptionMode) (P : AdaptiveProtocol n In Out NetQ NetR View) (mem : PartyMemory) (κ : ℕ) (C₀ : Finset (Fin n)) {α : Type} (program : ProbOracleComp (adaptiveProtocolSpec n In Out NetQ NetR (WriteOnceView In Out View)) α) (rs : AdaptiveRouterState (WriteOnceState (P.machine κ).State In Out View n) (WriteOnceView In Out View) n) {x : α × AdaptiveRouterState (WriteOnceState (P.machine κ).State In Out View n) (WriteOnceView In Out View) n} (hx : x ∈ (Machine.closeEval ((adaptiveRouter mode (P.withWriteOnce mem) κ C₀).runFrom program rs)).support) :

      Across any execution of adaptiveRouter mode (P.withWriteOnce mem) κ C₀, both the per-party write-once tapes (TapePrefix) and the corrupted party set (⊆) evolve monotonically: old tape records and corruptions can never be erased or overwritten.

      theorem Cslib.Crypto.Protocols.UC.AdaptiveProtocol.PolyBounded.withWriteOnce {n : ℕ} {In Out NetQ NetR View : Type} {P : AdaptiveProtocol n In Out NetQ NetR View} {p : Polynomial ℕ} (mem : PartyMemory) (hP : P.PolyBounded p) :

      Wrapping an AdaptiveProtocol in withWriteOnce preserves its per-activation call budget with zero overhead.

      Projection equivalence and emulation implication #

      def Cslib.Crypto.Protocols.UC.mapNetRAdversary {n : ℕ} {In Out NetQ NetR View₁ View₂ AdvQ AdvR : Type} (f : AdaptiveNetR Out NetR View₁ → AdaptiveNetR Out NetR View₂) (A : AdaptiveAdversary n In Out NetQ NetR View₂ AdvQ AdvR) :
      AdaptiveAdversary n In Out NetQ NetR View₁ AdvQ AdvR

      Adapt an adversary talking to View₂ to talk to View₁ by transforming network replies with f : AdaptiveNetR Out NetR View₁ → AdaptiveNetR Out NetR View₂.

      theorem Cslib.Crypto.Protocols.UC.mapNetRAdversary_comp {n : ℕ} {In Out NetQ NetR View₁ View₂ View₃ AdvQ AdvR : Type} (f : AdaptiveNetR Out NetR View₁ → AdaptiveNetR Out NetR View₂) (g : AdaptiveNetR Out NetR View₂ → AdaptiveNetR Out NetR View₃) (A : AdaptiveAdversary n In Out NetQ NetR View₃ AdvQ AdvR) :

      Composing two network-reply adapters on an adversary equals adapting once by their composition.

      theorem Cslib.Crypto.Protocols.UC.AdaptiveAdversary.PolyBounded.mapNetR {n : ℕ} {In Out NetQ NetR View₁ View₂ AdvQ AdvR : Type} (f : AdaptiveNetR Out NetR View₁ → AdaptiveNetR Out NetR View₂) {A : AdaptiveAdversary n In Out NetQ NetR View₂ AdvQ AdvR} {pA : Polynomial ℕ} (hA : A.PolyBounded pA) :

      Transforming network replies in an adversary preserves its call budget identically.

      Project a CorruptionReport (WriteOnceView In Out View) down to a CorruptionReport View matching target memory mode mem by discarding the write-once tape and either keeping projected snapshot views (mem = .nonErasing) or dropping history (mem = .erasing).

      def Cslib.Crypto.Protocols.UC.projectWriteOnceNetR {In Out NetR View : Type} (mem : PartyMemory) :
      AdaptiveNetR Out NetR (WriteOnceView In Out View) → AdaptiveNetR Out NetR View

      Project AdaptiveNetR answers from WriteOnceView In Out View down to View under target memory mode mem.

      def Cslib.Crypto.Protocols.UC.projectWriteOnceProgram {n : ℕ} {In Out NetQ NetR View : Type} (mem : PartyMemory) {α : Type} (program : ProbOracleComp (adaptiveProtocolSpec n In Out NetQ NetR View) α) :
      ProbOracleComp (adaptiveProtocolSpec n In Out NetQ NetR (WriteOnceView In Out View)) α

      Adapt a program over adaptiveProtocolSpec ... View to talk to adaptiveRouter for P.withWriteOnce, forwarding .inl party/status queries directly and projecting .inr network replies via projectWriteOnceNetR mem.

      Drop .tape and router .history from a CorruptionReport (WriteOnceView In Out View) to recover the .erasing report of P.withWriteOnce .erasing.

      def Cslib.Crypto.Protocols.UC.dropWriteOnceTapeNetR {In Out NetR View : Type} :
      AdaptiveNetR Out NetR (WriteOnceView In Out View) → AdaptiveNetR Out NetR (WriteOnceView In Out View)

      Drop .tape and .history from AdaptiveNetR answers under WriteOnceView.

      Lift a CorruptionReport View into CorruptionReport (WriteOnceView In Out View) for .erasing memory mode (tape := none, history := none).

      def Cslib.Crypto.Protocols.UC.liftWriteOnceErasingNetR {In Out NetR View : Type} :
      AdaptiveNetR Out NetR View → AdaptiveNetR Out NetR (WriteOnceView In Out View)

      Lift AdaptiveNetR answers from View into WriteOnceView In Out View for .erasing memory mode.

      structure Cslib.Crypto.Protocols.UC.WriteOnceRouterRel {n : ℕ} {In Out NetQ NetR View : Type} (P : AdaptiveProtocol n In Out NetQ NetR View) (κ : ℕ) (rs₁ : AdaptiveRouterState (WriteOnceState (P.machine κ).State In Out View n) (WriteOnceView In Out View) n) (rs₂ : AdaptiveRouterState (P.machine κ).State View n) :

      State relation between the router states of P.withWriteOnce mem and P: matching inner protocol states, matching corrupted sets, and P.withWriteOnce's snapshot traces projecting entrywise via .current to P's snapshot traces.

      theorem Cslib.Crypto.Protocols.UC.runFrom_adaptiveRouter_withWriteOnce_noCorrupt {n : ℕ} {In Out NetQ NetR View α β : Type} (mode : CorruptionMode) (P : AdaptiveProtocol n In Out NetQ NetR View) (mem : PartyMemory) (κ : ℕ) (C₀ : Finset (Fin n)) (program : ProbOracleComp (adaptiveProtocolSpec n In Out NetQ NetR View) α) (hno : OracleComp.QueriesSatisfy (Sum.elim (fun (x : ℕ) => True) fun (q : AdaptivePartyQ n In ⊕ AdaptiveNetQ n In NetQ) => ∀ (i : Fin n), q ≠ Sum.inr (AdaptiveNetQ.corrupt i)) program) (rs₁ : AdaptiveRouterState (WriteOnceState (P.machine κ).State In Out View n) (WriteOnceView In Out View) n) (rs₂ : AdaptiveRouterState (P.machine κ).State View n) (hR : WriteOnceRouterRel P κ rs₁ rs₂) (f : α × AdaptiveRouterState (WriteOnceState (P.machine κ).State In Out View n) (WriteOnceView In Out View) n → ProbOracleComp OracleSpec.empty β) (g : α × AdaptiveRouterState (P.machine κ).State View n → ProbOracleComp OracleSpec.empty β) (hfg : ∀ (a : α) (rs₁' : AdaptiveRouterState (WriteOnceState (P.machine κ).State In Out View n) (WriteOnceView In Out View) n) (rs₂' : AdaptiveRouterState (P.machine κ).State View n), WriteOnceRouterRel P κ rs₁' rs₂' → f (a, rs₁') = g (a, rs₂')) :
      (adaptiveRouter mode (P.withWriteOnce mem) κ C₀).runFrom (projectWriteOnceProgram P.memory program) rs₁ >>= f = (adaptiveRouter mode P κ C₀).runFrom program rs₂ >>= g

      Honest-phase / uncorrupted execution transparency: for any program over adaptiveProtocolSpec containing no .corrupt queries (in particular, all honest-party .inl and .net queries), running against adaptiveRouter mode (P.withWriteOnce mem) κ C₀ from related states produces the identical ProbOracleComp result and related state as running directly against adaptiveRouter mode P κ C₀.

      theorem Cslib.Crypto.Protocols.UC.adaptiveExec_withWriteOnce_project {n : ℕ} {In Out NetQ NetR View AdvQ AdvR : Type} (mode : CorruptionMode) (P : AdaptiveProtocol n In Out NetQ NetR View) (mem : PartyMemory) (hmem : P.memory = PartyMemory.nonErasing → mem = PartyMemory.nonErasing) (A : AdaptiveAdversary n In Out NetQ NetR View AdvQ AdvR) (Z : AdaptiveEnvironment n In Out AdvQ AdvR) (κ : ℕ) (z : List Bool) :

      Projecting .corrupt reports from P.withWriteOnce mem back to P preserves the exact ProbComp Bool execution distribution for every environment, adversary, and corruption mode, provided mem retains router history whenever P.memory = .nonErasing.

      theorem Cslib.Crypto.Protocols.UC.adaptiveExec_withWriteOnce_erasing {n : ℕ} {In Out NetQ NetR View AdvQ AdvR : Type} (mode : CorruptionMode) (P : AdaptiveProtocol n In Out NetQ NetR View) (A : AdaptiveAdversary n In Out NetQ NetR (WriteOnceView In Out View) AdvQ AdvR) (Z : AdaptiveEnvironment n In Out AdvQ AdvR) (κ : ℕ) (z : List Bool) :

      Dropping .tape and .history in .nonErasing withWriteOnce execution yields the exact ProbComp Bool execution of P.withWriteOnce .erasing.

      theorem Cslib.Crypto.Protocols.UC.adaptiveExec_withWriteOnce_erasing_eq {n : ℕ} {In Out NetQ NetR View AdvQ AdvR : Type} (mode : CorruptionMode) (P : AdaptiveProtocol n In Out NetQ NetR View) (hP : P.memory = PartyMemory.erasing) (A : AdaptiveAdversary n In Out NetQ NetR (WriteOnceView In Out View) AdvQ AdvR) (Z : AdaptiveEnvironment n In Out AdvQ AdvR) (κ : ℕ) (z : List Bool) :

      For any .erasing protocol P, running P.withWriteOnce .erasing against A produces the exact same ProbComp Bool execution as running P against mapNetRAdversary liftWriteOnceErasingNetR A.

      theorem Cslib.Crypto.Protocols.UC.AdaptiveEmulatesWithin.of_writeOnce {n : ℕ} {In Out NetQ NetR View View₂ NetQ₂ NetR₂ : Type} {mode : CorruptionMode} {P : AdaptiveProtocol n In Out NetQ NetR View} {Q : AdaptiveProtocol n In Out NetQ₂ NetR₂ View₂} {g : Polynomial ℕ} {ε : Polynomial ℕ → Polynomial ℕ → ℕ → NNReal} (h : AdaptiveEmulatesWithin mode (P.withWriteOnce PartyMemory.nonErasing) Q g ε) :

      Concrete adaptive emulation in the coin-exposing .nonErasing write-once wrapper implies concrete adaptive emulation of the underlying protocol P (including when P.memory = .erasing) with identical simulator budget and error.

      theorem Cslib.Crypto.Protocols.UC.AdaptiveEmulates.of_writeOnce {n : ℕ} {In Out NetQ NetR View View₂ NetQ₂ NetR₂ : Type} {mode : CorruptionMode} {P : AdaptiveProtocol n In Out NetQ NetR View} {Q : AdaptiveProtocol n In Out NetQ₂ NetR₂ View₂} (h : AdaptiveEmulates mode (P.withWriteOnce PartyMemory.nonErasing) Q) :

      Asymptotic adaptive emulation in the coin-exposing .nonErasing write-once wrapper implies asymptotic adaptive emulation of P (valid in particular when P.memory = .erasing).

      theorem Cslib.Crypto.Protocols.UC.AdaptiveEmulatesWithin.erasing_of_writeOnce {n : ℕ} {In Out NetQ NetR View View₂ NetQ₂ NetR₂ : Type} {mode : CorruptionMode} {P : AdaptiveProtocol n In Out NetQ NetR View} {Q : AdaptiveProtocol n In Out NetQ₂ NetR₂ View₂} {g : Polynomial ℕ} {ε : Polynomial ℕ → Polynomial ℕ → ℕ → NNReal} (h : AdaptiveEmulatesWithin mode (P.withWriteOnce PartyMemory.nonErasing) Q g ε) :

      Concrete adaptive emulation for P.withWriteOnce .nonErasing implies concrete adaptive emulation for P.withWriteOnce .erasing with identical simulator budget and error.

      theorem Cslib.Crypto.Protocols.UC.AdaptiveEmulates.erasing_of_writeOnce {n : ℕ} {In Out NetQ NetR View View₂ NetQ₂ NetR₂ : Type} {mode : CorruptionMode} {P : AdaptiveProtocol n In Out NetQ NetR View} {Q : AdaptiveProtocol n In Out NetQ₂ NetR₂ View₂} (h : AdaptiveEmulates mode (P.withWriteOnce PartyMemory.nonErasing) Q) :

      Asymptotic adaptive emulation for P.withWriteOnce .nonErasing implies asymptotic adaptive emulation for P.withWriteOnce .erasing.

      theorem Cslib.Crypto.Protocols.UC.AdaptiveEmulatesWithin.withWriteOnce_erasing_iff {n : ℕ} {In Out NetQ NetR View View₂ NetQ₂ NetR₂ : Type} {mode : CorruptionMode} {P : AdaptiveProtocol n In Out NetQ NetR View} {Q : AdaptiveProtocol n In Out NetQ₂ NetR₂ View₂} {g : Polynomial ℕ} {ε : Polynomial ℕ → Polynomial ℕ → ℕ → NNReal} (hP : P.memory = PartyMemory.erasing) :

      For any .erasing protocol P, concrete adaptive emulation of P.withWriteOnce .erasing is equivalent to concrete adaptive emulation of P with identical simulator budget and error.

      theorem Cslib.Crypto.Protocols.UC.AdaptiveEmulates.withWriteOnce_erasing_iff {n : ℕ} {In Out NetQ NetR View View₂ NetQ₂ NetR₂ : Type} {mode : CorruptionMode} {P : AdaptiveProtocol n In Out NetQ NetR View} {Q : AdaptiveProtocol n In Out NetQ₂ NetR₂ View₂} (hP : P.memory = PartyMemory.erasing) :

      For any .erasing protocol P, asymptotic adaptive emulation of P.withWriteOnce .erasing is equivalent to asymptotic adaptive emulation of P.