# BlueBerryBank#withdrawLend will cause underlying token accounting error if soft/hard vault has withdraw fee

BlueBerryBank.withdrawLend only subtracts the post-fee amount from pos.underlyingAmount, leaving phantom collateral usable to borrow against.

- Payout: Contest reward
- Severity: high
- Program: Blueberry
- Credited: y1cunhui
- Disclosed: 2023-02-01
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2023-02-blueberry-judging/issues/33
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-02-blueberry%3AH-9
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:fee-bypass

**Target:** BlueBerryBank.withdrawLend / SoftVault & HardVault withdraw accounting
**Root cause:** Vault withdraw returns the amount net of the withdraw fee, but withdrawLend subtracts only that net wAmount from pos.underlyingAmount instead of the full share value, so the fee portion remains as phantom collateral.
**Steps:**
1. Configure soft/hard vault with a nonzero withdraw fee (e.g. 5%) within withdrawVaultFeeWindow.
2. User deposits 100 underlying, receiving 100 shares (1:1).
3. User calls `withdrawLend(100 shares)`; vault burns shares and returns 95 after 5% fee.
4. Observe `pos.underlyingVaultShare` drops to 0 but `pos.underlyingAmount` remains 5.
5. `oracle.getUnderlyingValue(pos.underlyingToken, pos.underlyingAmount)` still counts the phantom 5 as collateral, enabling excess borrowing.
**How found:** Reviewer read the vault withdraw fee logic (withdrawAmount -= fee) and compared it to withdrawLend's accounting, noticing only the returned net amount is subtracted from pos.underlyingAmount.
**Exploitation:** Attacker deposits, then repeatedly withdraws through a fee-charging vault; each withdrawal leaves residual pos.underlyingAmount that is counted as collateral, letting them borrow more than their real deposit backs, extracting protocol funds.
**Escalation:** Repeating deposit/withdraw cycles accumulates phantom collateral, amplifying borrow capacity beyond real holdings.
**Insight:** When a vault/strategy returns a net amount after fees, check every caller that uses the return value for accounting; the fee delta must be reconciled or phantom balances persist and inflate collateral.
