Balancer ReClamm Swap Rounding Invariant
Swap rounding cannot give traders extra value.
L is the ReClamm product (R_A + V_A) * (R_B + V_B).
A and B are token labels for the two tokens in the ReClamm pool.
R_A and R_B are the real token reserves before or after the quote is applied.
V_A and V_B are the current virtual balances held fixed during this quote.
Balancer is an automated market maker protocol for programmable liquidity pools. ReClamm is one of its Balancer v3 two-token pool designs: it combines real balances with virtual balances so liquidity can be concentrated and readjusted over time. The swap quote is computed by onSwap, which calls into ReClammMath for exact-in and exact-out swaps.
Why It Matters
ReClamm prices swaps using the product (balanceA + virtualBalanceA) * (balanceB + virtualBalanceB). Exact-in swaps must round output down. Exact-out swaps must round input up. If either direction rounded in the trader's favor, repeated swaps could extract value from the pool.
How This Was Modeled and Proven
We modeled the ReClamm swap quote in Verity, LFG Labs' language for writing executable smart-contract models and proving properties about them in Lean 4. The model keeps the swap branch structure close to the Solidity source. The exact-in branch follows computeOutGivenIn and its Solidity division, which rounds the output down. The exact-out branch follows computeInGivenOut and calls the modeled mulDivUp helper, matching Balancer's ceiling-rounded input calculation.
The proof first extracts the returned quote from the executable hRun. It then proves the floor inequality for exact-in swaps and the ceiling inequality for exact-out swaps. The last step is arithmetic over natural numbers: applying the real balance deltas cannot reduce the product.
Scope
The proof covers successful onSwap quotes with current virtual balances held fixed during the quote. It checks exact-in and exact-out swaps for both token directions: token A to token B and token B to token A.
The proof does not cover the virtual-balance refresh path, timestamp interpolation, fees, or Vault accounting. Those are separate protocol layers. This case isolates the arithmetic surface related to Certora's I-01 finding, where an intermediate floor division could defeat an intended rounding-up path.
Proof artifacts
The source model is in Contract.lean. The invariant is stated in Specs.lean using the same helpers shown above: L_before and L_after.
Proven. The ReClamm case has one theorem and one spec. The reference proof compiles with no sorry, no admit, and no axiom.
| Function | Theorem | Status |
|---|---|---|
| onSwap | onSwap_fixed_virtual_balances_product_non_decreasing | Proven |
Verify it yourself
git clone https://github.com/lfglabs-dev/verity-benchmark cd verity-benchmark lake build Benchmark.Cases.Balancer.ReClammSwapRounding.Compile
If the build succeeds, Lean has checked the model, spec, and proof. Source repository
Hypotheses
The theorem uses these hypotheses. They are explicit proof boundaries, not axioms.
swap goes token A to B or token B to AReClamm two-token pool design
The swap indexes
(indexIn, indexOut)are either(0, 1)or(1, 0): token A to token B, or token B to token A. A production swap entering this pool is already in one of these two cases. The scalar Verity model keeps it explicit because token indexes are raw inputs.the successful swap math does not overflowSolidity 0.8 checked arithmetic
The successful Solidity arithmetic path does not overflow. This bundles five checks: the token-A total, token-B total, exact-in denominator, exact-in numerator, and exact-out numerator. If any overflowed, the quote would revert instead of returning an amount. The proof uses this to compare Verity's executable
Uint256execution with ordinary natural-number arithmetic.the swap quote succeedsExecutable Verity model
onSwapreturns success withamountCalculatedScaled18. The theorem is about successful quotes. If a require fails, the swap reverts and there is no returned amount to apply.
Learn More
Upstream Solidity source: ReClammPool.sol and ReClammMath.sol.
Certora report: April 15, 2025 ReClamm formal verification report.
Full case directory in the Verity benchmark repository.
What is a formal proof? A short explanation for non-specialists.
More research
Kuru V2 Shared Withdrawal Budget
A successful batch of ordinary withdrawals in the model reduces the shared budget by exactly its recorded payout value, across all accounts and tokens.
Dromos MetaDEX Allocation Conservation
In the root-ledger model, chain allocations sum to committed voting power.

KPK Shares Settlement Accounting
A successful kpkShares settlement batch processes each eligible request at most once and accounts exactly for its fees, shares and asset transfers.