Low Liquidity in Uniswap V3 Pool Can Lead to ETH Lockup in JBXBuybackDelegate Contract
The JBXBuybackDelegate contract swaps ETH for project tokens on Uniswap V3 but sets the price limit to the extreme, so if the pool has low liquidity the swap stops early and the unused ETH remains locked in the contract. An attacker could exploit this by manipulating the pool or waiting for low liquidity, causing users' ETH to become permanently stuck.
minhquanym Follow with BLACK-PANDA-REACH, rbserver and 9 others
Originally disclosed on Code4rena
Submitted by minhquanym, also found by BLACK-PANDA-REACH, rbserver, Udsen, adriro, adriro, Udsen, sces60107, Madalad, max10afternoon, 0xStalin, and T1MOH
The JBXBuybackDelegate contract employs Uniswap V3 to perform ETH-to-project token swaps. When the terminal invokes the JBXBuybackDelegate.didPay() function, it provides the amount of ETH to be swapped for project tokens. The swap operation sets sqrtPriceLimitX96 to the lowest possible price, and the slippage is checked at the callback.
However, if the Uniswap V3 pool lacks sufficient liquidity or being manipulated before the transaction is executed, the swap will halt once the pool’s price reaches the sqrtPriceLimitX96 value. Consequently, not all the ETH sent to the contract will be utilized, resulting in the remaining ETH becoming permanently locked within the contract.
Proof of Concept
The _swap() function interacts with the Uniswap V3 pool. It sets sqrtPriceLimitX96 to the minimum or maximum feasible value to ensure that the swap attempts to utilize all available liquidity in the pool.
try pool.swap({
recipient: address(this),
zeroForOne: !_projectTokenIsZero,
amountSpecified: int256(_data.amount.value),
sqrtPriceLimitX96: _projectTokenIsZero ? TickMath.MAX_SQRT_RATIO - 1 : TickMath.MIN_SQRT_RATIO + 1,
data: abi.encode(_minimumReceivedFromSwap)
}) returns (int256 amount0, int256 amount1) {
// Swap succeeded, take note of the amount of projectToken received (negative as it is an exact input)
_amountReceived = uint256(-(_projectTokenIsZero ? amount0 : amount1));
} catch {
// implies _amountReceived = 0 -> will later mint when back in didPay
return _amountReceived;
}
In the Uniswap V3 pool, this check stops the loop if the price limit is reached or the entire input has been used. If the pool does not have enough liquidity, it will still do the swap until the price reaches the minimum/maximum price.
// continue swapping as long as we haven't used the entire input/output and haven't reached the price limit
while (state.amountSpecifiedRemaining != 0 && state.sqrtPriceX96 != sqrtPriceLimitX96) {
StepComputations memory step;
step.sqrtPriceStartX96 = state.sqrtPriceX96;
(step.tickNext, step.initialized) = tickBitmap.nextInitializedTickWithinOneWord(
state.tick,
tickSpacing,
zeroForOne
);
Finally, the uniswapV3SwapCallback() function uses the input from the pool callback to wrap ETH and transfer WETH to the pool. So, if _amountToSend < msg.value, the unused ETH is locked in the contract.
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external override {
// Check if this is really a callback
if (msg.sender != address(pool)) revert JuiceBuyback_Unauthorized();
// Unpack the data
(uint256 _minimumAmountReceived) = abi.decode(data, (uint256));
// Assign 0 and 1 accordingly
uint256 _amountReceived = uint256(-(_projectTokenIsZero ? amount0Delta : amount1Delta));
uint256 _amountToSend = uint256(_projectTokenIsZero ? amount1Delta : amount0Delta);
// Revert if slippage is too high
if (_amountReceived < _minimumAmountReceived) revert JuiceBuyback_MaximumSlippage();
// Wrap and transfer the weth to the pool
weth.deposit{value: _amountToSend}();
weth.transfer(address(pool), _amountToSend);
}
Recommended Mitigation Steps
Consider returning the amount of unused ETH to the beneficiary.
LSDan (judge) decreased severity to Medium
drgorillamd (Juicebox) confirmed
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 contract sets the Uniswap V3 swap price limit to the absolute minimum or maximum, so the swap can consume all liquidity and leave unused ETH without a refund mechanism.
Impact
If the pool has low liquidity or is manipulated, the unused ETH becomes permanently locked in the contract, causing a loss of funds for the user.
What the attacker needed
Low liquidity in the Uniswap V3 pool; or pool manipulation before the transaction
The fix
The contract should return any unused ETH to the beneficiary after the swap.
How it was found
- The terminal calls didPay() with ETH to swap.
- The _swap() function calls pool.swap() with sqrtPriceLimitX96 set to the extreme value.
- The Uniswap V3 pool stops the swap when the price limit is reached or input is exhausted.
- The callback wraps and sends only the used ETH as WETH to the pool.
- Any unused ETH remains in the contract because no refund is made.
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 pay ETH to this contract, it tries to swap all of it for project tokens on a trading pool. If the pool doesn't have enough tokens to buy, the swap stops early and the leftover ETH stays stuck in the contract forever, because there is no way to get it out.
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.