Bounded no-theft: how much the pool's callers can gain

On this page

Summary

Consider a two-coin plain Curve StableSwap-NG pool. Across any sequence of calls to the pool, everyone who calls the pool—counted together as a single group—ends the run with at most

more than they started with, once anything borrowed from outside parties is repaid, and never more than the starting value of the pool's reserves. All values are measured at the pool's fixed initial rates, which price one whole coin of either kind at par. For a balanced pool, I = 0; for an imbalanced pool, I is the invariant gap V₀ − D*—the pre-fee arbitrage value at the peg of trading the pool back to 50/50—about 206 coins at a 60/40 split and 2,762 coins at 80/20 in a million-coin pool with amplification A = 100. In a balanced million-coin pool of two 18-decimal coins, callers who start with one coin and borrow nothing can extract at most about 0.0001 coin in total over 100 pool calls, as long as the passive LPs keep their LP tokens (π = 0).

This guarantee is a theorem, bounded_no_theft_readable, machine-checked in HOL4 against the pool's Vyper source (CurveStableSwapNG.vy) executed in a formal semantics of Vyper. It holds for every finite run: any sequence of calls to any of the pool's 54 public functions—successful or reverting, with arbitrary arguments—interleaved with external token transfers that satisfy the assumptions below. Its second conjunct states the dual guarantee for passive liquidity providers: their collective share of the pool's reserves drops by at most I plus the same per-call rounding allowance, U and π. The theorem makes no assumption about LP allowances or permits: because only attackers call the pool during the run, a passive holder's LP tokens can leave the protected group only if an attacker pulls them via transferFrom under an allowance or permit the holder granted, and any value transferred that way is accounted for in π.

What the bound does and does not cover:

The sections below walk through the execution model, the formal theorem and its sixteen antecedents, each term of the bound, the initial imbalance I, and the scope limits. Two companion pages accompany this overview:

The setting

The pool. We model a single two-coin Curve StableSwap-NG pool configured with plain coins. Pool calls execute the contract's Vyper source (CurveStableSwapNG.vy) in vyper-hol's definitional interpreter (call_external), while the two coins and the factory are arbitrary contracts whose behavior on pool calls satisfies the honesty hypotheses below.

LP tokens. The pool issues its own ERC-20 liquidity token: depositing coins mints LP tokens and burning LP tokens withdraws coins. We refer to the total number of LP tokens in existence as the supply.

A run. Starting from an initial machine state am0, a run executes a finite list of steps in order, where each step is either:

The final machine state am_end is produced by executing the steps from am0, rather than supplied as a separate free state.

Roles. A setup record s identifies the pool address, the set of attackers, and the set of protected LP holders. Every address that calls the pool during the run must belong to the attacker set, and all attackers are accounted for in aggregate so profit cannot be hidden by splitting calls across sybil addresses. The protected holders represent the passive liquidity providers: the passive tranche is the set of all LP tokens not held by attackers at am0, and the bound tracks how much of that tranche the protected holders retain (see π below). For coin transfers outside the pool, every address that is neither an attacker nor the pool is an outsider (including lenders, the protocol fee receiver, protected LP holders, and other token holders).

Value. Each coin i is valued at a constant price pᵢ, defined as the value of one smallest indivisible unit (wei) of coin i in normalized value units: the pool's initial stored rate stored_rates()[i] at am0 divided by 10¹⁸ (start_price). Because Curve StableSwap-NG factories set the stored rate of a plain coin with d decimals to 10^(36−d), its unit price is pᵢ = 10^(18−d) and one whole coin of either token is worth exactly 10¹⁸ value units. All numerical examples on this page follow that convention.

Wealth. The attackers' collective wealth at any machine (attacker_wealth) is the value of the coins they hold directly plus the value of their LP claim on the pool: when attackers hold L LP tokens out of total supply S against pool reserves r₀ and r₁, their LP claim is p₀ × ⌊L × r₀ / S⌋ + p₁ × ⌊L × r₁ / S⌋—the exact value of the coins a proportional withdrawal (remove_liquidity) would return, rounded down. Coins sitting inside the pool count toward attacker wealth solely through this claim. Both the reserves rᵢ (which exclude admin fees) and the LP quantities S and L are read through the pool's own public views balances(i), totalSupply(), and balanceOf(a), each evaluated as a standalone read-only transaction (pool_view). Attackers' direct coin balances are read through each coin's own balanceOf(a) method as invoked by the pool (coin_holding), with reverting queries counted as 0.

The theorem

