code-423n4 / 2024-04-revert-mitigation-findings

1 stars 1 forks source link

M-24 MitigationConfirmed #98

Open c4-bot-10 opened 5 months ago

c4-bot-10 commented 5 months ago

Lines of code

Vulnerability details

Lines of code

https://github.com/revert-finance/lend/blob/audit/src/V3Vault.sol?plain=1#L1211

Vulnerability details

C4 issue

M-24: Incorrect liquidation fee calculation during underwater liquidation, disincentivizing liquidators to participate

Comments

When a liquidator liquidates a loan, the liquidator must pay a liquidation fee. This fee according to the Revert whitepaper should be calculated as 10% of the debt. However, in V3Vault._calculateLiquidation(), the liquidation fee is calculated as:

uint256 penaltyValue = fullValue * (Q32 - MAX_LIQUIDATION_PENALTY_X32) / Q32;

fullValue represents the full value of the collateral. This formula is incorrect as the penaltyValue is calculated as fullValue * 90%. Instead, the formula should be defined as debt * 10%.

Mitigation

PR #7

This PR resolves one major fix with a minor unrelated change.

The major fixes include:

If the penalty exceeds the fullValue, the liquidator will not have to pay anything for the liquidation. Next, the liquidationValue is set to fullValue, indicating that the liquidator will receive the full NFT position value. Finally, the reserve cost is set to debt - liquidatorCost. Since the liquidator is covering the liquidatorCost, the reserves will cover the delta between debt and liquidatorCost.

Minor changes:

To sum up, by setting the penalty to debt * 10%, the liquidator will now receive the appropriate discount for liquidating the bad loan. If the penalty exceeds the fullValue, although the liquidator will receive the full value of the position they will not receive the full 10% debt discount. I believe this is acceptable as the liquidator is not paying anything for the liquidation.

Conclusion

LGTM

c4-judge commented 5 months ago

jhsagd76 marked the issue as satisfactory

c4-judge commented 5 months ago

jhsagd76 marked the issue as confirmed for report