What was proven
lean-solana prove translated three leaf functions from raydium-cp-swap at commit 3d69122 into Lean with Charon and Aeneas. The Lean kernel checked one theorem per function against AmmMath.ConstantProduct, with no sorry and only the axioms propext, Classical.choice and Quot.sound.
- Fees::
trading_fee Returns without panicking for every input.Some(fee)exactly whenamount * rate + 1_000_000 <= u128::MAX, withfee = ceil(amount * rate / 1_000_000);Noneotherwise. - ConstantProductCurve::
swap_base_input_without_fees Returns without panicking and equalsfloor(input * output_vault / (input_vault + input)), for inputs whereinput * output_vaultandinput_vault + inputfit inu128andinput_vault + input > 0. Outside this domain the function is not covered by this proof. - ConstantProductCurve::
lp_tokens_to_trading_tokens Returns without panicking for every input.Someexactly whenlp * vault_0andlp * vault_1fit inu128andsupply > 0;Noneotherwise.Floorgivesfloor(lp * vault / supply);Ceilingadds one when the division leaves a remainder and the floor is not zero.
AmmMath.ConstantProduct has related results about these definitions, which need further caller assumptions and are not part of these three theorems.
Lean ProveLib/AmmConstantProduct.lean
∀ amount rate, trading_fee amount rate ⦃ o => match o with
| some fee => amount.val * rate.val + FEE_DENOM ≤ U128.max ∧ fee.val = tradeFee amount.val rate.val
| none => U128.max < amount.val * rate.val + FEE_DENOM ⦄
∀ input x y, input.val * y.val ≤ U128.max → x.val + input.val ≤ U128.max → 0 < x.val + input.val →
swap_base_input_without_fees input x y ⦃ out => out.val = swapOut x.val y.val input.val 0 ⦄
∀ lp supply v0 v1 dir, lp_tokens_to_trading_tokens lp supply v0 v1 dir ⦃ o => match o with
| some r => lp.val * v0.val ≤ U128.max ∧ lp.val * v1.val ≤ U128.max ∧ 0 < supply.val ∧
(match dir with
| .Floor => r.token_0_amount.val = lpToTokensFloor lp.val supply.val v0.val ∧
r.token_1_amount.val = lpToTokensFloor lp.val supply.val v1.val
| .Ceiling => r.token_0_amount.val = lpToTokensCeil lp.val supply.val v0.val ∧
r.token_1_amount.val = lpToTokensCeil lp.val supply.val v1.val)
| none => U128.max < lp.val * v0.val ∨ U128.max < lp.val * v1.val ∨ supply.val = 0 ⦄
f args ⦃ r => P r ⦄ means the translated function returns normally and its result satisfies P. U128.max is 2128 − 1 and FEE_DENOM is 1 000 000.
What is trusted
- Charon's and Aeneas's translation of the Rust into Lean, Aeneas's models of
u128arithmetic andOption::unwrap, and the two modelsprovesupplies for?onOption. - The spec definitions
tradeFee,swapOut,lpToTokensFloorandlpToTokensCeilinpackages/amm-math/AmmMath/ConstantProduct.lean. - For
swap_base_input_without_fees, that callers stay inside the stated domain. That is checked by reading and is not proven. - That the extracted crate holds the upstream bytes. Each file's upstream git blob id and kept line ranges are recorded, and a live test refetches the files and compares them.
- The receipt published today comes from a WSL run without container isolation. A receipt from the Docker runner in CI replaces it.
Not covered
- In the extracted crate:
swap_base_output_without_fees,floor_div,protocol_fee,fund_fee,creator_fee,creator_fee_shared_amount,split_creator_fee,calculate_pre_fee_amount,CheckedCeilDiv::checked_ceil_div. - Everything else in raydium-cp-swap, including
CurveCalculator::swap_base_inputand the program's instructions. - The deployed program
CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C. Lean Directory's own program check reports it as unverified with no attestation; nothing here links it to commit3d69122.
How to reproduce
From a checkout of the Lean Directory repository, with the prove toolchain ready (lean-solana prove doctor):
node packages/prove/bin/prove.mjs docs/case-studies/raydium-cp-swap/crate --spec amm-cp --json LEANSVM_PROVE_LIVE=1 node --test --test-concurrency=1 packages/prove/test/prove.test.mjs
The prove run prints a receipt with ok: true and three proven obligations. The live tests also check that ten deliberately broken versions of the three functions each fail, and refetch the upstream files to compare bytes. The extracted crate, its extraction record, the receipt and the program-check record are in docs/case-studies/raydium-cp-swap/.