sherlock-audit / 2023-05-ironbank-judging

2 stars 2 forks source link

MohammedRizwan - Unhandled chainlink revert would lock price oracle access #379

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

MohammedRizwan

medium

Unhandled chainlink revert would lock price oracle access

Summary

Chainlink's latestRoundData() is used which could potentially revert and make it impossible to query any prices. This could lead to permanent denial of service.

Vulnerability Detail

In PriceOracle.sol,

File: src/protocol/oracle/PriceOracle.sol

66    function getPriceFromChainlink(address base, address quote) internal view returns (uint256) {
67        (, int256 price,,,) = registry.latestRoundData(base, quote);
68        require(price > 0, "invalid price");
69
70        // Extend the decimals to 1e18.
71        return uint256(price) * 10 ** (18 - uint256(registry.decimals(base, quote)));
72    }

The PriceOracle.getPriceFromChainlink() function makes use of Chainlink's latestRoundData() to get the latest price. However, there is no fallback logic to be executed when the access to the Chainlink data feed is denied by Chainlink's multisigs. Chainlink's multisigs can immediately block access to price feeds at will. Therefore, to prevent denial of service scenarios, it is recommended to query Chainlink price feeds using a defensive approach with Solidity’s try/catch structure. In this way, if the call to the price feed fails, the caller contract is still in control and can handle any errors safely and explicitly.

Impact

Call to latestRoundData could potentially revert and make it impossible to query any prices. This could lead to permanent denial of service.

Code Snippet

https://github.com/sherlock-audit/2023-05-ironbank/blob/9ebf1702b2163b55479624794ab7999392367d2a/ib-v2/src/protocol/oracle/PriceOracle.sol#L67

Openzeppelin reference-

Refer to https://blog.openzeppelin.com/secure-smart-contract-guidelines-the-dangers-of-price-oracles/ for more information regarding potential risks to account for when relying on external price feed providers.

Tool used

Manual Review

Recommendation

Surround the call to latestRoundData() with try/catch instead of calling it directly. In a scenario where the call reverts, the catch block can be used to call a fallback oracle or handle the error in any other suitable way.

Duplicate of #433