Skip to content

Latest commit

 

History

History
44 lines (25 loc) · 2.35 KB

File metadata and controls

44 lines (25 loc) · 2.35 KB

Sharp Carmine Tortoise

High

Delever can be bricked leading to unwanted liquidations

Summary

The delever function calls the _setToken.invokeApprove function through the _repayBorrow function. If loan token is USDT it will cause the delever function to revert as USDT doesn't allow the token to be approved again when the approved amount is already more than 0. This could cause the delever function to be permanently blocked if USDT is used as the loan token which eventually could cause unwanted liquidations.

Root Cause

The delever function relies on the _repayBorrow function.

https://github.com/sherlock-audit/2024-10-morpho-x-index/blob/main/index-protocol/contracts/protocol/modules/v1/MorphoLeverageModule.sol#L281

Inside the _repayBorrow function, the _setToken.invokeApprove function is called to approve the required token before it calls _setToken.invokeRepay function. The _setToken.invokeRepay function in some chances will not necessarily use all the approved amount because the post trade amount can be greater than the (borrowed amount + interest rate) . As a result it's highly likely there will be some leftover approved amount. The logic inside the _repayBorrow function is fine for most ERC20 tokens, however this will fail for some tokens like USDT the second time this function is called, as USDT doesn't allow the token to be approved again with an amount more than 0 when the approved amount is already more than 0.

https://github.com/sherlock-audit/2024-10-morpho-x-index/blob/main/index-protocol/contracts/protocol/modules/v1/MorphoLeverageModule.sol#L733

Internal pre-conditions

No response

External pre-conditions

  1. USDT is used as the loan token
  2. USDT approval amount is already > 0

Attack Path

  1. SetToken manager call delever with USDT as loan token.
  2. SetToken manager call delever (again) with USDT as loan token. (Transaction reverted)

Impact

Delever can be bricked which is the function indirectly used by every user using morpho extension which could lead to unwanted liquidations for users.

PoC

No response

Mitigation

In the _repayBorrow function: If loan token used is USDT then check if the approval amount is already more than 0 if yes skip the approval. Alternatively, call the approval with 0 amount to reset the approval amount to 0, then call again with the real approval amount.