Assumptions and implication antecedents (16):

 1. coins = state0.immutables.coins
 2. am_end = LAST (ordinary_machines am0 steps)
 3. wealth0 = attacker_wealth s coins am0 am0
 4. borrowed = total_borrowed s coins am0 steps
 5. rebalancing_arb = initial_imbalance s.pool am0
 6. slack =
   pool_calls steps *
   (SQRT (pool_value s.pool am0 + wealth0 + borrowed + 5) + 13)
 7. tranche = passive_tranche s am0
 8. pulled = pulled_lps s am0 steps
 9. pool_ready s am0 state0 ps0 (trace_K steps)
10. amp_fixed s.pool am0 steps
11. honest_contracts s am0 coins state0.immutables.factory steps
12. coins_answer_balanceOf s am0 coins
13. threat_model s steps
14. protected_start s am0
15. outside_steps s coins am0 steps
16. storage_slots_separate steps

Conclusion:

attacker_wealth s coins am0 am_end + total_paid_out s coins am0 steps ≤
wealth0 +
MIN (start_value s.pool am0 0 + start_value s.pool am0 1)
  (rebalancing_arb + 2 * unit_value_sum s.pool am0 + slack + pulled) +
borrowed ∧
pool_lp_claim s.pool am0 tranche am0 ≤
pool_lp_claim s.pool am0 tranche am_end + rebalancing_arb +
unit_value_sum s.pool am0 + slack + pulled
Free variable types

Free variables:

coins : 160 word list
state0 : CurveStableSwapNG_state
am_end : abstract_machine
am0 : abstract_machine
steps : ordinary_step list
wealth0 : num
s : theft_setup
borrowed : num
rebalancing_arb : num
slack : num
tranche : num
pulled : num
ps0 : pool_state

The theorem (bounded_no_theft_readable, in theory boundedNoTheft, stableswap-ng/bridge/boundedNoTheftScript.sml) is proved with zero admitted steps or oracles. All arithmetic is over natural numbers, where integer division and SQRT round down.

The assumptions

Each antecedent is summarized below; the assumptions section of the theorem dossier gives the exact HOL4 definitions alongside what each condition requires, why it cannot be dropped, and which internal lemmas pin it.

Crucially, nothing about how the pool's own code behaves is assumed: the effect of every pool entrypoint, the reserve accounting across calls, and the constancy of A are all proved from the Vyper source semantics. Likewise, nothing is assumed about how protected LP tokens move during the run—any loss of protected LP tokens is captured quantitatively by π.

When the protected holders retain at least the initial passive tranche at every step of the run (passive_lps) rather than only at am0, π = 0 (passive_lps_pulled_zero), and the corollary bounded_no_theft_readable_passive states the same bounds with π omitted.

The bound, term by term

Written in terms of the callers' net wealth gain (attacker_wealth at am_end minus W₀), the first conjunct of the conclusion states:

gain  ≤  min(V₀, I + n × (⌊√(V + W₀ + x + 5)⌋ + 13) + 2U + π) + (x − y)

where each symbol corresponds to a term in the formal statement:

Term Name in the theorem Meaning
W₀ wealth0 (attacker_wealth s coins am0 am0) the attackers' combined wealth at the start
V₀ start_value s.pool am0 0 + start_value s.pool am0 1 the starting value of the pool's reserves (excluding admin fees): beyond net borrowing, the attackers can never gain more than all the reserves in the pool
I rebalancing_arb (initial_imbalance s.pool am0) the pool's initial imbalance V₀ − D*: the pre-fee value at start prices of trading the pool back to balance (below)
n pool_calls steps the number of pool calls in the run, including reverting calls (outside steps do not increment n)
V pool_value s.pool am0 the total starting value of the coins held by the pool, including admin fees
x borrowed (total_borrowed s coins am0 steps) gross value lost by outsiders in outside steps—flash loans or transfers to attackers, as well as coins sent directly to the pool by outsiders
y total_paid_out s coins am0 steps gross value gained by outsiders in outside steps—loan repayments, interest/fees, or transfers from attackers
U unit_value_sum s.pool am0 p₀ + p₁, the combined value of one smallest unit (wei) of each coin
π pulled (pulled_lps s am0 steps) the start-price value of any LP tokens lost by the protected holders during the run (below)

The pulled LP tokens π

