Skip to content

Commit d348ca9

Browse files
refactor(OracleReduction): generalise the lift helper; drop dead code and linter warnings
Addresses review findings on the identity-soundness / log-discard proofs. No statement changes; both theorems remain axiom-clean. 1. Generalise the private helper and use core lemmas properly. `OptionT_liftM_bind_fst` was hard-coded to `OptionT m` at `Type 0`, and proved by unfolding `liftM` / `MonadLift.monadLift` / `OptionT.lift` / `OptionT.mk` through a goal-changing `show` plus `congr 1` -- of whose six `simp` arguments five were unused. It is in fact the `monadLift`-generic form of `bind_map_left`, so restate it for any `[MonadLiftT m n] [LawfulMonadLiftT m n]` over arbitrary universes as `monadLift_bind_fst`, proved by `rw [monadLift_map, bind_map_left]` (both Lean core). Shorter, strictly more general, and it no longer depends on how `OptionT`'s lift happens to be implemented. 2. Dead code, in the region these changes own. - Removed the ~20-line commented-out `calc` attempt below the now-proved theorem; the docstring that referred to it ("a partial `calc` attempt is retained in comments") is already gone. - Removed `private lemma Monad.map_of_prod_fst_eq_prod_fst`, which nothing references. 3. Linter warnings. The above removes all 8 that `lake build` reported inside the new code (1 × `linter.style.show`, 7 × `linter.unusedSimpArgs`). The warnings remaining in `Execution.lean` are pre-existing. 4. Comments. Replaced the "Remaining: ..." / "should equal" note in front of the closing `rfl`, which read as unfinished work, with a statement of what the `rfl` discharges; and recorded why the verifier-logging step needs an explicit induction rather than reusing VCV-io's `loggingOracle.fst_map_run_simulateQ` or ArkLib's `loggingOracle.map_fst_run_simulateQ` (the verifier's run sits under `liftM` inside `OptionT`, so its log is consumed by an `OptionT` bind rather than a `Prod.fst` map -- six drop-in variants of those lemmas were tried and none applies). Named the three anonymous shadowing `have`s at the end of `Verifier.id_soundness`. Correction to the previous commit message: it says all three declarations that depend on `Verifier.id_soundness` reach it by implicit `simp` firing and are invisible to a text search. Only `OracleVerifier.id_soundness` does. `Verifier.seqCompose_soundness` names it outright (`Composition/Sequential/General.lean`, `exact Verifier.id_soundness init impl`) and `OracleVerifier.seqCompose_soundness` reaches it through that. The substantive claim is unaffected: a library-wide `Lean.collectAxioms` sweep confirms exactly three declarations move from `sorryAx`-tainted to clean -- `Verifier.id_soundness`, `OracleVerifier.id_soundness` (the one silent dependent) and `Reduction.runWithLog_discard_logs_eq_run`. Verified: `lake build` green (4135 jobs, 0 errors); `#print axioms` reports [propext, Classical.choice, Quot.sound] for both theorems and for `OracleVerifier.id_soundness`; no style-lint error and no build-linter warning inside the changed ranges. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 0a6d73a commit d348ca9

2 files changed

Lines changed: 31 additions & 47 deletions

File tree

ArkLib/OracleReduction/Execution.lean

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ArkLib.ToVCVio.OracleComp.EvalDist
1111

1212
open OracleComp OracleSpec SubSpec ProtocolSpec
1313

14-
universe u v
14+
universe u v v'
1515

1616
-- namespace loggingOracle
1717

@@ -404,23 +404,17 @@ def Reduction.runWithLog (stmt : StmtIn) (wit : WitIn)
404404
liftM (simulateQ loggingOracle (reduction.verifier.run stmt proverResult.1)).run
405405
return ⟨⟨proverResult, ← stmtOut.getM⟩, proveQueryLog, verifyQueryLog⟩
406406

