Skip to content

feat(OracleComp): logs of fixed-answer runs, handler query bounds and unqueried cache entries - #1207

Open
dtumad wants to merge 1 commit into
Verified-zkEVM:mainfrom
dtumad:dtumad/querytracking-runlog
Open

dtumad wants to merge 1 commit into
Verified-zkEVM:mainfrom
dtumad:dtumad/querytracking-runlog

Conversation

@dtumad

@dtumad dtumad commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Adds the run-and-log API for programs answered by a fixed answer function, with the query-bound,
cache and probability lemmas that reason about such runs.

Runs with fixed answers (VCVio/OracleComp/QueryTracking/RunLog.lean, new). runLog ans oa
lists the queries of evalWithAnswerFn ans oa, oldest first, with their answers:

  • evalWithAnswerFn_withQueryLog: answering oa.withQueryLog with ans gives the run and its
    log;
  • runLog_pure, runLog_bind, runLog_query, runLog_query_bind, runLog_map,
    runLog_withQueryLog, runLog_simulateQ, mem_runLog_simulateQ;
  • answer functions that agree at every logged query give the same run and the same log
    (evalWithAnswerFn_eq_of_forall_mem_runLog, runLog_eq_of_forall_mem_runLog), and a run only
    makes queries the program may make (forall_mem_runLog_of_allQueriesSatisfy,
    runLog_eq_of_allQueriesSatisfy);
  • length_filterMap_runLog_le: a program making at most n queries satisfying p logs at most
    n of them.

tableQueryLog (RandomOracle/FreshQuery.lean) is now runLog against the table; its lemmas
keep their names and statements and are one-line consequences of the general ones.

Handlers and query bounds.

  • IsQueryBoundP.simulateQ_of_step_le (QueryBound/Simulation.lean): a handler using at most
    cost queries satisfying q per query satisfying p, and none otherwise, turns a bound n
    into n * cost. It is the stateless form of IsQueryBoundP.simulateQ_run_of_step_le;
    IsQueryBoundP.simulateQ_of_step (cost = 1) and IsQueryBoundP.simulateQ_of_step_le_total
    (p always true) are now derived from it.
  • AllQueriesSatisfy.map_run_simulateQ_eq_of_query_map_eq: the state-projection law
    map_run_simulateQ_eq_of_query_map_eq, needing the step law only at the queries the program may
    make.
  • QueryBound/Basic.lean: isQueryBoundP_bind_le, allQueriesSatisfy_map_iff and
    evalWithAnswerFn_eq_of_allQueriesSatisfy. IsTotalQueryBound.isQueryBoundP and
    isQueryBoundP_true_iff move here from QueryBound/Simulation.lean, unchanged, so that the
    derivation above can use them.
  • LoggingOracle/Core.lean: isQueryBoundP_withQueryLog_iff and
    allQueriesSatisfy_withQueryLog_iff, beside isTotalQueryBound_withQueryLog_iff.
  • simulateQ_pure_eq_evalWithAnswerFn (SimSemantics/SimulateQ.lean): answering every query
    with pure (f t) in a lawful monad is pure (evalWithAnswerFn f oa). It replaces the
    X →ₒ Y case in VectorCommitment, whose one caller now uses it.

Unqueried cache entries. A program whose queries all satisfy P returns the same results from
two caches that agree on P, as an equality of programs: for any cached handler
(QueryImpl.fst_map_run_simulateQ_withCaching_eq_of_allQueriesSatisfy, through the step lemma
QueryImpl.map_withCaching_run_ofFn_ite) and in the random oracle model
(OracleSpec.fst_map_run_simulateQ_romImpl_eq_of_allQueriesSatisfy).

Probability (EvalDist/ProbabilityBounds.lean, for any lawful measure semantics):
prEvent_le_prEvent_add_prEvent_of_imp, absDiff_prEvent_le_absDiff_prEvent_and_not_add,
prEvent_exists_list_le (the list form of prEvent_exists_finset_le), and the simp lemma
prEvent_bind_bind_false.

docs/agents/query-tracking.md describes the run-log API and the cache lemmas.

