Skip to content

formal: Lean proofs in the repo, linked to Router and AsyncSwap - #16

Merged
mmsaki merged 1 commit into
mainfrom
formal/lean-proofs
Oct 20, 2026
Merged

mmsaki merged 1 commit into
mainfrom
formal/lean-proofs

Conversation

@mmsaki

@mmsaki mmsaki commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Ports the Lean proofs from asyncswap/v2-proofs (dev @ f3c37e4) into formal/ and links them to the code the Foundry scripts call.

Port. AsyncSwapSpec/ and AsyncSwapProtocol/ with lakefile.toml, lean-toolchain (leanprover/lean4:v4.35.0) and the Mathlib pin, copied as files (v2-proofs history unchanged). cd formal && lake exe cache get && lake build: clean, no sorry, no extra axioms.

Link. formal/Generated/ is the Lean model of Router and AsyncSwap from Formal Mind's formal-ast (solc AST; formal/scripts/generate.sh). formal/Refinement/ proves each script-called def against the AsyncSwapProtocol.V2 step it implements:

Function Theorems Spec
AsyncSwap.setExecutor setExecutor_refines, _frame, _escrow, _bal_nonneg, _claims_nonneg, _backing, _conservation, _reserves_nonneg step (.setExecutor …) and every step_* invariant
AsyncSwap.isExecutor isExecutor_refines World.isExecutor
Router.swap swap_sound, swap_complete, swapGuard_router the Router's conjuncts of swapGuard, then unlock(Swap, order)
Router.cancelOrder cancelOrder_sound, cancelOrder_complete, unlockCallback_cancel sender = o.owner; the callback becomes HOOK.cancelOrder(order)
Router.fillOrder fillOrder_value_sound, fillOrder_forwards, fillOrder_maxPrice, unlockCallback_fill_maxPrice fillGuard's msg.value conjunct and liveGross ≤ maxPrice

All five show as proved on Formal Mind's Audit page (checked with formal-ast … formal).

CI. .github/workflows/formal.yml runs lake build in formal/ on every push and PR that touches it, and fails on sorry / admit / axiom.

Gaps (details in formal/README.md):

  • The PoolManager (unlock calls back) and the hook's ETH receive are hypotheses in fillOrder_maxPrice. Router.fillOrder itself is proved against its generated body, which needs formal-ast with call{value:} support (asyncswap/formalmind, see below).
  • The hook's half of the swap / cancel / fill guards and bodies isn't refined yet. That needs an abstraction from asyncOrders / priceBooks to World.orders, and several hook internals are still opaque.
  • Token movements (settle, _settlePriorityFee, permits) are opaque, so the ledger effects aren't tied to code.
  • Callback routing for Swap / Match / LiquidityFill isn't proved.

🤖 Generated with Claude Code

Brings the Lake project from asyncswap/v2-proofs (dev @ f3c37e4) into formal/:
AsyncSwapSpec (fees, matching, partial fills, escrow invariant, admin, radix price
tree) and AsyncSwapProtocol (Router / PoolManager / hook / FeeVault call-sequence
state machine), Lean v4.35.0 + Mathlib. Copied as files; v2-proofs history is
unchanged.

Adds the Lean model of Router and AsyncSwap generated by Formal Mind's formal-ast
from solc's AST (formal/Generated, formal/scripts/generate.sh) and refinement
theorems (formal/Refinement) for the functions the scripts call:
AsyncSwap.setExecutor / isExecutor (full refinement; every step_* invariant carries
over), Router.swap and Router.cancelOrder (sound and complete for the Router's
conjuncts of the spec guard), Router.unlockCallback (Cancel routes to the hook;
FillOrder enforces liveGross <= maxPrice) and Router.fillOrder (conditional on its
untranslated body). Gaps are listed in formal/README.md.

`lake build` in formal/ is clean: no sorry, no extra axioms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mmsaki
mmsaki merged commit a97b093 into main Oct 20, 2026
2 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.

1 participant