ConstantProductPool.burnSingle swap amount computations should use balance
The burnSingle function in ConstantProductPool computes swap amounts using reserves instead of balances, which can lead to incorrect swap amounts and potential loss of funds from the pool.
Submitted by cmichel
The ConstantProductPool.burnSingle function is basically a burn followed by a swap and must therefore act the same way as calling these two functions sequentially.
The token amounts to redeem (amount0, amount1) are computed on the balance (not the reserve). However, the swap amount is then computed on the reserves and not the balance. The burn function would have updated the reserve to the balances and therefore balance should be used here:
amount1 += _getAmountOut(amount0, _reserve0 - amount0, _reserve1 - amount1);
⚠️ The same issue occurs in the
HybridPool.burnSingle.
Impact
For a burn, usually the reserve should equal the balance, however if any new tokens are sent to the contract and balance > reserve, this function will return slightly less swap amounts.
Recommended Mitigation Steps
Call _getAmountOut with the balances instead of the reserves: _getAmountOut(amount0, balance0 - amount0, balance1 - amount1)
Please bump this to High sev. This bug can actually lead to loss of funds from the pool. The author found the right issue but failed to analyze the full impact. Regardless, I think they deserve “High” for pointing this out.
This is what we come to C4 for
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
This bug can actually lead to loss of funds from the pool.
What the attacker needed
Balance > reserve due to extra tokens sent
The fix
Call _getAmountOut with the balances instead of the reserves.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a liquidity pool, users can burn their tokens to get back their share. The burnSingle function combines burning and swapping in one step. It calculates the swap using the pool's reserves (the amount the pool thinks it has) instead of the actual balance (the real amount it holds). If extra tokens are sent to the pool, the balance is higher than the reserve, so the swap gives less than it should, which can cause a loss of funds.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.