Skip to content
Business logic Audit finding Intermediate

Interest component of underlying amount is not withdrawable using the `withdrawLend` function. Such amount is permanently locked in the BlueBerryBank contract

The withdrawLend function caps the withdrawable amount to the user's initial deposit, so when a user burns all vault shares, the accrued interest remains locked in the contract. An attacker could not directly exploit this, but users permanently lose access to their interest.

berndartmueller Follow with carrot, minhtrng and 11 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-blueberry-judging/issues/109

Found by

berndartmueller, carrot, minhtrng, 0Kage, Jeiwan, chaduke, koxuan, Ruhum, cergyk, rbserver, stent, saian, XKET, GimelSec

Summary

Soft vault shares are issued against interest bearing tokens issued by Compound protocol in exchange for underlying deposits. However, withdrawLend function caps the withdrawable amount to initial underlying deposited by user (pos.underlyingAmount). Capping underlying amount to initial underlying deposited would mean that a user can burn all his vault shares in withdrawLend function and only receive original underlying deposited.

Interest accrued component received from Soft vault (that rightfully belongs to the user) is no longer retrievable because the underlying vault shares are already burnt. Loss to the users is permanent as such interest amount sits permanently locked in Blueberry bank.

Vulnerability Detail

withdrawLend function in BlueBerryBank allows users to withdraw underlying amount from Hard or Soft vaults. Soft vault shares are backed by interest bearing cTokens issued by Compound Protocol

User can request underlying by specifying shareAmount. When user tries to send the maximum shareAmount to withdraw all the lent amount, notice that the amount withdrawable is limited to the pos.underlyingAmount (original deposit made by the user).

While this is the case, notice also that the full shareAmount is deducted from underlyingVaultShare. User cannot recover remaining funds because in the next call, user doesn't have any vault shares against his address. Interest accrued component on the underlying that was returned by SoftVault to BlueberryBank never makes it back to the original lender.

Solidity
    wAmount = wAmount > pos.underlyingAmount
            ? pos.underlyingAmount
            : wAmount;

        pos.underlyingVaultShare -= shareAmount;
        pos.underlyingAmount -= wAmount;
        bank.totalLend -= wAmount;

Impact

Every time, user withdraws underlying from a Soft vault, interest component gets trapped in BlueBerry contract. Here is a scenario.

  • Alice deposits 1000 USDC into SoftVault using the lend function of BlueberryBank at T=0
  • USDC soft vault mints 1000 shares to Blueberry bank
  • USDC soft vault deposits 1000 USDC into Compound & receives 1000 cUSDC
  • Alice at T=60 days requests withdrawal against 1000 Soft vault shares
  • Soft Vault burns 1000 soft vault shares and requests withdrawal from Compound against 1000 cTokens
  • Soft vault receives 1050 USDC (50 USDC interest) and sends this to BlueberryBank
  • Blueberry Bank caps the withdrawal amount to 1000 (original deposit)
  • Blueberry Bank deducts 0.5% withdrawal fees and deposits 995 USDC back to user

In the whole process, Alice has lost access to 50 USDC.

Code Snippet

https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L693

Tool used

Manual Review

Recommendation

Introduced a new variable to adjust positions & removed cap on withdraw amount.

Highlighted changes I recommend to withdrawLend with //******//.

Solidity
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);
        
        //*********-audit cap shareAmount to maximum value, pos.underlyingVaultShare*******
        if (shareAmount > pos.underlyingVaultShare) {
            shareAmount = pos.underlyingVaultShare;
        }

        // if (shareAmount == type(uint256).max) {
        //     shareAmount = pos.underlyingVaultShare;
        // }        

        uint256 wAmount;
        uint256 amountToOffset; //*********- audit added this to adjust position********
        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);
        }

        //*********- audit calculate amountToOffset********
        //*********-audit not capping wAmount anymore*******
        amountToOffset = wAmount > pos.underlyingAmount
            ? pos.underlyingAmount
            : wAmount;

        pos.underlyingVaultShare -= shareAmount;
     //*********-audit subtract amountToOffset instead of wAmount*******
        pos.underlyingAmount -= amountToOffset;
        bank.totalLend -= amountToOffset;

        wAmount = doCutWithdrawFee(token, wAmount);

        IERC20Upgradeable(token).safeTransfer(msg.sender, wAmount);
    }

The original report as published on Sherlock, by berndartmueller. 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

Root cause

The withdrawLend function limits the withdrawal amount to the original deposit (pos.underlyingAmount) while deducting the full share amount, so any interest earned is left in the contract with no shares left to claim it.

Impact

Every time a user withdraws from a Soft vault, the interest component gets trapped in the BlueBerry contract, causing a permanent loss to the user.

What the attacker needed

User has deposited into a Soft vault; Interest has accrued on the deposit; User withdraws all shares

The fix

The withdrawLend function should be modified to remove the cap on the withdrawal amount and adjust the position accordingly, as shown in the recommendation.

How it was found

  1. Alice deposits 1000 USDC into SoftVault using the lend function.
  2. SoftVault mints 1000 shares to BlueberryBank and deposits 1000 USDC into Compound, receiving 1000 cUSDC.
  3. After 60 days, Alice requests withdrawal against 1000 Soft vault shares.
  4. SoftVault burns 1000 shares, withdraws from Compound, receives 1050 USDC (including 50 USDC interest), and sends it to BlueberryBank.
  5. BlueberryBank caps the withdrawal to 1000 USDC (original deposit), deducts fees, and returns 995 USDC to Alice.
  6. The 50 USDC interest remains locked in BlueberryBank and Alice cannot retrieve it because her shares are burned.

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.

When you deposit money into a savings-like contract, it earns interest over time. This report says that if you try to withdraw everything at once, the contract only gives back your original deposit and keeps the interest, and because your shares are burned, you cannot get that interest later. So the interest is stuck forever.

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 berndartmueller

View all

97 more disclosed reports, best first.

More from Blueberry Update #3

View all

The newest disclosed reports for this program.

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.