Lack of price validity check from Synthetix results in loss of funds while liquidating
The liquidation and order-fee code paths read prices from Synthetix without checking the returned 'isInvalid' flag, unlike other functions in the same contract that do check it. An attacker could trigger a liquidation while the price feed is momentarily invalid or stale, causing under- or over-liquidation and a loss of funds for the user or the protocol.
DadeKuma Follow with rbserver and __141345__
Originally disclosed on Code4rena
Submitted by DadeKuma, also found by rbserver and 141345
Lack of a validity check while liquidating results in loss of funds, as the price could be invalid momentarily from Synthetix due to high volatility or other issues.
Proof of Concept
There isn’t a check for isInvalid in getMarkPrice and getAssetPrice, which must be false before closing the liquidation:
File: src/ShortCollateral.sol
134: (uint256 markPrice,) = exchange.getMarkPrice();
135: (uint256 collateralPrice,) = synthetixAdapter.getAssetPrice(currencyKey);
This check is used in other similar functions that fetch the price:
File: src/ShortCollateral.sol
194: (uint256 markPrice, bool isInvalid) = exchange.getMarkPrice();
195: require(!isInvalid);
205: (collateralPrice, isInvalid) = synthetixAdapter.getAssetPrice(collateralKey);
206: require(!isInvalid);
This must be present to ensure that the price fetched from Synthetix is not stale or invalid.
If this isn’t the case, a liquidation could result in under-liquidation (a loss for the user) or over-liquidation (a loss for the protocol).
The same problem is also present in LiquidityPool:
File: src/LiquidityPool.sol
388: (uint256 markPrice,) = exchange.getMarkPrice();
As the markPrice is not validated when calculating the orderFee.
Recommended Mitigation Steps
Add a check to be sure that isInvalid is false in both markPrice and collateralPrice before liquidating.
rivalq (Polynomial) disagreed with severity
Would like @rivalq ‘s thought on the severity and validity. Was there a reason for an absence on these checks? (Like a redundancy because it would revert somewhere on an invalid price).
It was also raised by the warden that an invalid price could be 0 through these:
PerpsV2MarketViews.sol#L45-L50PerpsV2Market.sol#L124-L126How likely is this to happen?
mubaris (Polynomial) confirmed and commented:
This seems like a miss from our side.
Agreed on Medium severity.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the liquidation and order-fee functions destructure only the price from the Synthetix calls and discard the 'isInvalid' boolean, so no staleness check is performed before using the value.
Impact
A liquidation or order-fee calculation could run on a momentarily invalid price, leading to under-liquidation (a loss for the user) or over-liquidation (a loss for the protocol); the text does not show this being exploited in practice.
What the attacker needed
A position eligible for liquidation; price feed momentarily invalid or stale
The fix
The project acknowledged the omission as a miss; the recommended fix is to require that 'isInvalid' is false for both the mark price and the collateral price before liquidating.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A price feed tells a smart contract what an asset is worth. Synthetix's feed also returns a flag saying whether the price is currently trustworthy; if it is not, the price may be stale or zero. Here the liquidation code ignored that flag, so it could settle a liquidation using a bad price and pay out the wrong amount.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.