Closed sherlock-admin2 closed 8 months ago
1 comment(s) were left on this issue during the judging contest.
takarez commented:
valid: duplicate of issue 106 due to the fact that if the returned offChainInvalid is true the diffPercent should be skipped and not checked; medium(2)
The protocol team fixed this issue in PR/commit https://github.com/dhedge/flatcoin-v1/pull/270.
evmboi32
medium
Offchain oracle price failure is handled incorrectly
Summary
Offchain oracle price failure is handled incorrectly.
Vulnerability Detail
The
OracleModule
is used to get a price of collateral. To get a price the contract calls_getPrice(maxAge)
and then tries to fetch an onchain chainlink oracle and offchain pyth oracle.The oracle price is chosen based on the latest timestamp, or if offchain oracle price is invalid it fallbacks to an onchain chainlink oracle.
The main idea is if the
offchainInvalid == true
which indicates that the offchain oracle price is invalid the contract should revert to the onchain oracle.The
offchainInvalid
will betrue
in one of three cases.1.) There is an error when calling the
oracle.getPriceNoOlderThan
2.)
price <= 0
orconf <= 0
orexpo >= 0
3.) the
price/confidence < minConfidenceRatio
In any of these cases, the price should rely on the onchain oracle as a fallback oracle.
Let's look at the code. Suppose we are fetching
ETH/USD
price. TheonchainPrice = 2000e18
and theoffchainPrice = 0e18
andoffchainInvalid = true
due to a failure in the_getOffchainPrice()
We then calculate the
priceDiff
= 2000e18 - 0 = 2000e18diffPercent
= 2000e18 * 1e18 / 2000e18 = 1e18The
diffPercent > maxDiffPercent
and the function reverts. The function should fallback to the onchain oracle in case of the invalid price data from the pyth oracle but it does not do so. ThemaxDiffPercent
should be set to1%
or so.Impact
If offchain oracle fails the system is DOSsed in the meantime instead of reverting to the onchain oracle.
Code Snippet
https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/OracleModule.sol#L111-L128
https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/OracleModule.sol#L163-L187
Tool used
Manual Review
Recommendation
Only check the
priceDiff
ifoffchainInvalid = false
. This will now correctly fallback to the onchain chainlink oracle in case of a pyth oracle failure. In cases where both prices are fetched correctly, it checks the price difference and selects the one with the latest timestamp.Duplicate of #177