code-423n4 / 2024-01-salty-findings

4 stars 3 forks source link

ChainlinkAdapterOracle uses the ChainlinkFeedRegistry to obtain the price of the requested tokens. #1030

Closed c4-bot-8 closed 5 months ago

c4-bot-8 commented 5 months ago

Lines of code

https://github.com/code-423n4/2024-01-salty/blob/main/src/price_feed/CoreChainlinkFeed.sol#L2

Vulnerability details

Impact

Detailed description of the impact of this finding.

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 would allow user to continue borrowing with the asset but at the wrong price. This is exactly what happened to Venus on BSC when LUNA imploded.

Proof of Concept

Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.

try chainlinkFeed.latestRoundData() returns ( uint80, // _roundID int256 _price, uint256, // _startedAt uint256 _answerTimestamp, uint80 // _answeredInRound ) { // Make sure that the Chainlink price update has occurred within its 60 minute heartbeat // https://docs.chain.link/data-feeds#check-the-timestamp-of-the-latest-answer uint256 answerDelay = block.timestamp - _answerTimestamp;

        if ( answerDelay <= MAX_ANSWER_DELAY )
            price = _price;
        else
            price = 0;
        }
    catch (bytes memory) // Catching any failure
        {
        // In case of failure, price will remain 0
        }

    if ( price < 0 )
        return 0;

    // Convert the 8 decimals from the Chainlink price to 18 decimals
    return uint256(price) * 10**10;
    }

ChainlinkFeedRegistry#latestRoundData pulls the associated aggregator and requests round data from it. ChainlinkAggregators have minPrice and maxPrice circuit breakers built into them. This means that if the price of the asset drops below the minPrice, the protocol will continue to value the token at minPrice instead of it's actual value. This will allow users to take out huge amounts of bad debt and bankrupt the protocol.

Example: TokenA has a minPrice of $1. The price of TokenA drops to $0.10. The aggregator still returns $1 allowing the user to borrow against TokenA as if it is $1 which is 10x it's actual value.

Note: Chainlink oracles are used a just one piece of the OracleAggregator system and it is assumed that using a combination of other oracles, a scenario like this can be avoided. However this is not the case because the other oracles also have their flaws that can still allow this to be exploited. As an example if the chainlink oracle is being used with a UniswapV3Oracle which uses a long TWAP then this will be exploitable when the TWAP is near the minPrice on the way down. In a scenario like that it wouldn't matter what the third oracle was because it would be bypassed with the two matching oracles prices. If secondary oracles like Band are used a malicious user could DDOS relayers to prevent update pricing. Once the price becomes stale the chainlink oracle would be the only oracle left and it's price would be used.

Tools Used

Manual Analysis

Recommended Mitigation Steps

ChainlinkAdapterOracle should check the returned answer against the minPrice/maxPrice and revert if the answer is outside of the bounds:

(, int256 answer, , uint256 updatedAt, ) = registry.latestRoundData(
    token,
    USD
);

Assessed type

Context

c4-judge commented 5 months ago

Picodes marked the issue as duplicate of #825

c4-judge commented 4 months ago

Picodes marked the issue as unsatisfactory: Invalid

Picodes commented 4 months ago

Out of scope with the bot report

c4-judge commented 4 months ago

Picodes marked the issue as not a duplicate

c4-judge commented 4 months ago

Picodes marked the issue as duplicate of #25