# Users buying too many tickets will DoS them and the protocol if they are the winner due to OOG

WinnablesTicket.ownerOf loops over all ticket IDs in a batch, so a winner holding ~4000+ tickets causes OOG in propagateWinner, locking raffle ETH.

- Payout: Audit contest
- Severity: medium
- Program: Winnables Raffles
- Found by: 0x73696d616f
- Disclosed: 2024-08-14
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-winnables-raffles-judging/issues/398
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-winnables-raffles%3AM-5
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:dos

**Target:** WinnablesTicket / WinnablesTicketManager Solidity contracts
**Root cause:** WinnablesTicket stores batch ownership only on the first minted NFT id; ownerOf() must loop from the batch start to the queried id, so gas cost scales linearly with batch size and can exceed the block gas limit.
**Steps:**
1. Admin sets maxTickets/maxHoldings high enough that a batch of ~4000+ tickets is allowed (README allows up to type(uint16).max per buyTickets call).
2. User buys a large batch via `WinnablesTicketManager::buyTickets()` with `ticketCount` up to 65535.
3. Draw proceeds: `drawWinner()` then Chainlink `fulfillRandomWords()` selects a winning ticket near the end of the batch.
4. `propagateWinner()` calls `WinnablesTicket::ownerOf(winnerTicketId)`, which loops over the batch and reverts OOG.
5. PoC: `winnablesTicket.mint(owner, 1, 4000); winnablesTicket.ownerOf(1, 3999);` consumes ~9M gas, above Avalanche block limit.
**How found:** Code reading of WinnablesTicket ownership storage: noticed only the first id of a batch records the owner, implying ownerOf must iterate; reasoned that gas cost grows with batch size and tested a 4000-ticket mint to measure ~9M gas.
**Exploitation:** Attacker (or any large buyer) purchases a large ticket batch; if the winning ticket falls late in that batch, propagateWinner reverts OOG, so the winner cannot be paid and the raffle cannot be canceled, locking the prize ETH.
**Insight:** When an ERC721-like contract stores ownership per-batch instead of per-token, any ownerOf/lookup that loops to resolve an id has gas linear in batch size; check whether user-controllable batch sizes can push that loop past the block gas limit in downstream settlement paths.

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

**Foundry PoC test causing ownerOf OOG**

```
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {WinnablesPrizeManager, LinkTokenInterface} from "contracts/WinnablesPrizeManager.sol";
import {WinnablesTicket} from "contracts/WinnablesTicket.sol";
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";

contract WinnablesPrizeManagerTest is Test {
    WinnablesPrizeManager public winnablesPrizeManager;
    WinnablesTicket public winnablesTicket;
    LinkTokenInterface public link;
    IRouterClient public router;
    address public owner;


    function setUp() public {
        vm.createSelectFork(vm.envString("ETHEREUM_RPC_URL"));
        link = LinkTokenInterface(0x514910771AF9Ca656af840dff83E8264EcF986CA);
        router = IRouterClient(0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D);
        owner = makeAddr("owner");

        vm.prank(owner);
        winnablesPrizeManager = new WinnablesPrizeManager(address(link), address(router));

        vm.prank(owner);
        winnablesTicket = new WinnablesTicket();
    }

    function test_POC_OwnerOfDos() public {
        vm.prank(owner);
        winnablesTicket.setRole(owner, 1, true);

        vm.prank(owner);
        winnablesTicket.mint(owner, 1, 4000);

        winnablesTicket.ownerOf(1, 3999);
    }
}
```

