Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M-24 MitigationConfirmed #98

Open
c4-bot-10 opened this issue Apr 29, 2024 · 2 comments
Open

M-24 MitigationConfirmed #98

c4-bot-10 opened this issue Apr 29, 2024 · 2 comments
Labels
confirmed for report This issue is confirmed for report mitigation-confirmed MR-M-24 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@c4-bot-10
Copy link
Contributor

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 debt + max penalty exceeds fullValue, the penalty is now calculated as debt * 10%. Revert introduces a new safety check here. This op checks if the NFT position's full value exceeds the penalty. If it does, Revert then deducts the penalty from the fullValue and sets the liquidatorCost to fullValue - penalty. This allows a liquidator to receive the penalty portioned from the NFT position full value.

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:

  • Revert will only call token.transferFrom() when liquidatorCost is zero.
  • Revert converts _requireMaxDifference()'s maxDifferenceX10000 argument from a uint256 to uint16. In addition, when checking if the price difference has exceeded an acceptable value, Revert now checks if maxDifferenceX10000 is below uint16 max value: maxDifferenceX10000 < type(uint16).max. This additional check has no impact on original issue documented but was worth mentioning as it's part of PR H-01 MitigationConfirmed #7.

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-bot-3 added a commit that referenced this issue Apr 29, 2024
@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label May 1, 2024
@c4-judge
Copy link

c4-judge commented May 1, 2024

jhsagd76 marked the issue as satisfactory

@c4-judge
Copy link

c4-judge commented May 1, 2024

jhsagd76 marked the issue as confirmed for report

@c4-judge c4-judge added the confirmed for report This issue is confirmed for report label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed for report This issue is confirmed for report mitigation-confirmed MR-M-24 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants