PriceOracle Does Not Filter Price Feed Outliers
The price oracle returns whatever value Chainlink supplies without checking it against any other source or historical range. If the feed were manipulated or malfunctioned, users would receive a malformed price, which could cause unintended liquidations or other economic harm.
Submitted by leastwood
Impact
If for whatever reason the Chainlink oracle returns a malformed price due to oracle manipulation or a malfunctioned price, the result will be passed onto users, causing unintended consequences as a result.
In the same time it’s possible to construct mitigation mechanics for such cases, so user economics be affected by sustainable price movements only. As price outrages provide a substantial attack surface for the project it’s worth adding some complexity to the implementation.
Proof of Concept
https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/PriceOracle.sol#L149-L161
function getLatestPrice(address num, address den) external view override returns (uint256, uint256) {
uint256 _price;
uint256 _decimals;
(_price, _decimals) = getChainlinkLatestPrice(num, den);
if (_decimals != 0) {
return (_price, _decimals);
}
(_price, _decimals) = getUniswapLatestPrice(num, den);
if (_decimals != 0) {
return (_price, _decimals);
}
revert("PriceOracle::getLatestPrice - Price Feed doesn't exist");
}
The above code outlines how prices are utilised regardless of their actual value (assuming it is always a non-zero value).
Recommended Mitigation Steps
Consider querying both the Chainlink oracle and Uniswap pool for latest prices, ensuring that these two values are within some upper/lower bounds of each other. It may also be useful to track historic values and ensure that there are no sharp changes in price. However, the first option provides a level of simplicity as UniswapV3’s TWAP implementation is incredibly resistant to flash loan attacks. Hence, the main issue to address is a malfunctioning Chainlink oracle.
The described suggestion is fairly complex - besides the increase in code complexity, we’d also have to decide the bounds within which the Uniswap and Chainlink oracles should report prices that won’t be trivial. We’ve also noted in the assumptions section of our contest repo that oracles are assumed to be accurate
” We expect these feeds to be fairly reliable.” - Based on this quote, I am going to leave this open at the current risk level. These are valid changes that could significantly reduce the risk of the implementation and unintended liquidations.
Fairly reliable != 100% reliable
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 oracle accepts the first non-zero price from Chainlink without sanity bounds or cross-checking against a second source such as a Uniswap TWAP.
Impact
A manipulated or malfunctioning Chainlink feed could feed a bad price into the protocol, potentially causing unintended liquidations; the report notes the project assumes oracles are accurate, so no defence is in place.
What the attacker needed
Chainlink feed returns a bad price; no secondary price check in place
The fix
The oracle should query both Chainlink and a Uniswap TWAP and reject prices that fall outside bounds between the two, or track historic values to catch sharp moves.
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 service that tells a smart contract what an asset is worth. This contract trusts that number completely, so if the oracle ever reports a wrong price, the contract acts on it. The report suggests comparing two independent price sources so a single bad number cannot slip through.