The provide_liquidity
instruction uses the same liquidity_calculation
function as the initialize_pool
instruction to calculate the amount of LP tokens to mint based on the amounts of tokens A and B provided:
This calculation is only correct during the initial pool creation (when no LP tokens exist yet). For subsequent liquidity additions, the LP token amount must be proportional to the existing LP supply and reserves.
Using the initial pool creation formula to mint LP tokens on additional liquidity deposits will cause:
Incorrect LP token minting: The amount of LP tokens minted will not reflect the depositor’s true share of the pool.
Imbalanced LP token distribution: Liquidity providers may receive too many or too few LP tokens, resulting in unfair shares.
Economic exploits: Malicious actors could exploit this miscalculation to mint more LP tokens than deserved, diluting other liquidity providers’ holdings.
Pool state inconsistency: Pool accounting and invariant assumptions may break, causing downstream issues in swaps or removals.
When liquidity already exists, LP tokens to mint must be proportional to the existing LP supply and token reserves. The correct formula is:
Where:
totalSupply
is the current total supply of LP tokens.
reserveA
and reserveB
are the current token balances in the pool vaults.
Replace the incorrect call to liquidity_calculation
with a function that:
Fetches the current total LP token supply.
Fetches the current vault balances (reserves) of tokens A and B.
Calculates lp_to_mint
as the minimum of the proportional LP tokens derived from each token amount relative to reserves and total LP supply.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.