Closed c4-bot-4 closed 6 months ago
raymondfam marked the issue as insufficient quality report
raymondfam marked the issue as duplicate of #4
See #8.
hansfriese marked the issue as unsatisfactory: Out of scope
Nice finding!
I will close #155 and give full credit to this one.
hansfriese marked the issue as not a duplicate
hansfriese removed the grade
hansfriese marked the issue as satisfactory
hansfriese marked the issue as duplicate of #164
Lines of code
https://github.com/code-423n4/2024-03-dittoeth/blob/91faf46078bb6fe8ce9f55bcb717e5d2d302d22e/contracts/libraries/LibOracle.sol#L50-L66
Vulnerability details
Impact
The project employs a recommended safer approach for querying Chainlink price feeds, utilizing a defensive approach with Solidity’s try/catch structure. This ensures that if the call to the price feed fails, the caller contract remains in control and can handle any errors safely and explicitly. However, there are critical missing checks for received asset prices that could lead to one of the following two issues:
In both cases, the impact could result in users and the protocol losing funds, potentially harming the protocol's reputation. Therefore, the severity should be determined by considering the following criteria:
Severity: MEDIUM
Proof of Concept
While a safer method is implemented for querying Chainlink price feeds, the fallback logic in case of errors is vulnerable. Specifically, if the asset being queried for price is a non-USD asset, meaning it has an asset-specific oracle different from the baseOracle, then the else statement of the catch block could lead to the following scenarios:
Stale data: The price may be stale, as there is no check for it like the one in
baseOracleCircuitBreaker()
, i.e.,block.timestamp > 2 hours + timeStamp;
. This could result in users' trades being executed with incorrect asset prices, leading to loss of funds for users or the protocol.Incorrect price: In rare cases, the
price
returned from the oracle could be a negative number. The current check does not handle this case, as it only checks ifprice == 0
, which is not sufficient. If theprice
is a negative number, a direct typecast touint256
could yield unexpected results, resulting in an incorrect price for the asset.To verify the second issue, the following function could be used in Remix:
The output is as follows:
Vulnerable code in the context:
Tools Used
Manual Review, Remix
Recommended Mitigation Steps
To implement robust failover logic, add the following checks to the else statement of the catch block:
Assessed type
Other