AutoCompoundingPodLP does not use correct oracle price as slippage for pairedLpTKn -> pTKN swap
The AutoCompoundingPodLP contract computes its minimum-output slippage check for a pairedLpTKn to pTKN swap using an oracle that returns the base-token-to-pTKN price rather than the paired-LP-token-to-pTKN price. For podded or fraxlend pair tokens the two prices differ by a constant asset/share ratio, so the slippage floor is set too low and attackers may be able to sandwich the swap.
Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/478
Found by
bretzel, pkqs90
Summary
AutoCompoundingPodLP does not use correct oracle price as slippage for pairedLpTKn -> pTKN swap.
Root Cause
When doing the pairedLpTKN -> pTKN swap in AutoCompoundingPodLP, it checks the oracle for the expected output, and uses it as slippage. However, the oracle does not return expected result.
There bug here is: the getPodPerBasePrice() function returns baseTKN/pTKN price, instead of pairedLpTKN/pTKN price. The difference is for podded token or fraxlend pair token as pairedLpTKN, e.g. pOHM or fUSDC. The price differs by a constant factor of asset/share ratio of the pod or the fraxlend pair token.
This underestimates the oracle price, which loosens the slippage constraint. This may lead to sandwich opportunities for attackers.
function _pairedLpTokenToPodLp(uint256 _amountIn, uint256 _deadline) internal returns (uint256 _amountOut) {
address _pairedLpToken = pod.PAIRED_LP_TOKEN();
uint256 _pairedSwapAmt = _getSwapAmt(_pairedLpToken, address(pod), _pairedLpToken, _amountIn);
uint256 _pairedRemaining = _amountIn - _pairedSwapAmt;
uint256 _minPtknOut;
if (address(podOracle) != address(0)) {
// calculate the min out with 5% slippage
// @audit-bug: This does not return the correct oracle price.
_minPtknOut = (
@> podOracle.getPodPerBasePrice() * _pairedSwapAmt * 10 ** IERC20Metadata(address(pod)).decimals() * 95
) / 10 ** IERC20Metadata(_pairedLpToken).decimals() / 10 ** 18 / 100;
}
IERC20(_pairedLpToken).safeIncreaseAllowance(address(DEX_ADAPTER), _pairedSwapAmt);
try DEX_ADAPTER.swapV2Single(_pairedLpToken, address(pod), _pairedSwapAmt, _minPtknOut, address(this)) returns (
uint256 _podAmountOut
) {
...
}
}
function getPodPerBasePrice() external view override returns (uint256 _pricePTknPerBase18) {
_pricePTknPerBase18 = 10 ** (18 * 2) / _calculateBasePerPTkn(0);
}
function _calculateBasePerPTkn(uint256 _price18) internal view returns (uint256 _basePerPTkn18) {
// pull from UniV3 TWAP if passed as 0
if (_price18 == 0) {
bool _isBadData;
(_isBadData, _price18) = _getDefaultPrice18();
if (_isBadData) {
return 0;
}
}
_basePerPTkn18 = _accountForCBRInPrice(pod, underlyingTkn, _price18);
// adjust current price for spTKN pod unwrap fee, which will end up making the end price
// (spTKN per base) higher, meaning it will take more spTKN to equal the value
// of base token. This will more accurately ensure healthy LTVs when lending since
// a liquidation path will need to account for unwrap fees
_basePerPTkn18 = _accountForUnwrapFeeInPrice(pod, _basePerPTkn18);
}
Internal pre-conditions
N/A
External pre-conditions
N/A
Attack Path
N/A
Impact
Oracle for pairedLpTKN -> pTKN swap slippage is incorrect. The slippage result is underestimated. This may lead to sandwich opportunities for attackers.
PoC
N/A
Mitigation
Also multiply the asset/share ratio for podded/fraxlend pair tokens as pairedLpTKN.
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 getPodPerBasePrice() oracle returns the baseTKN/pTKN price instead of the pairedLpTKN/pTKN price, omitting the asset/share ratio for podded or fraxlend pair tokens, so the computed minimum output is too low.
Impact
The slippage constraint on the pairedLpTKn to pTKN swap is loosened, which may create sandwich opportunities for attackers.
What the attacker needed
PairedLpTKn is a podded or fraxlend pair token
The fix
The oracle price used for slippage should also be multiplied by the asset/share ratio when the paired token is a podded or fraxlend pair token.
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 a contract swaps one token for another it sets a minimum amount it will accept, so a bad price cannot be forced on it. Here that minimum was calculated from the wrong price feed, one that ignores a conversion factor between two related tokens. The floor ended up lower than it should be, which gives someone who reorders trades around it more room to profit.
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.