sherlock-audit/2023-12-flatmoney-judging

iberry - `latestRoundData()` has no check for round completeness

Closed this issue · 1 comments

iberry

medium

latestRoundData() has no check for round completeness

Summary

No check for round completeness could lead to stale prices and wrong price return value, or outdated price. The functions rely on accurate price feed might not work as expected, sometimes can lead to fund loss.

Vulnerability Detail

The oracle wrapper getOraclePrice() call out to an oracle with latestRoundData() to get the price of some token. Although the returned timestamp is checked, there is no check for round completeness.

According to Chainlink's documentation, this function does not error if no answer has been reached but returns 0 or outdated round data. The external Chainlink oracle, which provides index price information to the system, introduces risk inherent to any dependency on third-party data sources. For example, the oracle could fall behind or otherwise fail to be maintained, resulting in outdated data being fed to the index price calculations. Oracle reliance has historically resulted in crippled on-chain systems, and complications that lead to these outcomes can arise from things as simple as network congestion.

Impact

If there is a problem with chainlink starting a new round and finding consensus on the new value for the oracle (e.g. chainlink nodes abandon the oracle, chain congestion, vulnerability/attacks on the chainlink system) consumers of this contract may continue using outdated stale data (if oracles are unable to submit no new round is started).

This could lead to stale prices and wrong price return value, or outdated price.

As a result, the functions rely on accurate price feed might not work as expected, sometimes can lead to fund loss. The impacts vary and depends on the specific situation like the following:

incorrect liquidation
some users could be liquidated when they should not
no liquidation is performed when there should be
wrong price feed
causing inappropriate loan being taken

Code Snippet

https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/OracleModule.sol#L141-L157
function _getOnchainPrice() internal view returns (uint256 price, uint256 timestamp) {
IChainlinkAggregatorV3 oracle = onchainOracle.oracleContract;
if (address(oracle) == address(0)) revert FlatcoinErrors.ZeroAddress("oracle");

    (, int256 _price, , uint256 updatedAt, ) = oracle.latestRoundData();
    timestamp = updatedAt;
    // check Chainlink oracle price updated within `maxAge` time.
    if (block.timestamp > timestamp + onchainOracle.maxAge)
        revert FlatcoinErrors.PriceStale(FlatcoinErrors.PriceSource.OnChain);


    if (_price > 0) {
        price = uint256(_price) * (10 ** 10); // convert Chainlink oracle decimals 8 -> 18
    } else {
        // Issue with onchain oracle indicates a serious problem
        revert FlatcoinErrors.PriceInvalid(FlatcoinErrors.PriceSource.OnChain);
    }
}

Tool used

Manual Review

Recommendation

(uint80 roundID, int256 price, , uint256 timeStamp, uint80 answeredInRound) = oracle.latestRoundData();
require(answeredInRound >= roundID, "...");
require(timeStamp != 0, "...");

Duplicate of #3

1 comment(s) were left on this issue during the judging contest.

takarez commented:

invalid