`spTKNMinimalOracle.sol` counts debond fee twice, which will make the end price (spTKN per base) higher than it should be
The spTKNMinimalOracle contract double-counts the debond fee when calculating the price of spTKN per base token, making the price higher than it should be. This inflated price could be used in Fraxlend to determine solvency and collateral amounts, potentially allowing a liquidator to receive more collateral than deserved.
0xSpearmint1 Follow with Honour, Silvermist and 7 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/386
Found by
0xSpearmint1, Honour, Silvermist, TessKimy, X77, ZoA, bretzel, exploitabilityexplorer, pkqs90, wickie
Summary
The spTKNMinimalOracle::_calculateBasePerPTkn will count unwrap fee twice, which will make the base per PTkn price lower than what it should be. Eventually the base per PTkn price will be reversed and calculated into spTKN per base price, which will be higher than what it should be.
This inflated price of spTKN can be used to calculate the aspTkn price and in the fraxlend to determine solvency and also in the liquidation process. As the result the liquidator might get more than what they should get.
Root Cause
spTKNMinimalOracle::_calculateBasePerPTkn calculates the PTkn price based on the Tkn price. When it converts from Tkn price to pTkn price, it accounts for CBR and then account for unwrap fee:
However, the _accountForCBRInPrice uses WeightedIndex::convertToAssets:
https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/oracle/spTKNMinimalOracle.sol#L243
The WeightedIndex::convertToAssets already subtracts the debond fee from the assets returned:
https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/WeightedIndex.sol#L120-L130
This PTkn price from convertToAssets will be accounted for the unwrap fee using _accountForUnwrapFeeInPrice which will subtract the debond fee once more:
https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/oracle/spTKNMinimalOracle.sol#L246-L253
Also, if the base is pod, it uses _checkAndHandleBaseTokenPodConfig, which will as well use these two functions _accountForCBRInPrice and _accountForUnwrapFeeInPrice. Therefore it will as well count the debond fee twice.
https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/oracle/spTKNMinimalOracle.sol#L164 https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/oracle/spTKNMinimalOracle.sol#L213-L216
Internal Pre-conditions
Either (does not need to be both)
DEBOND_FEEof the WeightedIndex is set to non-zero- or the
BASE_IS_PODand the base has debond fee
External Pre-conditions
- The
aspTKNMinimalOracle.solwhich inherits fromspTKNMinimalOracle.sol, is used in the Fraxlend pair to determine the price ofaspTKNperborrowTkn.
Attack Path
- liquidator liquidates
Impact
The price of spTKN per base will calculated higher than it should be. If this incorrect price is used in Fraxlend pair, this incorrect price may be used to determine solvency and the amount of collateral for liquidator:
For the solvency, it is result in effectively higher maxLTV, so it is less problematic.
But for the calculation of collateral amounts for liquidator, the liquidator may get more collateral than they should get.
PoC
No response
Mitigation
Consider dropping the _accountForUnwrapFeeInPrice
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 function `_accountForCBRInPrice` already subtracts the debond fee via `WeightedIndex::convertToAssets`, and then `_accountForUnwrapFeeInPrice` subtracts it again.
Impact
The inflated price could cause a liquidator to receive more collateral than they should when the price is used in Fraxlend.
What the attacker needed
DEBOND_FEE is non-zero or BASE_IS_POD with debond fee; aspTKNMinimalOracle used in Fraxlend pair
The fix
The `_accountForUnwrapFeeInPrice` should be removed to avoid double-counting the debond fee.
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 price oracle is a smart contract that tells other contracts the price of an asset. Here, the oracle mistakenly subtracted a fee twice when converting between token prices, so the reported price was too high. If a lending platform uses this wrong price, it might give a liquidator too much collateral.
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.