# withdraw() users may can't withdraw underlyingBorrowToken properly

Size's withdraw() applies the opening-limit collateral-ratio check even when withdrawing borrowed tokens, locking users' own borrowed funds after minor price moves.

- Payout: Audit contest
- Severity: medium
- Program: Size
- Found by: bin2chen
- Disclosed: 2024-09-16
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-06-size-findings/issues/88
- Library page: https://bugbountylibrary.com/r/c4%3A2024-06-size%3AM-10
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Size lending protocol withdraw() function
**Root cause:** withdraw() unconditionally calls validateUserIsNotBelowOpeningLimitBorrowCR after executeWithdraw, even when the withdrawn token is underlyingBorrowToken, which does not affect collateral ratio.
**Steps:**
1. User borrows underlyingBorrowToken against collateral, leaving borrowed tokens in Size.
2. Price of collateral drops slightly so collateralRatio falls below openingLimitBorrowCR but remains far above liquidation threshold.
3. User calls `withdraw({token: underlyingBorrowToken, amount, to})`.
4. executeWithdraw transfers via withdrawUnderlyingTokenFromVariablePool, then validateUserIsNotBelowOpeningLimitBorrowCR reverts, blocking withdrawal.
**How found:** Code reading of withdraw() flow: noticed the collateral-ratio validation runs for both token branches despite borrow-token withdrawal not changing collateralRatio.
**Insight:** When a shared validation runs after a branch that handles multiple token types, check whether the invariant it enforces actually applies to every branch; borrow-token withdrawals don't move collateral ratio.

## Proof of concept (copied exactly from the original report)

**withdraw() calls validateUserIsNotBelowOpeningLimitBorrowCR for borrow token**

```
function withdraw(WithdrawParams calldata params) external payable override(ISize) whenNotPaused {
        state.validateWithdraw(params);
        state.executeWithdraw(params);
@>      state.validateUserIsNotBelowOpeningLimitBorrowCR(msg.sender);
    }
```

**executeWithdraw withdraws underlying borrow token from variable pool**

```
if (params.token == address(state.data.underlyingBorrowToken)) {
            amount = Math.min(params.amount, state.data.borrowAToken.balanceOf(msg.sender));
            if (amount > 0) {
@>              state.withdrawUnderlyingTokenFromVariablePool(msg.sender, params.to, amount);
```

