Documentation

CslibFrontier.Languages.Probabilistic.UntilBad.PlantedQuery

Adaptive planted-query union bounds for ProbOracleComp #

In a multi-query reduction (such as chosen-ciphertext decryption-rejection hops or adaptive search-to-decision reductions), an adversary interacts with an oracle that latches a bad event on the first target query satisfying isBad q s, while a reduction guesses the zero-based target-query index j < Q uniformly, simulates the < j target queries faithfully with sim, captures extract q on target query j, and answers query j and all subsequent queries with dummyReply without further state changes.

plantedHandler packages that countdown-and-capture state machine over the named composite record PlantedOracleState Cand State, using StateLens.zoom on passive (isTarget q = false) calls. toOuterMeasure_bad_le_sum_planted_of_cost proves the adaptive union bound once by induction on the structural target-query budget IsCostBounded: the probability of reaching bad from embed s is at most the sum over j ∈ Finset.range Q of the probability that the j-th planted execution captures a winning candidate (hasCaptured ∧ win candidate oracleState). toOuterMeasure_bad_le_sum_planted specializes isTarget to fun _ => true for total external query budgets ProbOracleComp.IsQueryBounded program Q.

Main definitions #

Main results #

structure Cslib.ProbOracleComp.PlantedState (Cand : Type u_1) :
Type u_1

Countdown and capture state for a planted-query reduction: skips rem target queries, captures a Cand value on the next target query (hasCaptured = true), and freezes thereafter.

  • rem : ℕ

    Number of target queries still to skip before capturing.

  • hasCaptured : Bool

    Whether the target query at the planted index has already been captured.

  • candidate : Cand

    Captured candidate value (initialized to a default value while hasCaptured = false).

