Skip to content
Business logic Audit finding Intermediate

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

The enterTickets function only checks if prize index 0 has been set, so users can still enter tickets after higher-index prizes have been distributed. Late entrants cannot win those already-distributed prizes, making their tickets worth less than early entrants' tickets.

EV_om Follow with oakcobalt and rvierdiiev

Originally disclosed on Code4rena

Submitted by EV_om, also found by 0xDING99YA (1, 2), oakcobalt, and rvierdiiev

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

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.

Recommended Mitigation Steps

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

jooleseth (Thruster) confirmed, but disagreed with severity and commented:

This is an issue reported in a few other Medium’s as well

  • Rewards should be set atomically in the same transaction call by an admin script. The expectation is that if the 0 index is set, then all should be set for the round, hence the check for the zero index.

We also use this zero index check in the claimPrizesForRound call.

I would consider this a Quality Assurance to improve the require check, or Medium at most, as reported by issue 17.

0xleastwood (judge) decreased severity to Low/Non-Critical and commented:

It seems to me that users would have to intentionally be negligible and enter tickets into a round that they are not eligible for. Downgrading to QA.

EV_om (warden) commented:

@0xleastwood - all users are eligible for prizes as long as they have valid tickets. The user cannot know that prizes have already been set - even if they checked before entering their tickets, an owner call to setWinningTickets() may end up being included in a block before their transaction.

Setting rewards atomically via a script addresses the issue, but it is an OOS mitigation. Considering that setting them non-atomically in both ascending and descending order is problematic and that this was not documented, Medium severity seems reasonable.

0xleastwood (judge) increased severity to Medium and commented:

Understandably, this issue would not be mitigated by having all prizes set at the same time because any tickets entered prior would not be eligible for any reward. There needs to be some clear distinction at which a round ends and when prizes are distributed to prevent this from happening. Would typically class front-running issues as QA but this leads to users spending funds with no expected return.


The original report as published on Code4rena, by EV_om. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the check for whether prizes have been set only looks at prize index 0, ignoring other indices that may have been set earlier.

Impact

Users who enter tickets after some prizes are distributed cannot win those prizes, so they may spend funds with no expected return for those prizes.

What the attacker needed

Multiple prizes in a round; prizes set non-atomically; user enters tickets after some prizes set

The fix

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

How it was found

  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.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In a lottery, tickets should all have the same chance to win every prize. Here, the contract only stops new tickets when the first prize is set, so if other prizes are set first, people can still buy tickets that cannot win those prizes. This means late buyers pay for tickets that are worth less than earlier ones.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by EV_om

View all

23 more disclosed reports, best first.

More from Thruster Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.