`BlueBerryBank.withdrawLend` function cannot be paused
The BlueBerryBank contract lacks a pause check for the withdrawLend function, so users can still reduce positions via IchiVaultSpell.reducePosition even when the protocol intends to pause such actions. This could allow funds to flow out during an emergency when the protocol needs to stop position reductions.
Source: https://github.com/sherlock-audit/2023-02-blueberry-judging/issues/204
Found by
rbserver
Summary
When an extreme market condition occurs, the protocol faces an exploit, or the authority issues a legal requirement, the protocol is able to pause the lending, borrowing, and repaying functionalities. However, the protocol is unable to pause the functionality for reducing a position.
Vulnerability Detail
Because the BlueBerryBank contract does not have a function, which is like BlueBerryBank.isBorrowAllowed, BlueBerryBank.isRepayAllowed, and BlueBerryBank.isLendAllowed, for pausing the functionality for reducing a position, the BlueBerryBank.withdrawLend function, which is shown in the Code Snippet section, cannot be paused. Users can still call the IchiVaultSpell.reducePosition function that further calls the BlueBerryBank.withdrawLend function to reduce a position when there is a need for pausing this functionality.
Impact
Just like pausing the lending, borrowing, and repaying functionalities, it is possible that the protocol needs to pause the functionality for reducing a position. However, when this need occurs, users can still reduce their positions through calling the IchiVaultSpell.reducePosition and BlueBerryBank.withdrawLend functions. The protocol cannot stop the outflow of the funds due to these position reductions even it is required to do so in this situation.
Code Snippet
function reducePosition(
uint256 strategyId,
address collToken,
uint256 collAmount
) external {
doWithdraw(collToken, collAmount);
doRefund(collToken);
_validateMaxLTV(strategyId);
}
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L669-L704
function withdrawLend(address token, uint256 shareAmount)
external
override
inExec
poke(token)
{
Position storage pos = positions[POSITION_ID];
Bank storage bank = banks[token];
if (token != pos.underlyingToken) revert INVALID_UTOKEN(token);
if (shareAmount == type(uint256).max) {
shareAmount = pos.underlyingVaultShare;
}
uint256 wAmount;
if (address(ISoftVault(bank.softVault).uToken()) == token) {
ISoftVault(bank.softVault).approve(
bank.softVault,
type(uint256).max
);
wAmount = ISoftVault(bank.softVault).withdraw(shareAmount);
} else {
wAmount = IHardVault(bank.hardVault).withdraw(token, shareAmount);
}
wAmount = wAmount > pos.underlyingAmount
? pos.underlyingAmount
: wAmount;
pos.underlyingVaultShare -= shareAmount;
pos.underlyingAmount -= wAmount;
bank.totalLend -= wAmount;
wAmount = doCutWithdrawFee(token, wAmount);
IERC20Upgradeable(token).safeTransfer(msg.sender, wAmount);
}
Tool used
Manual Review
Recommendation
A function, which is similar to the BlueBerryBank.isBorrowAllowed, BlueBerryBank.isRepayAllowed, and BlueBerryBank.isLendAllowed functions, can be added in the BlueBerryBank contract for pausing the BlueBerryBank.withdrawLend function. This function can then be used in the BlueBerryBank.withdrawLend function so the BlueBerryBank.withdrawLend function can be paused when needed.
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 withdrawLend function lacks a pause check similar to those in isBorrowAllowed, isRepayAllowed, and isLendAllowed, so it remains callable when the protocol is paused.
Impact
The protocol cannot stop the outflow of funds from position reductions even when it is required to do so.
What the attacker needed
Protocol must be in a paused state; user must have a position to reduce
The fix
A pause check similar to isBorrowAllowed, isRepayAllowed, and isLendAllowed should be added to withdrawLend so it can be paused when needed.
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 can have a pause feature to stop certain actions in an emergency. Here, the team can pause lending, borrowing, and repaying, but not the action of reducing a position. So even when they want to stop all money from leaving, users can still withdraw their lent funds.
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.