Light ModeLight
Light ModeDark

One Bug Per Day

One H/M every day from top Wardens

Checkmark

Join over 1145 wardens!

Checkmark

Receive the email at any hour!

Ad

Tickets can be entered after prizes for current round have partially been distributed

mediumCode4rena

Lines of code

https://github.com/code-423n4/2024-02-thruster/blob/3896779349f90a44b46f2646094cb34fffd7f66e/thruster-protocol/thruster-treasure/contracts/ThrusterTreasure.sol#L85

Vulnerability details

Impact

The ThrusterTreasure contract is designed to facilitate a lottery game where users can enter tickets to win prizes based on entropy. The contract includes mechanisms for entering tickets into rounds (enterTickets()), setting prizes for rounds (setPrize()), and claiming prizes (claimPrizesForRound()). A critical aspect of the game's integrity is ensuring each ticket has an equal chance to win every prize.

However, there is a significant flaw in enterTickets(). The function checks if winning tickets for the prize index 0 have been set by verifying that winningTickets[currentRound_][0].length == 0. This check is intended to prevent users from entering tickets after prizes have begun to be distributed, but it does not account for prizes with higher indices that may already have been distributed. As a result, users can still enter tickets after some prizes have been distributed, but these late-entered tickets will not have a chance to win the already distributed prizes: ThrusterTreasure.sol#L83-L96

solidity
function enterTickets(uint256 _amount, bytes32[] calldata _proof) external { ... require(winningTickets[currentRound_][0].length == 0, "ET"); ... }

Proof of Concept

  1. The contract owner sets up a new round with multiple prizes.
  2. User A enters tickets early in the round.
  3. The contract owner distributes prizes for index 1.
  4. User B enters tickets into the round.
  5. Due to the flawed logic in enterTickets(), User B's tickets are accepted, even though the prizes for indices 1 and above have already been distributed. User B's tickets, therefore, have no chance of winning those prizes and are worth less than user A's, but the system incorrectly allows their participation for the undistributed prize at index 0.

Tools Used

Manual review

Recommended Mitigation Steps

Freeze ticket entry for the current round once any prize has been set.

Assessed type

Other