Closed nzlatev7 closed 9 months ago
Yh a good one @nzlatev7 Actually found this bug while doing my unit test
Only to find out we ain't updating the liquidator Mapping of minted dsc
Yh a good one @nzlatev7 Actually found this bug while doing my unit test
Only to find out we ain't updating the liquidator Mapping of minted dsc
I was wondering why the liquidator health factor stay the same. And are we deliberately not updating the mapping. But if we purposely do not update liquidator's health factor the impact is this.
This is actually the correct functionality. When we liquidate a user, we are essentially paying off the users debt in return for a better rate on the liquidated users collateral.
It wouldn't make sense to liquidate a user and then STILL have the user owe money to the protocol.
Broken internal health factor after
liquidate
Relevant GitHub Links
https://github.com/Cyfrin/foundry-defi-stablecoin-f23/blob/76ba1ceb93214ece058f6b8b31580745a8340f4b/src/DSCEngine.sol#L200-L227
Summary
Base on the proof of concept provided below, you can see that after the liquidator perform liquidation calling the
liquidate
function his internal health factor is broken (the health factor may be good, but is not the health factor that need to be). The key is that theliquidate
function does not update thes_DSCMinted
mapping for the liquidator. It updates thes_DSCMinted
mapping for the user with the bad health factor and sendstotalCollateralToRedeem
to the liquidator but nothing is performed for the dept deposited by the liquidator. At the end, base on the system (s_DSCMinted
mapping) liquidator has amount of tokens that is difference from his actual dsc token balance (dsc.balanceOf(bob)
). In this way the liquidator will not be able to get back his full amount of collateral because he can not provide the amount listed in the mapping.Vulnerability Details
Impact
Liquidators will no be able to redeem their full collateral potencial base on the health factor, because the
s_DSCMinted
mapping have stale info. Additionally, liquidators would not call liquidate. The protocol would suffer insolvency in adverse market conditions due to no liquidations taking placeTools Used
Manual Review
Recommendations
To update the
s_DSCMinted
mapping in theliquidate
function for the liquidator, but this will lead to other vulnerabilities.