Skip to content

feat(oracle): share deterministic query bounds and expectation folds - #1179

Merged
dtumad merged 6 commits into
Verified-zkEVM:mainfrom
dtumad:dtumad/436-polyfun-pin
Nov 22, 2026
Merged

dtumad merged 6 commits into
Verified-zkEVM:mainfrom
dtumad:dtumad/436-polyfun-pin

Conversation

@dtumad

@dtumad dtumad commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

OracleComp.queryUpperBound_of_isTotalQueryBound converts a structural query budget into CSLib’s size bound under every fixed deterministic oracle. A regression covers an input that makes no queries and an adaptive computation that can make two.

OracleComp.ProgramLogic.wp_eq_wpFold identifies VCVio’s measure-based lower expectation with the free-program fold under its configured discrete answer measures. It integrates each continuation and accepts an arbitrary postcondition. The primitive query law follows from the fold.

PolyFun’s exact writer instance supplies the rules for bind, pure and map, so the simplifier and the unary tactic use those laws in place of the three OracleComp.Lower.WriterT lemmas. An ordinary-import test exercises all three on a list writer.

This PR first pinned PolyFun at bdc1cde7 and fixed the program-logic regressions that pin exposed. Those fixes reached main through #1186 and #1204, and main now pins PolyFun at 713d8857, a descendant of bdc1cde7. After merging main, this PR adds the results above, their tests and documentation, and a row in docs/reading/upstream-alignment.md.

Verification

093a6930d merges main at e9727ae07. The pin files are now main's, and the ledger keeps both new rows. On that commit, ./scripts/validate.sh --lint --test --axioms passed, including environment lint, lake test and the axiom sweep. The sweep found zero sorry or nonstandard-axiom taint across 32,435 declarations in 1,335 modules. The run used the default test configuration with the optional native FFI backends disabled.

@github-actions

github-actions Bot commented Nov 18, 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 11
✅ Lines Added 87
❌ Lines Removed 13

Lean Declarations

✏️ Added: 6 declaration(s)

VCVio/OracleComp/QueryTracking/QueryBound.lean (1)

  • theorem queryUpperBound_of_isTotalQueryBound {ι α : Type u} {X : Type v}

VCVio/ProgramLogic/Unary/HoareTriple.lean (1)

  • theorem wp_eq_wpFold (oa : OracleComp spec α) (post : α → ℝ≥0∞) :

