Overflow in the mint function of ConcentratedLiquidityPool causes LPs’ funds to be stolen
The mint function of the ConcentratedLiquidityPool contract performed a balance check inside an unchecked block, so adding the amount owed to the existing reserve could wrap around to a small number. An attacker could then mint a very large liquidity position while paying almost nothing, and later burn it to take other liquidity providers' funds.
Submitted by broccoli
Impact
Similar to a previous finding in the IndexPool contract, the mint function of ConcentratedLiquidityPool allows integer overflows when checking the balance is larger or equal to the received amount of token plus the reserve. As a result, the attacker could get a large amount of liquidity but only provide a small number of tokens to the pool, effectively stealing other LPs’ funds when burning his liquidity.
Notice that this bug is independent of another bug of incorrect casting uint256 type to uint128 in the _getAmountsForLiquidity function. Even if the previously mentioned bug does not exist, the attacker could still steal the funds in the pool by exploiting this bug.
Proof of Concept
- Suppose that the current price is at the tick
500000, an attacker calls themintfunction with the following parameters:
mintParams.lower = 100000
mintParams.upper = 500000
mintParams.amount1Desired = (1 << 128) - 47541305835 # a carefully chosen number
mintParams.amount0Desired = 0
- Since the current price is equal to the upper price, we have
_liquidity = mintParams.amount1Desired * (1 << 96) // (priceUpper - priceLower)
= 4731732988155153573010127839
- The amounts of
token0andtoken1that the attacker has to pay is
amount0Actual = 0
amount1Actual = uint128(DyDxMath.getDy(_liquidity, priceLower, priceUpper, true))
= uint128(_liquidity * (priceUpper - priceLower) // (1 << 96)) # round up
= uint128(340282366920938463463374607384226905622)
= 340282366920938463463374607384226905622
= (1 << 128) - 47541305834
- As long as
reserve1is greater than47541305834, the additionamount1Actual + reserve1overflows to a small number, causing the attacker to pass the balance check.
Referenced code:
Recommended Mitigation Steps
Consider removing the unchecked statement to check for integer overflow or casting both amount1Actual and reserve1 to type uint256 before adding them and comparing to the _balance(token).
sarangparikh22 (Sushi) disputed:
The example is wrong, you can’t add use upper tick as odd, correct the example and resubmit please.
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
Root cause
Likely the balance check adds two values inside an unchecked block, so the sum can overflow and pass the comparison.
Impact
An attacker could obtain a large liquidity position for a tiny payment and later burn it to steal other LPs' funds; the project disputed the example, saying the upper tick used was invalid.
What the attacker needed
A deployed ConcentratedLiquidityPool; pool reserve1 above the small threshold; attacker can call mint
The fix
The unchecked block should be removed, or both values cast to uint256 before adding and comparing, so overflow is detected.
How it was found
- Choose mint parameters with a carefully selected amount1Desired near the maximum 128-bit value and a lower tick below the current tick.
- The contract computes liquidity from the desired amount and the price range.
- The amount the attacker must pay is computed and wraps to a value just below the 128-bit maximum.
- Because the reserve is larger than the small difference, the addition overflows and the balance check passes.
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.
A smart contract pool holds money from many people who deposit it. When you add a new deposit, the contract checks that you actually sent enough tokens by adding your amount to what is already there. If that addition is allowed to wrap around past the maximum number (an overflow), the total looks tiny and the check passes even though you paid almost nothing. The attacker then withdraws, taking other people's money.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.