Closed code423n4 closed 11 months ago
Seems like it's an edge case narrowing the room for the end user unless the supplyCap is not a big value.
Relaying to the Sponsors for the perusal.
0xSorryNotSorry marked the issue as primary issue
ElliotFriedman marked the issue as sponsor disputed
not a valid issue, there are other ways to avoid this situation as a borrower such as posting collateral of a different type or repaying existing debt, also this report assumes that a position will go under water atomically, which is incredibly dubious that in a single block the following steps would happen:
The attacker doesn't need to be watching the mempool (which doesn't exist in Base) to execute this. If user A is dangerously close to liquidation, and the market in question is close to the supplyCap
, the liquidator might decide to add liquidity so that the supplyCap
is reached and an avenue for A to avoid liquidation is closed. It is a jungle out there and this looks like fair play to me.
I'll accept it as grade-b QA, and let the sponsor include this in the documentation if they wish to.
alcueca changed the severity to QA (Quality Assurance)
alcueca marked the issue as grade-b
Actually, reporting this as High is egregious. Invalid.
alcueca marked the issue as grade-c
Lines of code
https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/Comptroller.sol#L228-L237 https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/MToken.sol#L500 https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/MErc20.sol#L171-L174
Vulnerability details
Impact
The
Comptroller.mintAllowed
function is used by theMToken.mintFresh
function to verify whether themint
isallowed
. Theomptroller.mintAllowed
function uses thesupplyCaps
mapping to check whether the supply cap is reached for the specificmToken
market. If the supply cap is reached then the transaction will revert as follows:Now let's conisder the following scenario:
A borrower has borrowed
Token B
by depositingToken A as collateral
to the moonwell protocol.The liquidation threshold for the Token A deposited collateral is
70%
.The price of
Token A
is currently having a sharp price decline and the borrower decides to call theMToken.mint
function to deposit more collateral (Token A) to keep his position healthy.But in the
Token A
market the supply cap is 10,000 (Using this number for ease of understanding) and currently 9,000 has been supplied.Borrower needs to deposit
500
ofToken A as collateral
tomoonwell
to increase his liquidity position so he can avoid liquidation if theToken A
price further declines.Borrower calls the
MToken.mint
function and attempts to deposit500
of Token A.A malicious user front runs the Borrower and deposits
501
ofToken A
to theMToken
contract direclty.Now when the Borrower's
mint
transaction starts executing it will perform the following check in theComptroller.mintAllowed
function:Since the
attacker
deposited501
tokens to themToken
contract directly. TheMToken(mToken).getCash()
will retrieve the increasedToken A
balance of the contract.Now the
Borrower's
mint
transaction will revert since thenextTotalSupplies < supplyCap
(10,001 < 10,000) is false.As a result
Borrower
liquidation threshold will be breached and theattacker
will be able to liquidate theBorrower
thus profiting the extra liquidated collateral.Proof of Concept
https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/Comptroller.sol#L228-L237
https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/MToken.sol#L500
https://github.com/code-423n4/2023-07-moonwell/blob/main/src/core/MErc20.sol#L171-L174
Tools Used
Manual Review and VSCode
Recommended Mitigation Steps
It is recommended to further analyze the requirement of the
supplyCap
functionality of theComptroller.mintAllowed
function. If there is no limitation of thesupplyCap
then the above attack vector is non-existent.If the
supplyCap
functinality is a must, then the borrowers should be informed on a timely manner via front-end or other notifications of thesupplyCap
limit being reached. So the borrowers will know that only way left for them toavoid liquidation
would be torepay the full amount or portion of the borrowed amount
. Hence he will not attempt to deposit collateral (to avoid liquidation) and get front run by an attacker which would make him vulnerable to liquidation.Assessed type
Other