Repository navigation
formal: Lean proofs in the repo, linked to Router and AsyncSwap - #16
Merged
Merged
Conversation
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]>
This was referenced Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the Lean proofs from asyncswap/v2-proofs (
dev@f3c37e4) intoformal/and links them to the code the Foundry scripts call.Port.
AsyncSwapSpec/andAsyncSwapProtocol/withlakefile.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, nosorry, no extra axioms.Link.
formal/Generated/is the Lean model ofRouterandAsyncSwapfrom Formal Mind's formal-ast (solc AST;formal/scripts/generate.sh).formal/Refinement/proves each script-called def against theAsyncSwapProtocol.V2step it implements:AsyncSwap.setExecutorsetExecutor_refines,_frame,_escrow,_bal_nonneg,_claims_nonneg,_backing,_conservation,_reserves_nonnegstep (.setExecutor …)and everystep_*invariantAsyncSwap.isExecutorisExecutor_refinesWorld.isExecutorRouter.swapswap_sound,swap_complete,swapGuard_routerswapGuard, thenunlock(Swap, order)Router.cancelOrdercancelOrder_sound,cancelOrder_complete,unlockCallback_cancelsender = o.owner; the callback becomesHOOK.cancelOrder(order)Router.fillOrderfillOrder_value_sound,fillOrder_forwards,fillOrder_maxPrice,unlockCallback_fill_maxPricefillGuard'smsg.valueconjunct andliveGross ≤ maxPriceAll five show as proved on Formal Mind's Audit page (checked with
formal-ast … formal).CI.
.github/workflows/formal.ymlrunslake buildinformal/on every push and PR that touches it, and fails onsorry/admit/axiom.Gaps (details in
formal/README.md):unlockcalls back) and the hook's ETHreceiveare hypotheses infillOrder_maxPrice.Router.fillOrderitself is proved against its generated body, which needs formal-ast withcall{value:}support (asyncswap/formalmind, see below).asyncOrders/priceBookstoWorld.orders, and several hook internals are still opaque.settle,_settlePriorityFee, permits) are opaque, so the ledger effects aren't tied to code.🤖 Generated with Claude Code