The protocol allows borrowing small positions that can create bad debt
The protocol lacks a minimum borrowing amount and a minimum withdrawal amount, allowing users to create small positions that are not worth liquidating. This can leave bad debt to the protocol because liquidators have no incentive to liquidate small positions.
serial-coder Follow with serial-coder and SBSecurity
Originally disclosed on Code4rena
Submitted by serial-coder, also found by serial-coder and SBSecurity
The WiseLending protocol allows users to borrow small positions. Even if the protocol has a minimum deposit (collateral) amount check to mitigate the small borrowing position from creating bad debt, this protection can be bypassed.
With a small borrowing position, there is no incentive for a liquidator to liquidate the position, as the liquidation profit may not cover the liquidation cost (gas). As a result, small liquidable positions will not be liquidated, leaving bad debt to the protocol.
Proof of Concept
The protocol allows users to borrow small positions since no minimum borrowing amount is checked in the WiseSecurity::checksBorrow().
// FILE: https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/WiseSecurity/WiseSecurity.sol
function checksBorrow(
uint256 _nftId,
address _caller,
address _poolToken
)
external
view
returns (bool specialCase) //@audit -- No minimum borrowing amount check
{
_checkPoolCondition(
_poolToken
);
checkTokenAllowed(
_poolToken
);
if (WISE_LENDING.verifiedIsolationPool(_caller) == true) {
return true;
}
if (WISE_LENDING.positionLocked(_nftId) == true) {
return true;
}
}
No minimum borrowing amount check.
Even if the protocol has a minimum deposit (collateral) amount check in the WiseCore::_checkDeposit() to mitigate the small borrowing position from creating bad debt, this protection can be easily bypassed.
The WiseCore::_checkMinDepositValue() is a core function that checks a minimum deposit (collateral) amount. By default, this deposit amount check would be overridden (disabled). Even though this deposit amount check will be enabled, this protection can be bypassed by withdrawing the deposited fund later, since there is no minimum withdrawal amount check in the WiseSecurity::checksWithdraw().
// FILE: https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/WiseCore.sol
function _checkDeposit(
uint256 _nftId,
address _caller,
address _poolToken,
uint256 _amount
)
internal
view
{
if (WISE_ORACLE.chainLinkIsDead(_poolToken) == true) {
revert DeadOracle();
}
_checkAllowDeposit(
_nftId,
_caller
);
_checkPositionLocked(
_nftId,
_caller
);
@1 WISE_SECURITY.checkPoolWithMinDeposit( //@audit -- Even if there is a minimum deposit amount check, this protection can be bypassed
@1 _poolToken,
@1 _amount
@1 );
_checkMaxDepositValue(
_poolToken,
_amount
);
}
// FILE: https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/WiseSecurity/WiseSecurity.sol
function _checkMinDepositValue(
address _token,
uint256 _amount
)
private
view
returns (bool)
{
@2 if (minDepositEthValue == ONE_WEI) { //@audit -- By default, the minimum deposit amount check would be overridden (disabled)
@2 return true;
@2 }
@3 if (_getTokensInEth(_token, _amount) < minDepositEthValue) { //@audit -- Even though the minimum deposit amount check will be enabled, this protection can be bypassed by withdrawing the deposited fund later
@3 revert DepositAmountTooSmall();
@3 }
return true;
}
@1 -- Even if there is a minimum deposit amount check, this protection can be bypassed: see here.
@2 -- By default, the minimum deposit amount check would be overridden (disabled): see here.
@3 -- Even though the minimum deposit amount check will be enabled, this protection can be bypassed by withdrawing the deposited fund later: see here.
As you can see, there is no minimum withdrawal amount check in the WiseSecurity::checksWithdraw(). Hence, a user can deposit collateral at or above the minimum deposit amount (i.e., minDepositEthValue) and then withdraw the deposited fund to be under the minDepositEthValue. Later, they can borrow a small amount with small collateral.
With a small borrowing position (and small collateral), there is no incentive for a liquidator to liquidate the position, as the liquidation profit may not cover the liquidation cost (gas). As a result, small liquidable positions will not be liquidated, leaving bad debt to the protocol.
// FILE: https://github.com/code-423n4/2024-02-wise-lending/blob/main/contracts/WiseSecurity/WiseSecurity.sol
function checksWithdraw(
uint256 _nftId,
address _caller,
address _poolToken
)
external
view
returns (bool specialCase) //@audit -- No minimum withdrawal amount check
{
if (_checkBlacklisted(_poolToken) == true) {
if (overallETHBorrowBare(_nftId) > 0) {
revert OpenBorrowPosition();
}
return true;
}
if (WISE_LENDING.verifiedIsolationPool(_caller) == true) {
return true;
}
if (WISE_LENDING.positionLocked(_nftId) == true) {
return true;
}
if (_isUncollateralized(_nftId, _poolToken) == true) {
return true;
}
if (WISE_LENDING.getPositionBorrowTokenLength(_nftId) == 0) {
return true;
}
}
No minimum withdrawal amount check.
Recommended Mitigation Steps
Implement the minimum borrowing amount check to limit the minimum size of borrowing positions.
vonMangoldt (Wise Lending) commented via duplicate issue #277:
Can also be circumvented by just paying back after borrowing. Doesn’t really add any value, in my opinion.
The bug class is valid, in my honest opinion; as either liquidator will liquidate at a loss or protocol will be losing money to protect from bad debt over time.
Mitigated here.
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
Root cause
Likely the absence of a minimum borrowing amount check and a minimum withdrawal amount check allows users to create positions too small to be profitably liquidated.
Impact
Small liquidable positions may not be liquidated, leaving bad debt to the protocol.
What the attacker needed
None
The fix
The protocol was mitigated by implementing a minimum borrowing amount check, according to the comment.
How it was found
- Deposit collateral at or above the minimum deposit amount.
- Withdraw the deposited fund to be under the minimum deposit amount.
- Borrow a small amount with small collateral.
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.
In a lending protocol, users deposit collateral and borrow assets. If the collateral value drops, liquidators repay the debt and seize collateral for a profit. This report says users can borrow tiny amounts, and the profit from liquidating such small positions is less than the gas cost, so no one liquidates them, leaving the protocol with bad debt.
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.