#46982 [SC-Insight] Spread calculation discrepancy allows wildly divergent prices to be accepted
Description
Brief/Intro
Vulnerability Details
function _calculateMedian(bytes memory _prices) internal view returns (uint256 _medianPrice, bool _priceOk) {
//...
uint256 spread = 0;
uint256 middleIndex = length / 2;
if (length % 2 == 1) {
_medianPrice = prices[middleIndex];
if (length >= 3) {
spread = prices[middleIndex + 1] - prices[middleIndex - 1];
}
} else {
// if median is "in the middle", take the average price of the two consecutive prices
_medianPrice = (prices[middleIndex - 1] + prices[middleIndex]) / 2;
spread = prices[middleIndex] - prices[middleIndex - 1];
}
// check if spread is within the limit
_priceOk = spread <= maxSpreadBIPS * _medianPrice / MAX_BIPS; // no overflow
}Impact Details
Proof of Concept
Previous#46976 [SC-Low] Agent Destruction Can Permanently Lock Unclaimed Transfer FeesNext#46984 [SC-Low] Incomplete Token Supply Check After Token Share Recalculation in `_selfCloseExitTo`
Was this helpful?