Zapper `_swapV3Single()` has multiple integration issues with V3 swap
Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/494
Found by
Honour, onthehunt, pkqs90
Summary
Zapper _swapV3Single() has multiple integration issues with V3 swap.
Root Cause
IndexUtils#addLPAndStake() uses the zap feature in case the provided _pairedLpTokenProvided token is not equal to _pairedLpToken. A swap needs to be conducted first to get the correct pairedLpTKN.
function addLPAndStake(
IDecentralizedIndex _indexFund,
uint256 _amountIdxTokens,
address _pairedLpTokenProvided,
uint256 _amtPairedLpTokenProvided,
uint256 _amountPairedLpTokenMin,
uint256 _slippage,
uint256 _deadline
) external payable override returns (uint256 _amountOut) {
...
if (_pairedLpTokenProvided != _pairedLpToken) {
@> _zap(_pairedLpTokenProvided, _pairedLpToken, _amtPairedLpTokenProvided, _amountPairedLpTokenMin);
}
...
}
In Zapper contract, there are multiple swap routes, depending on how zapMap[in][out] is defined. One of them is using Uniswap V3. However, there are a couple of issues here:
- In a single hop swap, the pool fee is forced to be
10000when quering the TWAP oracle. This is the case for PEAS/pairedLpTKN (protocol team commits to maintaining a PEAS/pairedLpTKN CL pool), however this may not be the case for other tokens. We should simply use_feeinstead of10000here. - On Arbitrum, the
_getPoolFee()always return 0, which does not work for DEX_ADAPTER. If we are using UniswapV3 on Arbitrum (instead of Camelot), this logic should be removed. - The predefined
V3_ROUTERis force set to Uniswap router on ethereum mainnet. For multihop v3 swaps,V3_ROUTERis used, so it will always fail for other chains, or other DEX routers.
https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/Zapper.sol
address constant V3_ROUTER = 0xE592427A0AEce92De3Edee1F18E0157C05861564;
function _getPoolFee(address _pool) internal view returns (uint24) {
@> return block.chainid == 42161 ? 0 : IUniswapV3Pool(_pool).fee();
}
function _swapV3Single(address _in, uint24 _fee, address _out, uint256 _amountIn, uint256 _amountOutMin)
internal
returns (uint256)
{
address _v3Pool;
@> try DEX_ADAPTER.getV3Pool(_in, _out, uint24(10000)) returns (address __v3Pool) {
_v3Pool = __v3Pool;
} catch {
@> _v3Pool = DEX_ADAPTER.getV3Pool(_in, _out, int24(200));
}
if (_amountOutMin == 0) {
address _token0 = _in < _out ? _in : _out;
uint256 _poolPriceX96 =
V3_TWAP_UTILS.priceX96FromSqrtPriceX96(V3_TWAP_UTILS.sqrtPriceX96FromPoolAndInterval(_v3Pool));
_amountOutMin = _in == _token0
? (_poolPriceX96 * _amountIn) / FixedPoint96.Q96
: (_amountIn * FixedPoint96.Q96) / _poolPriceX96;
}
uint256 _outBefore = IERC20(_out).balanceOf(address(this));
uint256 _finalSlip = _slippage[_v3Pool] > 0 ? _slippage[_v3Pool] : _defaultSlippage;
IERC20(_in).safeIncreaseAllowance(address(DEX_ADAPTER), _amountIn);
DEX_ADAPTER.swapV3Single(
@> _in, _out, _fee, _amountIn, (_amountOutMin * (1000 - _finalSlip)) / 1000, address(this)
);
return IERC20(_out).balanceOf(address(this)) - _outBefore;
}
function _swapV3Multi(
address _in,
uint24 _fee1,
address _in2,
uint24 _fee2,
address _out,
uint256 _amountIn,
uint256 _amountOutMin
) internal returns (uint256) {
uint256 _outBefore = IERC20(_out).balanceOf(address(this));
IERC20(_in).safeIncreaseAllowance(V3_ROUTER, _amountIn);
bytes memory _path = abi.encodePacked(_in, _fee1, _in2, _fee2, _out);
@> ISwapRouter(V3_ROUTER).exactInput(
ISwapRouter.ExactInputParams({
path: _path,
recipient: address(this),
deadline: block.timestamp,
amountIn: _amountIn,
amountOutMinimum: _amountOutMin
})
);
return IERC20(_out).balanceOf(address(this)) - _outBefore;
}
Internal pre-conditions
N/A
External pre-conditions
N/A
Attack Path
N/A
Impact
Zap feature does not work as expected, which impacts users calling IndexUtils#addLPAndStake().
PoC
N/A
Mitigation
N/A
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Peapods. Sherlock made it public on 12 March 2025. Found in the 749 audit contest (finding M-30), also found by 2 other wardens.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.