Instances For
    def Cslib.ProbOracleComp.instDecidableEqPlantedState.decEq {Cand✝ : Type u_1} [DecidableEq Cand✝] (x✝ x✝¹ : PlantedState Cand✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    @[instance_reducible]
    instance Cslib.ProbOracleComp.instReprPlantedState {Cand✝ : Type u_1} [Repr Cand✝] :
    Repr (PlantedState Cand✝)
    def Cslib.ProbOracleComp.PlantedState.init {Cand : Type u_1} (j : ℕ) (defaultCand : Cand) :

    Initial PlantedState targeting zero-based query index j with fallback defaultCand.

    structure Cslib.ProbOracleComp.PlantedOracleState (Cand : Type u_1) (State : Type u_2) :
    Type (max u_1 u_2)

    Composite state pairing a PlantedState Cand countdown with an underlying oracle state State.

    • planted : PlantedState Cand

      Countdown and capture state of the planted-query reduction.

    • oracleState : State

      Underlying state of the simulated external oracle.

    Instances For
      @[instance_reducible]
      instance Cslib.ProbOracleComp.instDecidableEqPlantedOracleState {Cand✝ : Type u_1} {State✝ : Type u_2} [DecidableEq Cand✝] [DecidableEq State✝] :
      DecidableEq (PlantedOracleState Cand✝ State✝)
      def Cslib.ProbOracleComp.instDecidableEqPlantedOracleState.decEq {Cand✝ : Type u_1} {State✝ : Type u_2} [DecidableEq Cand✝] [DecidableEq State✝] (x✝ x✝¹ : PlantedOracleState Cand✝ State✝) :
      Decidable (x✝ = x✝¹)
      @[instance_reducible]
      instance Cslib.ProbOracleComp.instReprPlantedOracleState {Cand✝ : Type u_1} {State✝ : Type u_2} [Repr Cand✝] [Repr State✝] :
      Repr (PlantedOracleState Cand✝ State✝)
      def Cslib.ProbOracleComp.instReprPlantedOracleState.repr {Cand✝ : Type u_1} {State✝ : Type u_2} [Repr Cand✝] [Repr State✝] :
      PlantedOracleState Cand✝ State✝ → ℕ → Std.Format
      def Cslib.ProbOracleComp.PlantedOracleState.init {Cand : Type u_1} {State : Type u_2} (j : ℕ) (defaultCand : Cand) (s : State) :

      Initial PlantedOracleState at target index j, fallback defaultCand, and oracle state s.

      Lawful lens focusing on the planted field of PlantedOracleState.

      Lawful lens focusing on the oracleState field of PlantedOracleState.

      noncomputable def Cslib.ProbOracleComp.plantedHandler {Query Cand State : Type} {spec : Query → Type} (sim : (q : Query) → StateT State PMF (spec q)) (isTarget : Query → Bool) (extract : Query → Cand) (defaultCand : Cand) (dummyReply : (q : Query) → spec q) (q : Query) :
      StateT (PlantedOracleState Cand State) PMF (spec q)

      Adaptive planted-query countdown handler on PlantedOracleState Cand State:

      • once st.planted.hasCaptured = true, every query returns dummyReply q and leaves st frozen;
      • while st.planted.hasCaptured = false:
        • on a target query (isTarget q = true), captures extract q with dummyReply q and freezes st.oracleState if st.planted.rem == 0, and otherwise steps sim q while decrementing st.planted.rem;
        • on a non-target query (isTarget q = false), steps sim q zoomed onto oracleState while leaving the countdown untouched.
      theorem Cslib.ProbOracleComp.runWith_plantedHandler_captured_bind_eq_one {Query Cand State α : Type} {spec : Query → Type} (sim : (q : Query) → StateT State PMF (spec q)) (isTarget : Query → Bool) (extract : Query → Cand) (defaultCand : Cand) (dummyReply : (q : Query) → spec q) (test : PlantedOracleState Cand State → Bool) (program : ProbOracleComp spec α) {st : PlantedOracleState Cand State} (hcap : st.planted.hasCaptured = true) (htest : test st = true) :
      ((runWith (plantedHandler sim isTarget extract defaultCand dummyReply) program st).bind fun (x : α × PlantedOracleState Cand State) => PMF.pure (test x.2)) true = 1

      Once st.planted.hasCaptured = true, plantedHandler freezes the entire PlantedOracleState across any subsequent ProbOracleComp execution, so any boolean state predicate test holding at st holds at termination with probability 1.

      theorem Cslib.ProbOracleComp.toOuterMeasure_bad_le_sum_planted_of_cost {Query Cand State BadS α : Type} {spec : Query → Type} {badHandler : (q : Query) → StateT BadS PMF (spec q)} {bad : BadS → Prop} (embed : State → BadS) (hembed : ∀ (s : State), ¬bad (embed s)) (sim : (q : Query) → StateT State PMF (spec q)) (isTarget : Query → Bool) (isBad : Query → State → Bool) (extract : Query → Cand) (defaultCand : Cand) (dummyReply : (q : Query) → spec q) (win : Cand → State → Bool) (hgood : ∀ (q : Query) (s : State), (isTarget q && isBad q s) = false → badHandler q (embed s) = PMF.map (fun (x : spec q × State) => (x.1, embed x.2)) (sim q s)) (hwin : ∀ (q : Query) (s : State), isTarget q = true → isBad q s = true → win (extract q) s = true) {program : ProbOracleComp spec α} {Q : ℕ} (hq : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) fun (q : Query) => if isTarget q = true then 1 else 0) program Q) (s : State) :
      (runWith badHandler program (embed s)).toOuterMeasure {x : α × BadS | bad x.2} ≤ ∑ j ∈ Finset.range Q, ((runWith (plantedHandler sim isTarget extract defaultCand dummyReply) program (PlantedOracleState.init j defaultCand s)).bind fun (x : α × PlantedOracleState Cand State) => PMF.pure (x.2.planted.hasCaptured && win x.2.planted.candidate x.2.oracleState)) true

      Cost-filtered adaptive planted-query union bound. Suppose program : ProbOracleComp spec α makes at most Q target queries (isTarget q = true), badHandler agrees with sim along embed : State → BadS whenever (isTarget q && isBad q s) = false, and every bad target query yields a winning extracted candidate (win (extract q) s = true). Then the probability that runWith badHandler program (embed s) ends in bad is bounded by the sum over j ∈ Finset.range Q of the probability that plantedHandler started at PlantedOracleState.init j defaultCand s captures a winning candidate.

      theorem Cslib.ProbOracleComp.toOuterMeasure_bad_le_sum_planted {Query Cand State BadS α : Type} {spec : Query → Type} {badHandler : (q : Query) → StateT BadS PMF (spec q)} {bad : BadS → Prop} (embed : State → BadS) (hembed : ∀ (s : State), ¬bad (embed s)) (sim : (q : Query) → StateT State PMF (spec q)) (isBad : Query → State → Bool) (extract : Query → Cand) (defaultCand : Cand) (dummyReply : (q : Query) → spec q) (win : Cand → State → Bool) (hgood : ∀ (q : Query) (s : State), isBad q s = false → badHandler q (embed s) = PMF.map (fun (x : spec q × State) => (x.1, embed x.2)) (sim q s)) (hwin : ∀ (q : Query) (s : State), isBad q s = true → win (extract q) s = true) {program : ProbOracleComp spec α} {Q : ℕ} (hq : program.IsQueryBounded Q) (s : State) :
      (runWith badHandler program (embed s)).toOuterMeasure {x : α × BadS | bad x.2} ≤ ∑ j ∈ Finset.range Q, ((runWith (plantedHandler sim (fun (x : Query) => true) extract defaultCand dummyReply) program (PlantedOracleState.init j defaultCand s)).bind fun (x : α × PlantedOracleState Cand State) => PMF.pure (x.2.planted.hasCaptured && win x.2.planted.candidate x.2.oracleState)) true

      Adaptive Q-query planted-index union bound (IsQueryBounded). When program makes at most Q external queries (program.IsQueryBounded Q), badHandler agrees with sim along embed whenever isBad q s = false, and every bad query yields win (extract q) s = true, the probability of reaching bad from embed s is at most the sum over j ∈ Finset.range Q of the probability that the j-th planted execution captures a winning candidate.

      theorem Cslib.ProbOracleComp.toOuterMeasure_bad_le_sum_planted_candidate_of_cost {Query Cand State BadS α : Type} {spec : Query → Type} {badHandler : (q : Query) → StateT BadS PMF (spec q)} {bad : BadS → Prop} (embed : State → BadS) (hembed : ∀ (s : State), ¬bad (embed s)) (sim : (q : Query) → StateT State PMF (spec q)) (isTarget : Query → Bool) (isBad : Query → State → Bool) (extract : Query → Cand) (defaultCand : Cand) (dummyReply : (q : Query) → spec q) (win : Cand → State → Bool) (hgood : ∀ (q : Query) (s : State), (isTarget q && isBad q s) = false → badHandler q (embed s) = PMF.map (fun (x : spec q × State) => (x.1, embed x.2)) (sim q s)) (hwin : ∀ (q : Query) (s : State), isTarget q = true → isBad q s = true → win (extract q) s = true) {program : ProbOracleComp spec α} {Q : ℕ} (hq : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) fun (q : Query) => if isTarget q = true then 1 else 0) program Q) (s : State) :
      (runWith badHandler program (embed s)).toOuterMeasure {x : α × BadS | bad x.2} ≤ ∑ j ∈ Finset.range Q, ((runWith (plantedHandler sim isTarget extract defaultCand dummyReply) program (PlantedOracleState.init j defaultCand s)).bind fun (x : α × PlantedOracleState Cand State) => PMF.pure (win x.2.planted.candidate x.2.oracleState)) true

      Variant of toOuterMeasure_bad_le_sum_planted_of_cost for reductions that output x.2.planted.candidate unconditionally (returning defaultCand when fewer than j + 1 target queries occur), dropping hasCaptured && in the winning event.