407-
/-- TODO: figure out a better name for this -/
408-
private lemma Monad.map_of_prod_fst_eq_prod_fst {m : Type u → Type v} [Monad m] [LawfulMonad m]
409-
{α β γ : Type u} (ma : m (α × β)) (c : γ) :
410-
(fun a => (c, a.1)) <$> ma = Prod.mk c <$> Prod.fst <$> ma := by
411-
simp only [Functor.map_map]
412-
413-
/-- In OptionT, lifting a pair-valued computation and projecting the first component
414-
in the continuation equals lifting the map and binding directly. -/
415-
private lemma OptionT_liftM_bind_fst {m : TypeType} [Monad m] [LawfulMonad m]
416-
{α β γ : Type} (x : m (α × β)) (f : α → OptionT m γ) :
417-
((liftM x : OptionT m _) >>= fun p => f p.1) =
418-
(liftM (Prod.fst <$> x) : OptionT m _) >>= f := by
419-
rw [← bind_map_left]
420-
show (Prod.fst <$> monadLift x) >>= f = monadLift (Prod.fst <$> x) >>= f
421-
congr 1
422-
simp [liftM, MonadLift.monadLift, OptionT.lift, OptionT.mk,
423-
Functor.map_map, Function.comp]
407+
/-- Lifting a pair-valued computation and then projecting its first component in the continuation
408+
is the same as lifting the already-projected computation.
409+
410+
This is the `monadLift`-generic form of `bind_map_left`, obtained from it and `monadLift_map`
411+
(both Lean core). Instantiated below at `OracleComp _ → OptionT (OracleComp _)` to strip the
412+
prover's query log before the verifier runs. -/
413+
private lemma monadLift_bind_fst {m : Type u → Type v} {n : Type u → Type v'}
414+
[Monad m] [LawfulMonad m] [Monad n] [LawfulMonad n]
415+
[MonadLiftT m n] [LawfulMonadLiftT m n] {α β γ : Type u} (x : m (α × β)) (f : α → n γ) :
416+
((monadLift x : n (α × β)) >>= fun p => f p.1) = (monadLift (Prod.fst <$> x) : n α) >>= f := by
417+
rw [monadLift_map, bind_map_left]
424418

425419
/-- Logging the queries made by both parties do not change the output of the reduction -/
426420
@[simp]
@@ -429,44 +423,32 @@ theorem Reduction.runWithLog_discard_logs_eq_run
429423
{reduction : Reduction oSpec StmtIn WitIn StmtOut WitOut pSpec} :
430424
Prod.fst <$>
431425
reduction.runWithLog stmt wit = reduction.run stmt wit := by
432-
simp only [Reduction.runWithLog, Reduction.run, map_bind, map_pure, Functor.map_map,
433-
Function.comp]
434-
have h1 := OptionT_liftM_bind_fst (m := OracleComp (oSpec + [pSpec.Challenge]ₒ))
426+
simp only [Reduction.runWithLog, Reduction.run, map_bind, map_pure]
427+
-- Discard the prover's log: pull the `Prod.fst` projection inside the lift, so that
428+
-- `Prover.runWithLog_discard_log_eq_run` applies to the lifted computation.
429+
have hProver := monadLift_bind_fst (m := OracleComp (oSpec + [pSpec.Challenge]ₒ))
430+
(n := OptionT (OracleComp (oSpec + [pSpec.Challenge]ₒ)))
435431
(Prover.runWithLog stmt wit reduction.prover)
436432
(fun proverResult =>
437433
liftM (simulateQ loggingOracle (Verifier.run stmt proverResult.1 reduction.verifier)).run
438434
>>= fun a_1 => (fun a_2 => (proverResult, a_2)) <$> a_1.1.getM)
439-
-- Prover logging elimination: use OptionT_liftM_bind_fst + Prover.runWithLog_discard_log_eq_run
440-
exact h1 ▸ by
435+
exact hProver ▸ by
441436
rw [Prover.runWithLog_discard_log_eq_run]
442437
congr 1; ext proverResult
443-
-- Verifier logging elimination by induction on the verifier computation
438+
-- Discard the verifier's log. VCV-io's `loggingOracle.fst_map_run_simulateQ` and ArkLib's
439+
-- `loggingOracle.map_fst_run_simulateQ` (`ToVCVio/OracleComp/QueryTracking/LoggingOracle.lean`)
440+
-- are this fact for a bare `OracleComp`, but neither matches here: the verifier's run sits
441+
-- under `liftM` inside `OptionT`, so its log is consumed by an `OptionT` bind rather than by a
442+
-- `Prod.fst` map. Hence the explicit induction.
444443
generalize Verifier.run stmt proverResult.1 reduction.verifier = vc
445444
induction vc using OracleComp.induction with
446445
| pure a => simp [simulateQ_pure, WriterT.run_pure]; rfl
447446
| query_bind t oa ih =>
448447
simp only [run_simulateQ_loggingOracle_query_bind]
449448
simp [bind_map_left, ih, OptionT.run_bind, Option.elimM, bind_assoc, OptionT.run_map]
450-
-- Remaining: OptionT.run distributing through liftM + bind on RHS
451-
-- The RHS has OptionT.run (liftM (query t) >>= oa) which should equal
452-
-- query t >>= fun u => OptionT.run (oa u). This is monadLift_bind for OptionT SubSpec.
449+
-- Closes `OptionT.run (liftM (query t) >>= oa) = query t >>= fun u => OptionT.run (oa u)`,
450+
-- which holds definitionally for the `OptionT` lift of a sub-spec query.
453451
rfl
454-
-- calc
455-
-- _ = (do
456-
-- let a ← (simulateQ loggingOracle proverRun).run
457-
-- (fun aFst : (pSpec.FullTranscript × StmtOut × WitOut) => (fun b => (aFst, Prod.fst b)) <$>
458-
-- (simulateQ loggingOracle (Verifier.run stmt aFst.1 reduction.verifier)).run.liftComp
459-
-- (oSpec + [pSpec.Challenge]ₒ)) a.1) := rfl
460-
-- _ = _ := by
461-
-- rw [loggingOracle.simulateQ_bind_fst_comp proverRun
462-
-- (fun a => (fun b => (a, Prod.fst b)) <$>
463-
-- (simulateQ loggingOracle (Verifier.run stmt a.1 reduction.verifier)).run.liftComp
464-
-- (oSpec + [pSpec.Challenge]ₒ))]
465-
-- congr
466-
-- ext proverResult
467-
-- rw [← Functor.map_map]
468-
-- simp
469-
470452

471453
/-- Run an interactive oracle reduction. Returns the full transcript, the output statement and
472454
witness, the log of all prover's oracle queries, and the log of all verifier's oracle queries to

ArkLib/OracleReduction/Security/Basic.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,12 @@ theorem Verifier.id_soundness {lang : Set StmtIn} :
572572
rw [hliftM, simulateQ_map, StateT.run_map] at ha
573573
simp only [support_map, Set.mem_image, Prod.exists] at ha
574574
obtain ⟨pr, s'', ⟨b, _, _, heq⟩⟩ := ha
575-
have := (Prod.mk.inj heq).1
576-
have := Option.some.inj this
577-
have := (Prod.mk.inj this).2
578-
rw [← this] at hev
575+
-- `heq` identifies the sampled output with `(some (pr, stmtIn), _)`; peel it apart to read off
576+
-- that the output statement is literally `stmtIn`, contradicting `stmtIn ∉ lang` via `hev`.
577+
have hOption := (Prod.mk.inj heq).1
578+
have hPair := Option.some.inj hOption
579+
have hStmtOut := (Prod.mk.inj hPair).2
580+
rw [← hStmtOut] at hev
579581
exact hev
580582

581583
/-- The straightline extractor for the identity / trivial reduction, which just returns the input

0 commit comments

Comments
 (0)