# Method refundPlayers doesn't update _lockedETH in WinnableTicketManager

refundPlayers in WinnablesTicketManager fails to decrement _lockedETH, permanently locking protocol income from cancelled raffles in the contract.

- Payout: Audit contest
- Severity: high
- Program: Winnables Raffles
- Found by: 0x0bserver
- Disclosed: 2024-08-14
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-winnables-raffles-judging/issues/138
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-winnables-raffles%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

**Target:** WinnablesTicketManager.sol refundPlayers / _lockedETH accounting
**Root cause:** refundPlayers sends ETH back to players on a cancelled raffle but never subtracts the refunded amount from _lockedETH, so the locked counter overstates held funds.
**Steps:**
1. Start raffle; Alice buys 2 ETH tickets, _lockedETH=2; Bob buys 1 ETH, _lockedETH=3.
2. Raffle cancelled; both call `refundPlayers(raffleId, [addr])` — ETH returned but _lockedETH stays 3.
3. New raffle: Alice and Bob each stake 2 ETH; _lockedETH becomes 3+4=7.
4. Raffle completes; `propagateRaffleWinner()` subtracts 4, leaving _lockedETH=3.
5. Owner calls withdraw for 4 ETH income but reverts since _lockedETH=3; only 1 ETH withdrawable, 3 ETH stuck.
**How found:** Code review of refundPlayers vs withdraw accounting: noticed refund path sends ETH without decrementing _lockedETH, then traced how stale locked value blocks owner withdrawals after subsequent raffles.
**Insight:** Whenever a contract tracks a 'locked' balance separate from actual balance, audit every path that moves ETH out (refunds, cancellations, emergency withdrawals) for a matching decrement — refund paths are commonly missed.

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

**Test calling refundPlayers and logging locked ETH**

```
it('Should be able to refund tickets purchased', async () => {
  const contractBalanceBefore = await ethers.provider.getBalance(manager.address);
  const userBalanceBefore = await ethers.provider.getBalance(buyer2.address);
  let lockedETH = await manager.getLockedEth()
  console.log("Locked ETH is: ", lockedETH)
  const tx = await manager.refundPlayers(1, [buyer2.address]);
  lockedETH = await manager.getLockedEth()
  console.log("Locked ETH after player unlock is: ", lockedETH)
  const { events } = await tx.wait();
  expect(events).to.have.lengthOf(1);
  const [ event ] = events;
  expect(event.event).to.equal('PlayerRefund');
  const contractBalanceAfter = await ethers.provider.getBalance(manager.address);
  const userBalanceAfter = await ethers.provider.getBalance(buyer2.address);
  expect(contractBalanceAfter).to.eq(contractBalanceBefore.sub(100));
  expect(userBalanceAfter).to.eq(userBalanceBefore.add(100));
  const { withdrawn } = await manager.getParticipation(1, buyer2.address);
  expect(withdrawn).to.eq(true);
});
```

**Mitigation patch updating _lockedETH in refundPlayers**

```
function refundPlayers(uint256 raffleId, address[] calldata players) external {
    Raffle storage raffle = _raffles[raffleId];
    if (raffle.status != RaffleStatus.CANCELED) revert InvalidRaffle();
    for (uint256 i = 0; i < players.length; ) {
        address player = players[i];
        uint256 participation = uint256(raffle.participations[player]);
        if (((participation >> 160) & 1) == 1) revert PlayerAlreadyRefunded(player);
        raffle.participations[player] = bytes32(participation | (1 << 160));
        uint256 amountToSend = (participation & type(uint128).max);
        _lockedETH -= amountToSend;
        _sendETH(amountToSend, player);
        emit PlayerRefund(raffleId, player, bytes32(participation));
        unchecked { ++i; }
    }
}
```