Tests. VCVioTest/OracleComp/QueryTracking/RunLog.lean computes logs of concrete programs
and checks each bound against a case that attains it or needs its hypothesis: answers differing at
a queried point change the run; the log shows that a program and a simulation through a doubling
handler exceed the next smaller query bound; a sure event is not bounded by two null ones; the
absDiff bound is attained; and a run that reads the differing cache entry, in a cached handler
and in the random oracle model, returns different results.

Validation. ./scripts/validate.sh --lint --test --axioms passes at 71c4042d9: the six proof
libraries build with no warnings, the umbrella, boundary, style, documentation and environment-lint
checks pass with the lint baseline unchanged, lake test passes, and the axiom sweep reports zero
debt. The native FFI tests (--ffi) were not run.

… unqueried cache entries

`OracleComp.runLog ans oa` is the query log of the run of `oa` answered by the fixed answer
function `ans`, with its bind, query, map, simulation and agreement laws, in the new
`QueryTracking/RunLog.lean`. `tableQueryLog` is `runLog` against its table.

`IsQueryBoundP.simulateQ_of_step_le` multiplies a predicate-targeted bound by the per-query cost
of a handler; `IsQueryBoundP.simulateQ_of_step` and `IsQueryBoundP.simulateQ_of_step_le_total`
follow from it. Query logging keeps predicate-targeted bounds and query predicates, and
`AllQueriesSatisfy.map_run_simulateQ_eq_of_query_map_eq` restricts the state-projection law to the
queries a program may make. From it, a cached run, and a run in the random oracle model, of a
program that never queries outside `P` returns the same results from caches agreeing on `P`.

`simulateQ_pure_eq_evalWithAnswerFn` answers queries with `pure` of fixed answers in any lawful
monad, and replaces the `X →ₒ Y` case in `VectorCommitment`. `ProbabilityBounds` gains a list
union bound, an implication bound, an `absDiff` split along a third event and a simp lemma for a
two-step null event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🤖 PR Summary

Failed to generate AI summary. Please check the per-file summaries and statistics below.


Statistics

Metric Count
📝 Files Changed 14
✅ Lines Added 713
❌ Lines Removed 78

Lean Declarations

✏️ Removed: 3 declaration(s)

VCVio/CryptoFoundations/VectorCommitment/Basic.lean (1)

  • theorem simulateQ_pure_eq_evalWithAnswerFn {m : Type → Type v} [Monad m] [LawfulMonad m]

VCVio/OracleComp/QueryTracking/QueryBound/Simulation.lean (2)

  • lemma isQueryBoundP_true_iff (oa : OracleComp spec α) (n : ℕ) :
  • theorem IsTotalQueryBound.isQueryBoundP {oa : OracleComp spec α} {n : ℕ}
✏️ Added: 76 declaration(s)

VCVio/EvalDist/ProbabilityBounds.lean (4)

  • theorem absDiff_prEvent_le_absDiff_prEvent_and_not_add (mx : m α) (p q r : α → Prop) :
  • theorem prEvent_bind_bind_false {β : Type} (mx : m α) (my : α → m β) :
  • theorem prEvent_exists_list_le {ι : Type*} (L : List ι) (mx : m α) (p : ι → α → Prop) :
  • theorem prEvent_le_prEvent_add_prEvent_of_imp (mx : m α) {p q r : α → Prop}

VCVio/OracleComp/QueryTracking/CachingOracle.lean (2)

  • lemma map_withCaching_run_ofFn_ite (so : QueryImpl spec m) {P : ι → Prop} [DecidablePred P]
  • theorem fst_map_run_simulateQ_withCaching_eq_of_allQueriesSatisfy (so : QueryImpl spec m)

VCVio/OracleComp/QueryTracking/LoggingOracle/Core.lean (2)

  • theorem allQueriesSatisfy_withQueryLog_iff {α : Type} (mx : OracleComp spec α) (P : ι → Prop) :
  • theorem isQueryBoundP_withQueryLog_iff {α : Type} (mx : OracleComp spec α) (p : ι → Prop)

VCVio/OracleComp/QueryTracking/QueryBound/Basic.lean (5)

  • lemma allQueriesSatisfy_map_iff (oa : OracleComp spec α) (f : α → β) (P : ι → Prop) :
  • lemma isQueryBoundP_bind_le
  • lemma isQueryBoundP_true_iff (oa : OracleComp spec α) (n : ℕ) :
  • theorem IsTotalQueryBound.isQueryBoundP {p : ι → Prop} [DecidablePred p] {oa : OracleComp spec α}
  • theorem evalWithAnswerFn_eq_of_allQueriesSatisfy {ans ans' : QueryImpl spec Id} {P : ι → Prop}

VCVio/OracleComp/QueryTracking/QueryBound/Simulation.lean (2)

  • theorem AllQueriesSatisfy.map_run_simulateQ_eq_of_query_map_eq
  • theorem IsQueryBoundP.simulateQ_of_step_le {ι' : Type u} {spec' : OracleSpec ι'}

VCVio/OracleComp/QueryTracking/RandomOracle/Simulation.lean (1)

  • lemma fst_map_run_simulateQ_romImpl_eq_of_allQueriesSatisfy {α : Type} {P : ι → Prop}

VCVio/OracleComp/QueryTracking/RunLog.lean (16)

  • @[simp] theorem evalWithAnswerFn_withQueryLog (ans : QueryImpl spec Id) (oa : OracleComp spec α) :
  • @[simp] theorem runLog_map (ans : QueryImpl spec Id) (g : α → β) (oa : OracleComp spec α) :
  • @[simp] theorem runLog_pure (ans : QueryImpl spec Id) (a : α) :
  • @[simp] theorem runLog_query (ans : QueryImpl spec Id) (t : spec.Domain) :
  • @[simp] theorem runLog_query_bind (ans : QueryImpl spec Id) (t : spec.Domain)
  • @[simp] theorem runLog_withQueryLog (ans : QueryImpl spec Id) (oa : OracleComp spec α) :
  • def runLog (ans : QueryImpl spec Id) (oa : OracleComp spec α) : QueryLog spec
  • theorem evalWithAnswerFn_eq_of_forall_mem_runLog {ans ans' : QueryImpl spec Id}
  • theorem forall_mem_runLog_of_allQueriesSatisfy (ans : QueryImpl spec Id) {P : ι → Prop}
  • theorem length_filterMap_runLog_le (ans : QueryImpl spec Id) {p : ι → Prop} [DecidablePred p]
  • theorem mem_runLog_simulateQ {ι' : Type u} {spec' : OracleSpec.{u, u} ι'}
  • theorem runLog_bind (ans : QueryImpl spec Id) (oa : OracleComp spec α)
  • theorem runLog_eq_of_allQueriesSatisfy {ans ans' : QueryImpl spec Id} {P : ι → Prop}
  • theorem runLog_eq_of_forall_mem_runLog {ans ans' : QueryImpl spec Id}
  • theorem runLog_simulateQ {ι' : Type u} {spec' : OracleSpec.{u, u} ι'} (ans : QueryImpl spec' Id)
  • theorem run_simulateQ_withLogging_eq_runLog (ans : QueryImpl spec Id) (oa : OracleComp spec α) :

VCVio/OracleComp/SimSemantics/SimulateQ.lean (1)

  • theorem simulateQ_pure_eq_evalWithAnswerFn [Monad m] [LawfulMonad m] (f : QueryImpl spec Id)

VCVioTest/OracleComp/QueryTracking/RunLog.lean (43)

  • @[expose] def allFalse : QueryImpl (Bool →ₒ Bool) Id
  • @[expose] def allTrue : QueryImpl (Bool →ₒ Bool) Id
  • @[expose] def atTrue : ((t : (Bool →ₒ Bool).Domain) × (Bool →ₒ Bool).Range t) → Option Unit
  • @[expose] def cacheF : (Bool →ₒ Bool).QueryCache
  • @[expose] def cacheT : (Bool →ₒ Bool).QueryCache
  • @[expose] def echo : QueryImpl (Bool →ₒ Bool) Id
  • @[expose] def hashFalse : OracleComp (unifSpec + (Bool →ₒ Bool)) Bool
  • @[expose] def hashTrue : OracleComp (unifSpec + (Bool →ₒ Bool)) Bool
  • @[expose] def queryTrue : OracleComp (Bool →ₒ Bool) Bool
  • @[expose] def twice : QueryImpl (Bool →ₒ Bool) (OracleComp (Bool →ₒ Bool))
  • @[expose] def twoQueries : OracleComp (Bool →ₒ Bool) Bool
  • example (mx : ProbComp Bool) (E : ℕ → Bool → Prop) :
  • example (mx : ProbComp Bool) (E : ℕ → Bool → Prop) :
  • example (mx : ProbComp Bool) (p q r : Bool → Prop) :
  • example (mx : ProbComp Bool) :
  • example : ((runLog allTrue twoQueries).filterMap atTrue).length = 2
  • example : (Prod.fst <$> queryTrue.withQueryLog).AllQueriesSatisfy (· = true)
  • example : (queryTrue >>= fun _ => queryTrue).IsQueryBoundP (· = true) 3
  • example : ENNReal.absDiff Pr{let _ ← (pure () : ProbComp Unit)}[True]
  • example : Prod.fst <$> (simulateQ (Bool →ₒ Bool).romImpl hashFalse).run cacheT ≠
  • example : Prod.fst <$> (simulateQ (Bool →ₒ Bool).romImpl hashTrue).run cacheT =
  • example : Prod.fst <$> (simulateQ allTrue.withCaching (liftM ((Bool →ₒ Bool).query false))).run
  • example : Prod.fst <$> (simulateQ allTrue.withCaching queryTrue).run cacheT =
  • example : Pr{let _ ← $ᵗ Bool; let _ ← $ᵗ Bool}[False] = 0
  • example : evalWithAnswerFn allFalse twoQueries.withQueryLog =
  • example : evalWithAnswerFn allTrue (liftM ((Bool →ₒ Bool).query false)) ≠
  • example : evalWithAnswerFn allTrue queryTrue = evalWithAnswerFn echo queryTrue
  • example : evalWithAnswerFn allTrue twoQueries = evalWithAnswerFn echo twoQueries
  • example : evalWithAnswerFn allTrue twoQueries ≠ evalWithAnswerFn allFalse twoQueries
  • example : runLog allFalse twoQueries = [⟨true, false⟩, ⟨false, false⟩]
  • example : runLog allTrue (simulateQ twice queryTrue) = [⟨true, true⟩, ⟨true, true⟩]
  • example : runLog allTrue queryTrue = runLog echo queryTrue
  • example : runLog allTrue twoQueries = [⟨true, true⟩, ⟨true, true⟩]
  • example : runLog allTrue twoQueries = runLog echo twoQueries
  • example : runLog allTrue twoQueries.withQueryLog = runLog allTrue twoQueries
  • example : simulateQ (fun t => (pure (allFalse t) : Option Bool)) twoQueries =
  • example : twoQueries.withQueryLog.IsQueryBoundP (· = true) 2
  • example : ¬ (simulateQ twice queryTrue).IsQueryBoundP (· = true) 1
  • example : ¬ Pr{let _ ← (pure () : ProbComp Unit)}[True] ≤
  • example : ¬ twoQueries.IsQueryBoundP (· = true) 1
  • example : ¬ twoQueries.withQueryLog.AllQueriesSatisfy (· = true)
  • theorem twice_simulateQ_bound : (simulateQ twice queryTrue).IsQueryBoundP (· = true) 2
  • theorem twoQueries_bound : twoQueries.IsQueryBoundP (· = true) 2

sorry Tracking

  • No sorrys were added, removed, or affected.

📄 **Per-File Summaries**
  • VCVio.lean: Added a public import of VCVio.OracleComp.QueryTracking.RunLog, making that module's definitions and theorems accessible to users of the VCVio package. This expands the public API to include the RunLog component of the QueryTracking subsystem.
  • VCVio/CryptoFoundations/VectorCommitment/Basic.lean: The theorem simulateQ_pure_eq_evalWithAnswerFn (which stated that answering every X →ₒ Y query with pure (H x) evaluates the computation at H) was removed from this file, and the proof of the existing theorem simulateQ_fixedOracleImpl_liftComp was refactored: the rw block no longer includes that lemma, and instead the lemma is applied using exact with explicit arguments, presumably importing it from elsewhere. No sorry or admit are introduced.
  • VCVio/EvalDist/ProbabilityBounds.lean: Added prEvent_exists_list_le, a union bound over lists mirroring the existing finset version; prEvent_le_prEvent_add_prEvent_of_imp, a lemma bounding a probability by the sum of two others under an implication condition; absDiff_prEvent_le_absDiff_prEvent_and_not_add, which bounds the absolute difference of two event probabilities by the distance where a third event fails plus its probability; and prEvent_bind_bind_false, a simp lemma giving probability zero for False after a double bind.
  • VCVio/OracleComp/QueryTracking/CachingOracle.lean: The file gains a module-level doc comment advertising the new theorem about unqueried cache entries. Lemma map_withCaching_run_ofFn_ite is added, stating that a withCaching step commutes with the operation of replacing cache entries outside a predicate P by entries from another cache. Theorem fst_map_run_simulateQ_withCaching_eq_of_allQueriesSatisfy then uses this lemma to prove that if every query in an OracleComp satisfies P, then cached runs from two caches that agree on all P-satisfying queries produce the same first-component results.
  • VCVio/OracleComp/QueryTracking/LoggingOracle/Core.lean: 添加了两个新定理: isQueryBoundP_withQueryLog_iff 和 allQueriesSatisfy_withQueryLog_iff。第一个定理说明对于任何谓词 p 和自然数 n, IsQueryBoundP mx.withQueryLog p n 等价于 IsQueryBoundP mx p n, 即日志记录保留了谓词导向的查询界限。第二个定理说明对于任何谓词 P, AllQueriesSatisfy mx.withQueryLog P 等价于 AllQueriesSatisfy mx P, 即日志记录不改变程序是否满足某个查询谓词。这些定理扩展了已有的 isTotalQueryBound_withQueryLog_iff, 用于证明日志记录是透明的。
  • VCVio/OracleComp/QueryTracking/QueryBound/Basic.lean: Added five lemmas and one theorem to the query-tracking infrastructure. isQueryBoundP_bind_le gives a monotonicity lemma for IsQueryBoundP with an explicit k ≥ n + m bound. allQueriesSatisfy_map_iff states that AllQueriesSatisfy is unchanged by mapping a function over the free monad. evalWithAnswerFn_eq_of_allQueriesSatisfy proves that answer functions agreeing on all queries satisfying P yield identical evaluations when the program's queries all satisfy P. IsTotalQueryBound.isQueryBoundP shows every total query bound implies a predicate‑targeted bound for any decidable predicate. isQueryBoundP_true_iff equates IsQueryBoundP with the always‑true predicate to IsTotalQueryBound. These extensions enable more flexible reasoning about query bounds and evaluation equivalence under query predicates.
  • VCVio/OracleComp/QueryTracking/QueryBound/Simulation.lean: Added the theorem IsQueryBoundP.simulateQ_of_step_le, establishing that a source program making at most n queries satisfying p is simulated by a program making at most n * cost queries satisfying q when each p-handler makes at most cost q-queries and each non-p-handler makes none; this generalizes the previous IsQueryBoundP.simulateQ_of_step_le_total (which now delegates to it via the new IsTotalQueryBound.isQueryBoundP conversion) and simplifies the proof of IsQueryBoundP.simulateQ_of_step. Deleted the lemmas IsTotalQueryBound.isQueryBoundP and isQueryBoundP_true_iff (superseded by the general framework). Added the theorem AllQueriesSatisfy.map_run_simulateQ_eq_of_query_map_eq, stating that a state projection commuting with handlers at all satisfied queries also commutes with the simulation. The module-level docstring was expanded to describe the multiplication-of-bounds pattern and the new AllQueriesSatisfy result.
  • VCVio/OracleComp/QueryTracking/RandomOracle/FreshQuery.lean: Summary unavailable — AI generation failed.
  • VCVio/OracleComp/QueryTracking/RandomOracle/Simulation.lean: Added a new lemma fst_map_run_simulateQ_romImpl_eq_of_allQueriesSatisfy (and its documentation) to OracleSpec in VCVio/OracleComp/QueryTracking/RandomOracle/Simulation.lean. The lemma states that if a program's hash queries all satisfy a predicate P, then the first component of the result of simulateQ hashSpec.romImpl oa is the same when run with two caches that agree at every point satisfying P. This formalizes the principle that unqueried points of the random oracle do not affect the program's output. The module-level docstring was also updated to include a bullet point describing this lemma.
  • VCVio/OracleComp/QueryTracking/RunLog.lean: This new file introduces the runLog function, which extracts the list of queries and their answers (the query log) from a deterministic run of an OracleComp program with a fixed answer function ans : QueryImpl spec Id. It provides a suite of theorems that characterize the log: the log of a pure program is empty (runLog_pure), the log of a bind concatenates logs (runLog_bind), a query logs itself with its answer (runLog_query), and logging a program does not change its log (runLog_withQueryLog). The file also establishes properties about simulations (runLog_simulateQ, mem_runLog_simulateQ), agreement of answer functions (evalWithAnswerFn_eq_of_forall_mem_runLog, runLog_eq_of_forall_mem_runLog, forall_mem_runLog_of_allQueriesSatisfy, runLog_eq_of_allQueriesSatisfy), and query bounds (length_filterMap_runLog_le). No sorries or admits are present.
  • VCVio/OracleComp/SimSemantics/SimulateQ.lean: The file adds a new theorem simulateQ_pure_eq_evalWithAnswerFn, which states that for any lawful monad m, any query implementation f in the identity monad, and any OracleComp mx, simulating with pure (f t) in m is pure of evalWithAnswerFn f mx. This is proved as a corollary of simulateQ_natural using MonadHom.pure. The module documentation is also updated to describe evalWithAnswerFn f as answering every query with the fixed answer function f, and to note the new theorem.
  • VCVioTest.lean: The file now publicly imports VCVioTest.OracleComp.QueryTracking.RunLog (line 128), making the RunLog module available to downstream consumers. This adds support for recording and reasoning about execution logs in the query-tracking subsystem, complementing the existing QueryLog module.
  • VCVioTest/OracleComp/QueryTracking/RunLog.lean: The file adds a new test module VCVioTest.RunLog with concrete examples and theorems verifying the behavior of OracleComp.runLog, query bounds (IsQueryBoundP), probability bounds, and unqueried cache entries. It defines oracle queries (twoQueries, queryTrue), handlers (allTrue, allFalse, echo, twice), caches (cacheT, cacheF), and random oracle programs (hashTrue, hashFalse). The examples show that logs record queries in order, that handlers agreeing on queried points produce equal logs and evaluations, that the bound twoQueries_bound is tight (two queries at true), and that caches for unqueried points are ignored while queried points matter. Probability bound lemmas are demonstrated with list union bounds and distance inequalities. No sorry or admit is present.
  • docs/agents/query-tracking.md: Added a new section "Runs with fixed answers" documenting evalWithAnswerFn, which answers every query with a fixed ans : QueryImpl spec Id, and OracleComp.runLog, which records the query path of such a run. The section lists lemmas (evalWithAnswerFn_withQueryLog, runLog_simulateQ, length_filterMap_runLog_le) that characterize log concatenation under bind, log behavior under simulateQ, and a bound on predicate-targeted queries, and notes that tableQueryLog in RandomOracle/FreshQuery.lean is runLog against a complete answer table. Also added a paragraph stating that if all queries satisfy P, two caches agreeing on P yield the same results via QueryImpl.fst_map_run_simulateQ_withCaching_eq_of_allQueriesSatisfy and similarly in the random oracle model via OracleSpec.fst_map_run_simulateQ_romImpl_eq_of_allQueriesSatisfy. The "Main Files" table now includes VCVio/OracleComp/QueryTracking/RunLog.lean.

Last updated: 2026-11-21 20:24 UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant