Two day low oracle used in Market.liquidate() makes the system highly at risk in an oracle attack
The liquidation function uses a two-day low exchange rate from the oracle, which an attacker could manipulate for a short period to trigger unfair liquidations and overpay liquidator rewards. The text claims this makes the system highly risky for oracle attacks.
gs8nrv Follow with immeas, yamapyblack and 4 others
Originally disclosed on Code4rena
Submitted by gs8nrv, also found by immeas, yamapyblack, idkwhatimdoing, kaden, Holmgren, and rvierdiiev
https://github.com/code-423n4/2022-10-inverse/blob/3e81f0f5908ea99b36e6ab72f13488bbfe622183/src/Market.sol#L596 https://github.com/code-423n4/2022-10-inverse/blob/3e81f0f5908ea99b36e6ab72f13488bbfe622183/src/Market.sol#L594 https://github.com/code-423n4/2022-10-inverse/blob/3e81f0f5908ea99b36e6ab72f13488bbfe622183/src/Market.sol#L597
Usage of the 2 day low exchange rate when trying to liquidate is highly risky as it incentives even more malicious agents to control the price feed for a short period of time. By controlling shortly the feed, it puts at risk any debt opened for a 2 day period + the collateral released will be overshoot during the liquidation.
Proof of Concept
The attack can be done by either an attack directly on the feed to push bad data, or in the case of Chainlink manipulating for a short period of time the markets to force an update from Chainlink. Then when either of the attacks has been made the attacker call Oracle.getPrice(). It then gives a 2 day period to the attacker (and any other agent who wants to liquidate) to liquidate any escrow.
This has a second drawback, we see that we use the same value at line 596, which is used to compute the liquidator reward (l.597), leading to more collateral released than expected. For instance manipulating once the feed and bring the ETH/USD rate to 20 instead of 2000, liquidator will earn 100 more than he should have had.
Recommended Mitigation Steps
Instead of using the 2 day lowest price during the liquidation, the team could either take the current oracle price, while still using the 2 day period for any direct agent interaction to minimise attacks both from users side and liquidators side.
0xean (judge) decreased severity to Medium
08xmt (Inverse) disputed and commented:
The debt is not more at risk than through normal oracle manipulation. The oracle will return the normalized price if it’s lower than the dampened two-day low, meaning oracle manipulations can always be used for bad liquidations.
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 logic uses a two-day low price from the oracle instead of the current price, allowing a short manipulation to affect liquidations and rewards.
Impact
An attacker could force liquidations and receive more collateral than expected as a reward, but the protocol disputed that the debt is more at risk than through normal oracle manipulation.
What the attacker needed
Ability to manipulate the price feed; or ability to manipulate market to force Chainlink update
The fix
The team should use the current oracle price for liquidation while keeping the two-day period for other interactions.
How it was found
- Manipulate the price feed directly or manipulate the market to force a Chainlink update.
- Call Oracle.getPrice() to record the manipulated low price.
- Within the two-day window, liquidate any escrow using the manipulated low price.
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 liquidation is when someone's debt is closed because their collateral is worth too little. This report says the system checks a price that is the lowest seen over two days, so if an attacker can briefly push the price down, they can force liquidations and get a bigger reward than they should.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.