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

0x52 - _calculateMaxBorrowCollateral calculates repay incorrectly and can lead to set token liquidation #26

Open
sherlock-admin4 opened this issue Oct 21, 2024 · 1 comment
Labels
Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed

Comments

@sherlock-admin4
Copy link
Contributor

sherlock-admin4 commented Oct 21, 2024

0x52

High

_calculateMaxBorrowCollateral calculates repay incorrectly and can lead to set token liquidation

Summary

When calculating the amount to repay, _calculateMaxBorrowCollateral incorrectly applies unutilizedLeveragePercentage when calculating netRepayLimit. The result is that if the borrowBalance ever exceeds liquidationThreshold * (1 - unutilizedLeveragPercentage) then all attempts to repay will revert. This is nearly identical to the valid issue reported in the last contest that was fixed in the Aave leverage extension.

Root Cause

In MorphoLeverageStrategyExtension.sol:L1124 the borrow limit is reduced by unutilizedLeveragePercentage which will cause L1134 to underflow and revert.

Internal pre-conditions

unutilizedLeveragePercentage must be a nonzero value. For context this is nonzero for every existing leveraged token currently deployed by Index Coop.

External pre-conditions

The underlying collateral value decreases rapidly in price pushing the set towards liquidation

Attack Path

  1. The price of the underlying collateral decreases rapidly causing liquidationThreshold to drop
  2. borrowBalance exceeds liquidationThreshold * (1 - unutilizedLeveragPercentage)
  3. Calls to MorphoLeverageStrategyExtension#ripcord will revert due to underflow
  4. Set token is liquidated

Impact

Set token suffers losses due to liquidation fee. For most Morpho markets this is at least 5%. Due to the leveraged nature of the set the loss will be multiplicative. This means a 3x leverage token will lose 15% NAV (5% * 3), 5x leverage will lose 25% NAV (5% * 5), etc.

PoC

No response

Mitigation

Don't adjust the max value by unutilizedLeveragPercentage when deleveraging

@sherlock-admin2 sherlock-admin2 changed the title Polite Sand Finch - _calculateMaxBorrowCollateral calculates repay incorrectly and can lead to set token liquidation 0x52 - _calculateMaxBorrowCollateral calculates repay incorrectly and can lead to set token liquidation Oct 28, 2024
@sherlock-admin2
Copy link

The protocol team fixed this issue in the following PRs/commits:
IndexCoop/index-coop-smart-contracts#192

@sherlock-admin3 sherlock-admin3 added Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed
Projects
None yet
Development

No branches or pull requests

3 participants