# YearnV2YieldSource wrong subtraction in withdraw

YearnV2YieldSource withdraw subtracts currentBalance from previousBalance, underflowing and reverting all vault withdrawals, locking user funds.

- Payout: Audit contest
- Severity: high
- Program: PoolTogether
- Found by: cmichel
- Disclosed: 2021-09-16
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2021-06-pooltogether-findings/issues/90
- Library page: https://bugbountylibrary.com/r/c4%3A2021-06-pooltogether%3AH-02
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** YearnV2YieldSource Solidity contract withdraw function
**Root cause:** After vault.withdraw increases the token balance, the code returns previousBalance.sub(currentBalance), reversing the operands so the subtraction underflows and reverts.
**Steps:**
1. Call withdraw on YearnV2YieldSource, which computes yShares = _tokenToYShares(amount).
2. Record previousBalance = token.balanceOf(address(this)).
3. Call vault.withdraw(yShares, address(this), maxLosses) (or vault.withdraw(yShares)), increasing token balance.
4. Record currentBalance = token.balanceOf(address(this)).
5. Return previousBalance.sub(currentBalance); since previousBalance < currentBalance, SafeMath underflow reverts the whole withdrawal.
**How found:** Code review of the withdraw accounting: noticed the token balance should increase after redeeming yTokens, making the previousBalance.sub(currentBalance) direction obviously inverted.
**Exploitation:** Not an attack; any user withdrawal reverts due to the underflow, permanently blocking redemption of deposited funds until patched.
**Insight:** In yield-source wrappers, verify the sign/direction of balance-delta accounting after external vault calls; a reversed subtraction in a SafeMath return bricks all withdrawals.

