# Curated Vault allocators cannot `reallocate()` a pool to zero due to attempting to withdraw 0 tokens from the underlying pool

Curated Vault allocators cannot reallocate a pool to zero because the code sets withdrawal amount to 0, causing a revert in the underlying pool's withdraw validation.

- Payout: Audit contest
- Severity: medium
- Program: New Scope
- Found by: 000000
- Disclosed: 2024-06-27
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-06-new-scope-judging/issues/434
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-13
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:business-logic

**Target:** CuratedVault::reallocate function
**Root cause:** When allocation.assets is 0, the code sets toWithdraw to 0 instead of supplyAssets, then calls pool.withdrawSimple with 0, which reverts because the pool requires amount > 0.
**Steps:**
1. Set up a curated vault with >1 pool in supplyQueue.
2. Supplier deposits assets into the vault.
3. Allocator calls `reallocate` with allocations[0] = {market: pool0, assets: 0} and allocations[1] = {market: pool1, assets: assets}.
4. Transaction reverts with 'NOT_ENOUGH_AVAILABLE_USER_BALANCE' due to zero withdrawal attempt.
**How found:** Code review of the forked MetaMorpho logic; noticed that setting toWithdraw to 0 when allocation.assets == 0 conflicts with ZeroLend's withdrawSimple which only accepts asset amounts and requires >0.
**Insight:** When forking code, verify that underlying function signatures and validation logic match; a safety check from the original may become a bug if the underlying implementation differs.

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

**PoC test reallocating pool to zero reverts**

```
contract POC_AllocatorCannotReallocateToZero is IntegrationVaultTest {
  function setUp() public {
    _setUpVault();
    _setCap(allMarkets[0], CAP);
    _sortSupplyQueueIdleLast();

    oracleB.updateRoundTimestamp();
    oracle.updateRoundTimestamp();
  }

  function test_POC_AllocatorCannotReallocateToZero() public {

    // 1. supplier supplies to underlying pool through curated vault
    uint256 assets = 10e18;
    loanToken.mint(supplier, assets);

    vm.startPrank(supplier);
    uint256 shares = vault.deposit(assets, onBehalf);
    vm.stopPrank();

    // 2. Allocator attempts to reallocate all of these funds to another pool
    MarketAllocation[] memory allocations = new MarketAllocation[](2);
    
    allocations[0] = MarketAllocation({
        market: vault.supplyQueue(0),
        assets: 0
    });

    // Fill in the second MarketAllocation struct
    allocations[1] = MarketAllocation({
        market: vault.supplyQueue(1),
        assets: assets
    });

    vm.startPrank(allocator);
    vm.expectRevert("NOT_ENOUGH_AVAILABLE_USER_BALANCE");
    vault.reallocate(allocations); // Reverts due to attempting a withdrawal amount of 0
```

