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

1 stars 1 forks source link

M-11 MitigationConfirmed #88

Open c4-bot-2 opened 2 months ago

c4-bot-2 commented 2 months ago

Lines of code

Vulnerability details

C4 issue

M-11: Lack of safety buffer in _checkLoanIsHealthy

Comments

Revert does not have a safety buffer for borrowed assets. Without a safety buffer, a borrower can borrow the maximum amount of funds equal to their collateral and if any minor price changes occurs in the market, the borrower runs the risk of being liquidated. This is encapsulated in the _requireLoanIsHealthy() function which maintains the following formula:

isHealthy = collateralValue >= debt;

As can be seen, there is no buffer between borrowed debt and collateral.

Mitigation

PR #17

This mitigation involves two fixes:

The first change updates the _checkLoanIsHealthy function to accept an additional argument called withBuffer. This param when set to true will re-calculate the collateral value to the following formula: collateralValue * BORROW_SAFETY_BUFFER_X32 / Q32. BORROW_SAFETY_BUFFER_X32 is also a new constant introduced in this fix and is set to 95% Q32. This formula reduces the collateral value by 5% and ensures that debt can never exceed 95% of the collateral. This adds a buffer if the debt or collateral values shift due to minor market movements.

The second change involves updating each call to _checkLoanIsHealthy() via passing in a new parameter called withBuffer. If set to true, this argument will calculate the collateral value with a buffer. If false, the collateral value will be calculated without a buffer. Below is a detailed list of each function that calls _checkLoanIsHealthy() and it's withBuffer setting:

To sum up, buffers should only be used when the loan's borrow or collateral changes. This prevents surprise liquidations. A buffer should NOT be used when calculating whether or not a loan should be liquidated.

Based on these changes, a buffer is correctly applied protecting borrowers from surprise liquidations.

Conclusion

LGTM

c4-judge commented 2 months ago

jhsagd76 marked the issue as satisfactory

c4-judge commented 2 months ago

jhsagd76 marked the issue as confirmed for report

c4-judge commented 2 months ago

jhsagd76 marked the issue as nullified

c4-judge commented 2 months ago

jhsagd76 marked the issue as not confirmed for report

c4-judge commented 2 months ago

jhsagd76 marked the issue as not nullified

c4-judge commented 2 months ago

jhsagd76 marked the issue as satisfactory

c4-judge commented 2 months ago

jhsagd76 marked the issue as confirmed for report