VCVio/ProgramLogic/Unary/WP/Lower.lean (1)

  • theorem instWP_eq_expectationWPMonad : instWP (spec

VCVioTest/ProgramLogic/CoreVCGen.lean (1)

  • example {α : Type} (t : spec.Domain) (k : spec.Range t → OracleComp spec α) (post : α → ℝ≥0∞) :

VCVioTest/ProgramLogic/CoreWP.lean (1)

  • example (x : WriterT (List Nat) ProbComp Nat) (post : Nat → List Nat → ℝ≥0∞) :

VCVioTest/QueryBounds.lean (1)

  • example : Cslib.Query.UpperBound

sorry Tracking

  • No sorrys were added, removed, or affected.

📄 **Per-File Summaries**
  • VCVio/OracleComp/QueryTracking/QueryBound.lean: The diff adds a public import of PolyFun.PFunctor.Free.Query and introduces a new theorem queryUpperBound_of_isTotalQueryBound. The theorem states that if a family of OracleComp programs (indexed by X) each satisfies IsTotalQueryBound with a monotone bound (via size), then the corresponding Cslib query programs (via toQueryProgram) have an UpperBound parameterized by the same size and bound. The proof uses PFunctor.FreeM.queryUpperBound_of_isTotalRollBound. No other changes occur in this file.
  • VCVio/ProgramLogic/Tactics/Unary.lean: The private tactic runVCGenFinish had three OracleComp.Lower.WriterT lemmas—wp_bind, wp_pure, and wp_map—removed from its internal lemma list, leaving only wp_tell and wp_monadLift from that namespace. This pruning narrows the set of rules the tactic can apply, potentially streamlining proof generation by avoiding unnecessary rewriting steps.
  • VCVio/ProgramLogic/Tactics/Unary/Internals/Steps.lean: This diff removes four WriterT theorems (wp_bind, wp_pure, wp_map) from the vcspec_simp attribute list in Steps.lean, while retaining wp_tell and wp_monadLift for that transformer. No theorems, definitions, or other code are added or modified; the change narrows the set of WriterT-layer lemmas that are automatically applied by vcspec_simp simplification.
  • VCVio/ProgramLogic/Unary/HoareTriple.lean: Added a new theorem wp_eq_wpFold that establishes an equality between the wp abbreviation and PFunctor.FreeM.wpFold applied to the oracle specification's Lintegral. The proofs of wp_query and wp_liftM_query were refactored to use this lemma, replacing previous invocations of wp_eq_lintegral, evalDist_liftM_query, and trim_eq_self with a single call to PFunctor.FreeM.wpFold_lift or a direct invocation of wp_query. The statements of wp_query and wp_liftM_query remain unchanged. No sorry or admit were introduced.
  • VCVio/ProgramLogic/Unary/WP/Lower.lean: The file now imports PolyFun.PFunctor.Free.Measure.WP, and the instWP instance is redefined to delegate to ExpectationWP.Lower.instWP instead of MAlgOrdered.toWPMonad. A new theorem instWP_eq_expectationWPMonad is added, establishing that this instance equals PFunctor.FreeM.expectationWPMonad under the oracle's discrete answer measures. Additionally, the open Lean.Order command was moved from its earlier position to after the new theorem block.
  • VCVioTest/ProgramLogic/CoreVCGen.lean: Added a new example proving that OracleComp.ProgramLogic.wp (queryBind t k) post equals the integral over OracleSpec.AnswerMeasure.toMeasure t of OracleComp.ProgramLogic.wp (k u) post. This decomposition, proved using wp_eq_wpFold and PFunctor.FreeM.wpFold_liftBind, is essential for reasoning about query continuations in the verification condition generator. No other changes appear in this file.
  • VCVioTest/ProgramLogic/CoreWP.lean: Added a new example that verifies an identity relating wp of a WriterT bind followed by map to wp of the original computation with the postcondition composed with Nat.succ. The proof relies on ExactWPMonad.wp_bind, ExactWPMonad.wp_map, and ExactWPMonad.wp_pure, expanding the test coverage for the program logic on WriterT.
  • VCVioTest/QueryBounds.lean: This change adds a public import of VCVio.OracleComp.QueryTracking.QueryBound and a new example that states and proves Cslib.Query.UpperBound for the program (fun b => if b then adaptive else pure false) with budget (fun b => if b then 2 else 0). The proof uses queryUpperBound_of_isTotalQueryBound and monotone_id, followed by case-splitting on b and simplifying with lemmas including isQueryBound_query_bind_iff and isQueryBound_query_iff. A docstring explains that the adaptive choice uses at most two queries under any fixed oracle while the other input returns immediately, exhausting its zero budget.
  • docs/agents/program-logic.md: The documentation in docs/agents/program-logic.md now describes the new OracleComp.ProgramLogic.wp_eq_wpFold lemma, which computes the expectation one call at a time by integrating each continuation under the configured answer measure, applying to arbitrary postconditions without requiring a measurable space on results. It also notes that the uniform-draw and constant-postcondition equations accept any empty exception postcondition, including the unit value that core normalization leaves in verification conditions, and that OracleComp.Lower.instWP_eq_expectationWPMonad identifies this scoped interpretation with PolyFun's free-program expectation reading. Finally, the documentation explains that the default query rule integrates the exact postcondition, while OracleComp.Lower.Pointwise lets vcgen descend through each answer.
  • docs/agents/query-tracking.md: Added a paragraph documenting how to import VCVio.OracleComp.QueryTracking.QueryBound to compare a structural budget with CSLib's deterministic oracle model, and explaining that OracleComp.queryUpperBound_of_isTotalQueryBound converts a family of total query budgets into a Cslib.Query.UpperBound on toQueryProgram for a monotone size bound. The paragraph clarifies that every fixed oracle follows one response path, and that a structural budget also covers response paths where repeated queries to the same index receive different answers.
  • docs/reading/upstream-alignment.md: The update adds a new row to the upstream-alignment table for PolyFun query counts and expectation readings, documenting that a structural total query budget implies CSLib's deterministic size bound, that the oracle lower WP equals the free expectation fold under configured discrete answer measures, and that exact uniform-draw rules reduce residual core WPs with an explicit empty exception postcondition. This matters because it captures significant upstream changes in how query budgets, expectation readings, and reading-specific rules are formalized in PolyFun, providing reviewers with essential context about the evolving dependency alignment.

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

@dtumad
dtumad force-pushed the dtumad/436-polyfun-pin branch from dd5946a to 565fbdc Compare November 18, 2026 04:34
@dtumad
dtumad changed the base branch from dtumad/lean-4.36 to main November 18, 2026 15:17
@dtumad
dtumad marked this pull request as ready for review November 18, 2026 15:27
dtumad and others added 5 commits November 18, 2026 09:28
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Main now pins PolyFun at 713d8857 (Verified-zkEVM#1204), a descendant of this
branch's pin bdc1cde7, so the pin conflicts resolve to main's files.
The upstream-alignment ledger keeps both new rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dtumad
dtumad added this pull request to the merge queue Nov 21, 2026
Merged via the queue into Verified-zkEVM:main with commit afef7b2 Nov 22, 2026
9 checks passed
dtumad added a commit to BoltonBailey/VCV-io that referenced this pull request Nov 22, 2026
…d-zkEVM#1186)

* feat(hashsig): replay settled WOTS+ chains from cache hints

Characterize when hidden caches with a shared hint admit a common upper bound in the native cache order. Apply the criterion to every settled WOTS+ chain and check a two-hash chain, incomparable caches, and conflicting answers.

Co-Authored-By: Codex <noreply@openai.com>

* refactor(deps): adopt current PolyFun strict state-bind lemmas

Preserve the existing VCVio instances while using the public theorem names from the target PolyFun revision. The full proof build rejects warnings from the deprecated spellings.

Co-Authored-By: Codex <noreply@openai.com>

* refactor(cache): keep the handler proof import private

The public criterion is stated in QueryCache vocabulary. Downstream consumers need the PolyFun theorem only while elaborating its proof.

Co-Authored-By: Codex <noreply@openai.com>

* refactor(wp): use generic strict WriterT rules

Keep the VCVio-specific names for explicit callers. The current PolyFun revision supplies the generic bind, pure and map simp rules for this exact-WP instance.

Co-Authored-By: Codex <noreply@openai.com>

* docs(hashsig): walk through two WOTS+ cache reads

Co-Authored-By: Codex <noreply@openai.com>

* fix(wp): import WriterT rules and use the shared infimum lemma

Co-Authored-By: Codex <noreply@openai.com>

* chore(deps): pin merged PolyFun handler replay

Co-Authored-By: Codex <noreply@openai.com>

* fix(pvcgen): retain unsolved goals after normalization

Port the tactic, lossless expectation rule, and regression from Verified-zkEVM#1179 commit 74ef550.

Co-Authored-By: Codex <noreply@openai.com>

* fix(wp): normalize constant expectations of partial computations

Co-Authored-By: Codex <noreply@openai.com>
(cherry picked from commit f587574)

* fix(wp): normalize uniform draws for any empty exception postcondition

Port the uniform-sampling rule from Verified-zkEVM#1179 commit 05df36f. The two-draw CoreVCGen regression exercises the normalized unit postcondition.

Co-Authored-By: Codex <noreply@openai.com>

---------

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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