Skip to content
Business logic Audit finding Intermediate

_calculateMaxBorrowCollateral calculates repay incorrectly and can lead to set token liquidation

The function _calculateMaxBorrowCollateral incorrectly applies unutilizedLeveragePercentage when computing the repay limit, causing an underflow and revert when borrowBalance exceeds a threshold. This prevents the ripcord function from repaying debt, leading to liquidation of the set token and losses from liquidation fees.

0x52 Follow with Kirkeelee

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-10-morpho-x-index-judging/issues/26

Found by

0x52, Kirkeelee

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

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/IndexCoop/index-coop-smart-contracts/pull/192

The original report as published on Sherlock, by 0x52. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

Set token suffers losses due to liquidation fee, which for most Morpho markets is at least 5%, and due to leverage the loss is multiplied (e.g., 15% for 3x, 25% for 5x).

What the attacker needed

UnutilizedLeveragePercentage is nonzero; collateral price drops rapidly

The fix

The protocol team fixed this issue in a pull request.

How it was found

  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

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract function that calculates how much debt can be repaid mistakenly reduces the limit by a percentage meant for unused leverage. When the debt grows too high, this causes a math error (underflow) that makes repayment attempts fail. As a result, the leveraged position cannot be rescued and gets liquidated, losing money to fees.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0x52

View all

211 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.