outdated variable is not effective to check price feed timeliness
The ChainlinkOraclePivot contract used a single 'outdated' variable to check the timeliness of two price feeds with different heartbeat intervals, making the check ineffective. An attacker could exploit stale prices from one feed or cause the other feed to always revert, potentially affecting rebalancing.
Source: https://github.com/sherlock-audit/2023-06-arrakis-judging/issues/83
Found by
0x007, 0x52, 0xg0, BenRai, Jeiwan, ast3ros, cergyk, elephant_coral, rvierdiiev, vnavascues
Summary
In ChainlinkOraclePivot, it uses one outdated variable to check if the two price feeds are outdated. However, this is not effective because the price feeds have different update frequencies.
Vulnerability Detail
Let's have an example:
In Polygon mainnet, ChainlinkOraclePivot uses two Chainlink price feeds: MATIC/ETH and ETH/USD.
The setup can be the same in this test case: https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/test/foundry/ChainLinkOraclePivotWrapper.t.sol#L49-L63
We can see that
- priceFeedA: MATIC/ETH price feed has a heartbeat of 86400s (https://data.chain.link/polygon/mainnet/crypto-eth/matic-eth).
- priceFeedB: ETH/USD price feed has a heartbeat of 27s (https://data.chain.link/polygon/mainnet/crypto-usd/eth-usd).
In function _getLatestRoundData, both price feeds use the same outdated variable.
- If we set the
outdatedvariable to 27s, the priceFeedA will revert most of the time since it is too short for the 86400s heartbeat. - If we set the
outdatedvariable to 86400s, the priceFeedB can have a very outdated value without revert.
try priceFeedA.latestRoundData() returns (
uint80,
int256 price,
uint256,
uint256 updatedAt,
uint80
) {
require(
block.timestamp - updatedAt <= outdated, // solhint-disable-line not-rely-on-time
"ChainLinkOracle: priceFeedA outdated."
);
priceA = SafeCast.toUint256(price);
} catch {
revert("ChainLinkOracle: price feed A call failed.");
}
try priceFeedB.latestRoundData() returns (
uint80,
int256 price,
uint256,
uint256 updatedAt,
uint80
) {
require(
block.timestamp - updatedAt <= outdated, // solhint-disable-line not-rely-on-time
"ChainLinkOracle: priceFeedB outdated."
);
priceB = SafeCast.toUint256(price);
} catch {
revert("ChainLinkOracle: price feed B call failed.");
}
Impact
The outdated variable is not effective to check the timeliness of prices. It can allow stale prices in one price feed or always revert in another price feed.
Code Snippet
https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/contracts/oracles/ChainLinkOraclePivot.sol#L31 https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/contracts/oracles/ChainLinkOraclePivot.sol#L239-L271
Tool used
Manual Review
Recommendation
Having two outdated values for each price feed A and B.
Discussion
Gevarist
oracle price check will always revert for few specific feeds. Should not result in fund loss, we are not considering the issue as medium level.
ctf-sec
I think this regular revert impact the rebalance...
#249 describes the issue well as well
recommend maintaining severity level
Gevarist
Yes that can impact rebalance but should not result in fund loss.
Gevarist
You can find the fix here on v2-manager-template repository, we now have two "outdated" variables to check individually if price feeds are outdated.
IAm0x52
Fix looks good. Oracle now has two separate outdated variables to accommodate feeds with different heartbeats
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 contract used a single 'outdated' threshold for two price feeds with different heartbeat intervals, so the check could not correctly validate both feeds.
Impact
The outdated variable is not effective to check the timeliness of prices. It can allow stale prices in one price feed or always revert in another price feed.
What the attacker needed
None
The fix
The fix was to use two separate 'outdated' variables, one for each price feed, to check individually if they are outdated.
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 used two price sources to calculate values, but checked both with the same time limit. Since one source updates every 27 seconds and the other every 24 hours, the check either rejected the slow source too often or accepted stale data from the fast source. This could lead to incorrect prices being used.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.