Skip to content

feat(pfunctor): fold rules and bounds for chargeUnder - #530

Merged
dtumad merged 4 commits into
Verified-zkEVM:mainfrom
spitters:feat/charge-under-lemmas
Nov 25, 2026
Merged

dtumad merged 4 commits into
Verified-zkEVM:mainfrom
spitters:feat/charge-under-lemmas

Conversation

@spitters

Copy link
Copy Markdown
Contributor

Free/WP/Charge.lean has the cost transformer chargeUnder and its rules at the postcondition 0. A cost
analysis that composes programs needs the rules at a general postcondition, and bounds for the control
constructs. This PR adds 18 lemmas to Free/WP/Charge.lean, under the existing imports:

  • Unfolding: OpSpec.chargeUnder_eq, OpSpec.demonicUnder_eq.
  • Fold rules at a general postcondition: wpFold_chargeUnder_liftBind_le_iff,
    wpFold_chargeUnder_liftBind_const, wpFold_chargeUnder_liftBind_const_add,
    wpFold_chargeUnder_liftBind_le, wpFold_chargeUnder_pure_le, wpFold_chargeUnder_bind_le_add,
    wpFold_demonicUnder_liftBind_const.
  • Control constructs: wpFold_ite_le_max_enat, wpFold_dite_le_max_enat.
  • Relation to the other cost readings: isRollBound_iff_wpFold_chargeUnder_true,
    wpFold_charge_eq_chargeUnder_true, and wpFold_chargeUnder_eq_restrict, which generalises
    costUnder_eq_cost_restrict from the postcondition 0 to any postcondition.
  • Price vectors: wpFold_chargeUnder_pi_apply, wpFold_chargeUnder_pi_le_iff,
    wpFold_chargeUnder_price_le_sum, wpFold_chargeUnder_price_le.

wpFold_chargeUnder_bind_le_add is proved from costUnder_bind_le_of_wpFold. The lemmas are used by a
tactic downstream that derives time bounds of free programs and refers to them by these names.

spitters and others added 3 commits November 25, 2026 00:19
Fold rules for wpFold under chargeUnder and demonicUnder at a general
postcondition, bounds for ite and dite, the price-vector forms, and the restriction
equation wpFold_chargeUnder_eq_restrict for a general postcondition.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The call and bind rules take any postcondition on the continuation, and the
results of a bind live in independent universes. Boundary tests cover calls
with no allowed answer, exact budgets, the leaf invariant of a bind, and a
priced fold strictly below the priced vector fold.

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

dtumad commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks for this. I pushed a few changes to the branch and merged main. Each statement change is a strict generalization, and names and explicit arguments are unchanged.

  • Any postcondition. wpFold_chargeUnder_liftBind_le_iff, wpFold_chargeUnder_liftBind_le and wpFold_chargeUnder_bind_le_add now take an implicit post on the continuation. Your versions are the case fun _ => 0. In bind_le_add the bound on x itself is still at 0.
  • Universes. The result type in wpFold_chargeUnder_liftBind_le_iff, wpFold_chargeUnder_liftBind_const and wpFold_chargeUnder_liftBind_const_add is in any universe, and the two results of the bind rule are in independent ones.
  • Tests. PolyFunTest/PFunctor/Charge/Under.lean checks boundary cases: a call with no allowed answer, exact budgets, the bind invariant, and a priced fold strictly below the priced vector fold.

./scripts/validate.sh --lint --test --axioms passes at 0f100774. I haven't built CatCrypt against these, so please say if anything gets in the way of your tactic.

@dtumad
dtumad added this pull request to the merge queue Nov 25, 2026
Merged via the queue into Verified-zkEVM:main with commit 6c9cf97 Nov 25, 2026
9 checks passed
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.

2 participants