ControllerPeggedAssetV2: outdated price may be used which can lead to wrong depeg events
The smart contract does not check the timestamp of the price feed data, so an outdated price could be used. This could cause a depeg event to be triggered incorrectly.
Source: https://github.com/sherlock-audit/2023-03-Y2K-judging/issues/70
Found by
0xRobocop, 0xnirlin, ABA, Ch_301, Delvir0, Saeedalipoor01988, ShadowForce, TrungOre, ast3ros, bin2chen, carrot, evan, kaysoft, lemonmon, martin, minhtrng, p0wd3r, peanuts, roguereddwarf
Summary
The updatedAt timestamp in the price feed response is not checked. So outdated prices may be used.
Vulnerability Detail
The following checks are performed for the chainlink price feed: https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Controllers/ControllerPeggedAssetV2.sol#L299-L315
As you can see the updatedAt timestamp is not checked.
So the price may be outdated.
Impact
The price that is used by the Controller can be outdated. This means that a depeg event may be caused due to an outdated price which is incorrect. Only current prices must be used to check for a depeg event.
Code Snippet
Tool used
Manual Review
Recommendation
Introduce a reasonable limit for how old the price can be and revert if the price is older:
iff --git a/Earthquake/src/v2/Controllers/ControllerPeggedAssetV2.sol b/Earthquake/src/v2/Controllers/ControllerPeggedAssetV2.sol
index 0587c86..cf2dcf5 100644
--- a/Earthquake/src/v2/Controllers/ControllerPeggedAssetV2.sol
+++ b/Earthquake/src/v2/Controllers/ControllerPeggedAssetV2.sol
@@ -275,8 +275,8 @@ contract ControllerPeggedAssetV2 {
,
/*uint80 roundId*/
int256 answer,
- uint256 startedAt, /*uint256 updatedAt*/ /*uint80 answeredInRound*/
- ,
+ uint256 startedAt,
+ uint256 updatedAt, /*uint80 answeredInRound*/
) = sequencerUptimeFeed.latestRoundData();
@@ -314,6 +314,8 @@ contract ControllerPeggedAssetV2 {
if (answeredInRound < roundID) revert RoundIDOutdated();
+ if (updatedAt < block.timestamp - LIMIT) revert PriceOutdated();
+
return price;
}
Discussion
3xHarry
considering this
3xHarry
fix PR: https://github.com/Y2K-Finance/Earthquake/pull/141
IAm0x52
Fix looks good. Controller will now revert if price is stale
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 contract fails to validate the freshness of the price feed data by not checking the `updatedAt` timestamp.
Impact
The price used by the Controller can be outdated, which may cause a depeg event to be triggered incorrectly.
What the attacker needed
Price feed becomes stale
The fix
The fix adds a check that reverts if the price is older than a reasonable limit, and the text confirms it was fixed.
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 smart contract uses a price feed to decide if an asset has lost its peg. The price feed includes a timestamp showing when the price was last updated, but the contract ignores it. So if the price feed stops updating, the contract might use an old price and wrongly think the asset is depegged.
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.