To track whether passive liquidity providers lose LP tokens during the run without restricting how LP tokens may be transferred, the theorem defines the protected holders' running floor (protected_floor). It starts at the initial passive tranche H and, after each step, updates to the minimum of its previous value and the protected holders' current summed balanceOf on the pool. Because it is a running minimum, returning LP tokens to protected holders later does not raise the floor. Whenever the floor drops, the drop is valued at the pool reserves and total supply immediately before that step (pool_lp_value), rounded up at the initial prices: losing L LP tokens from a pool with reserves r₀, r₁ and supply S adds ⌈L × (p₀ × r₀ + p₁ × r₁) / S⌉ to π (pulled_lps). Any shortfall below H at am0 is valued at am0, and any drop during step k is valued at machine k just before step k executes.

Whenever the protected holders keep at least H LP tokens at every step from am0 onward, the floor never drops and π = 0. Because only attackers call the pool during the run, a protected holder cannot call transfer or remove_liquidity directly; the floor can drop during the run only if an attacker pulls LP tokens from a protected holder via transferFrom using an allowance or EIP-2612 permit. Even then, the proof does not need to inspect how the tokens moved—it simply prices the drop in the protected holders' collective balance.

The initial-state hypothesis protected_start ensures that the protected holders start at am0 with all of H, so there is no initial shortfall at am0 and π sums only drops that happen during the run (protected_start_pulled). Without protected_start, any LP tokens held at am0 by a non-attacker omitted from s.protected would be counted in π as an immediate loss at am0.

The initial imbalance I

The initial imbalance I = V₀ − D* (initial_imbalance) is the gap between:

Economically, D* is the value the pool's reserves would have at peg prices once traded to a 50/50 balance along the zero-fee invariant curve, so I = V₀ − D* is the pre-fee arbitrage value the curve offers to whoever rebalances an off-balance pool at the peg (positive swap fees reduce the realizable payout below I). Because an imbalanced pool sells its surplus coin below par to attract the scarce coin, no theorem verified at par prices across all fee settings can exclude I. When the pool starts balanced (p₀ × r₀ = p₁ × r₁), D* = V₀ and I = 0.

For a pool holding one million coins in total (two 18-decimal coins at unit rates), I in whole coins (rounded to the nearest coin) varies with the reserve split and the effective amplification A = future_A() / A_PRECISION (A_PRECISION = 100) as follows:

A      50/50  60/40  80/20  95/5     (coins)
100    0      206    2762   19877
200    0      104    1393   10282
1000   0      21     281    2116

These figures are computed directly from the HOL definitions of initial_imbalance and newton_D_star (via binary search, justified by the monotonicity theorem cost_mono_D_general), and the A = 100, 80/20 entry is also verified inside HOL4: D* = 997238241325037251197896, giving I = 2761.758… coins.

When a pool starts severely lopsided at low amplification, I is correspondingly large and the bound becomes loose. For instance, the imbalanced withdrawal witness in rliAttackerOnlyNonVacuity starts from reserves [486288748, 3000] at unit prices and A = 1, where I = 468,563,285 (checked in HOL4) while a single remove_liquidity_imbalance call extracts 11,914.

What the passive providers can lose

The second conjunct of bounded_no_theft_readable bounds the loss of the passive LP tranche directly. Writing H for the initial passive tranche (tranche in the theorem, defined as passive_tranche s am0: totalSupply() minus the attackers' starting balanceOf) and valuing H by its proportional claim on the pool's reserves (pool_lp_claim), the theorem establishes:

claim of H at the start  ≤  claim of H at the end + I + U + n × (⌊√(V + W₀ + x + 5)⌋ + 13) + π

In other words, the passive liquidity providers' collective proportional claim on the pool's reserves—measured at the pool's fixed initial rates—can decrease across the run by at most the initial imbalance I, the per-call rounding allowance slack, one wei of each coin (U), and the value π of any LP tokens transferred out of the protected floor. Note that this bounds the passive tranche as an aggregate and values it by proportional reserve share (remove_liquidity), not by single-sided withdrawal (remove_liquidity_one_coin).

What the theorem does not promise

Why the assumptions can all hold

To verify that the sixteen antecedents are mutually consistent and non-vacuous, bounded_no_theft_readable_hypotheses_at_witness (in theory boundedNoTheftNonVacuity, stableswap-ng/evidence) proves every antecedent of bounded_no_theft_readable—together with passive_lps and π = 0—on a concrete six-step execution trace, conditional only on Keccak storage-key separation for the concrete keys touched by that trace (F4_keccak_separation). In that witness run, an external lender loans an attacker 40 coins of each token, and the attacker deposits them into the pool, withdraws liquidity, and repays both loans against concrete EVM bytecode deployments of the factory and token contracts.

Built from stableswap-proofs commit e6d73fa859d8 (2026-11-23). Formal identifiers in the text link directly to their definitions in the theorem explorer.