Summary
Chainlink aggregators have a built in circuit breaker if the price of an asset goes outside of a predetermined price band. The result is that if an asset experiences a huge drop in value (i.e. LUNA crash) the price of the oracle will continue to return the minPrice instead of the actual price of the asset. This is exactly what happened to Venus on BSC when LUNA imploded.
Vulnerability Details
Note there is only a check for price
to be non-negative and activeness check, but not within an acceptable range.
function checkForInvalidTimestampOrAnswer(
uint256 timestamp,
int256 answer,
uint256 currentTimestamp,
uint256 maxTimeout
) private pure returns (bool) {
if (timestamp == 0 || timestamp > currentTimestamp) return true;
if (currentTimestamp.sub(timestamp) > maxTimeout) return true;
if (answer <= 0) return true;
return false;
}
https://github.com/Cyfrin/2024-05-beanstalk-the-finale/blob/main/protocol/contracts/libraries/Oracle/LibChainlinkOracle.sol#L182-L196
A similar issue is seen here.
Impact
refer Summary
Tools Used
Manual review
Recommendations
Implement the proper check for each asset. It must revert in the case of bad price.
https://github.com/Cyfrin/2024-05-beanstalk-the-finale/blob/main/protocol/contracts/libraries/Oracle/LibChainlinkOracle.sol#L55-L88
try priceAggregator.latestRoundData() returns (
uint80 roundId,
int256 answer,
uint256 ,
uint256 timestamp,
uint80
) {
if (roundId == 0) return 0;
if (checkForInvalidTimestampOrAnswer(timestamp, answer, block.timestamp, maxTimeout)) {
return 0;
}
+ require(answer >= minPrice && answer <= maxPrice, "invalid price");
return uint256(answer).mul(PRECISION).div(10 ** decimals);
} catch {
return 0;
}
}
```