AddLiquidity and decreaseLiquidity missing slippage protection
The contract hardcodes the minimum amount parameters to zero when increasing or decreasing liquidity in Uniswap V3 positions, removing slippage protection. An attacker could front-run these transactions to cause the user to receive much less than expected.
Submitted by ladboy233, also found by adriro, immeas, bin2chen, and said
When user mint NFT add liquidity, user can specify two parameter, params.amount0Min and params.amount1Min
// mint the position
(tokenId, liquidity, amount0Minted, amount1Minted) = Base.UNI_POSITION_MANAGER.mint(
INonfungiblePositionManager.MintParams({
token0: params.token0,
token1: params.token1,
fee: params.fee,
tickLower: params.tickLower,
tickUpper: params.tickUpper,
amount0Desired: params.amount0ToMint,
amount1Desired: params.amount1ToMint,
amount0Min: params.amount0Min,
amount1Min: params.amount1Min,
recipient: address(this),
deadline: block.timestamp
})
);
If the minted amount is too small, transaction revert in this check in Uniswap position manager when addling liquidity.
(amount0, amount1) = pool.mint(
params.recipient,
params.tickLower,
params.tickUpper,
liquidity,
abi.encode(MintCallbackData({poolKey: poolKey, payer: msg.sender}))
);
require(amount0 >= params.amount0Min && amount1 >= params.amount1Min, 'Price slippage check');
However, when addling liquidity, the parameter amount0Min and amount1Min is set to 0.
// increase liquidity via position manager
(liquidity, amount0Added, amount1Added) = Base.UNI_POSITION_MANAGER.increaseLiquidity(
INonfungiblePositionManager.IncreaseLiquidityParams({
tokenId: tokenId,
amount0Desired: amount0,
amount1Desired: amount1,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
})
);
As Uniswap V3 docs highlight:
https://docs.uniswap.org/contracts/v3/guides/providing-liquidity/mint-a-position#calling-mint
We set amount0Min and amount1Min to zero for the example - but this would be a vulnerability in production. A function calling mint with no slippage protection would be vulnerable to a frontrunning attack designed to execute the mint call at an inaccurate price.
If the user transaction suffers from frontrunning, a much less amount of token can be minted.
Same issue happens when user decrease liquidity:
function decreaseLiquidity(uint256 tokenId, uint128 liquidity) internal returns (uint256 amount0, uint256 amount1) {
(amount0, amount1) = Base.UNI_POSITION_MANAGER.decreaseLiquidity(
INonfungiblePositionManager.DecreaseLiquidityParams({
tokenId: tokenId,
liquidity: liquidity,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
})
);
}
The amount0 and amount1Min are set to 0.
When MEV bot frontruns the decrease liquidity, much less amount0 and amount1 are released.
Recommended Mitigation Steps
Recommend do not hardcode slippage protection parameter amount0Min and amount1Min to 0 when increase liquidity or decrease liquidity.
0xleastwood (Judge) commented:
This seems valid and serious. Worth adding as user-controlled parameters.
wukong-particle (Particle) confirmed and commented:
Agreed. Will add slippage protection when increase/decrease liquidity.
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
The contract hardcodes the slippage protection parameters (amount0Min and amount1Min) to zero instead of allowing the user to specify them.
Impact
A front-running attacker could cause the user to receive significantly less liquidity or tokens than expected, as the zero minimums provide no protection.
What the attacker needed
User adds or removes liquidity; attacker can front-run transaction
The fix
The contract should allow user-controlled slippage protection parameters instead of hardcoding them to zero.
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.
When you add or remove money from a trading pool, you can set a minimum amount you are willing to accept to protect against price changes. This code sets that minimum to zero, so if someone manipulates the price just before your transaction, you could get far less than you intended.
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.