claimPrizesForRound transfers the entire amount deposited for a prize regardless of the number of winners
The claimPrizesForRound function transfers the entire prize amount to the first caller, ignoring the number of winners, so later winners cannot claim their share. This can deny winnings to other winners or cause the transaction to revert if funds are insufficient.
EV_om Follow with 0xDING99YA and oakcobalt
Originally disclosed on Code4rena
Submitted by EV_om, also found by 0xDING99YA and oakcobalt
claimPrizesForRound() transfers the entire amount of a prize to a winner without considering the total number of winners for that prize.
The prize for a given round and prize index can be set by calling the setPrize() function, which pulls the amounts from the caller (the owner) and stores the prize data in the prizes array:
ThrusterTreasure.sol#L163-L184
function setPrize(uint256 _round, uint64 _prizeIndex, uint256 _amountWETH, uint256 _amountUSDB, uint64 _numWinners)
external
onlyOwner
{
require(_round >= currentRound, "ICR");
require(_prizeIndex < maxPrizeCount, "IPC");
depositPrize(msg.sender, _amountWETH, _amountUSDB);
prizes[_round][_prizeIndex] = Prize(_amountWETH, _amountUSDB, _numWinners, _prizeIndex, uint64(_round));
}
function depositPrize(address _from, uint256 _amountWETH, uint256 _amountUSDB) internal {
WETH.transferFrom(_from, address(this), _amountWETH);
USDB.transferFrom(_from, address(this), _amountUSDB);
emit DepositedPrizes(_amountWETH, _amountUSDB);
}
However, the claimPrizesForRound() function always transfers the full prize amounts to the first caller, regardless of the number of winners for the prize. Once the prize for a specific index is claimed, other winners of that prize cannot claim their share (or winners of other prizes may end up not being able to claim theirs), effectively being denied their winnings:
ThrusterTreasure.sol#L102-L134
function claimPrizesForRound(uint256 roundToClaim) external {
...
for (uint256 i = 0; i < maxPrizeCount_; i++) {
Prize memory prize = prizes[roundToClaim][i];
uint256[] memory winningTicketsRoundPrize = winningTickets[roundToClaim][i];
for (uint256 j = 0; j < winningTicketsRoundPrize.length; j++) {
uint256 winningTicket = winningTicketsRoundPrize[j];
if (round.ticketStart <= winningTicket && round.ticketEnd > winningTicket) {
_claimPrize(prize, msg.sender, winningTicket);
}
}
}
...
}
function _claimPrize(Prize memory _prize, address _receiver, uint256 _winningTicket) internal {
uint256 amountETH = _prize.amountWETH;
uint256 amountUSDB = _prize.amountUSDB;
WETH.transfer(_receiver, amountETH);
USDB.transfer(_receiver, amountUSDB);
emit ClaimedPrize(_receiver, _prize.round, _prize.prizeIndex, amountETH, amountUSDB, _winningTicket);
}
This approach can lead to scenarios where the amount available to be distributed among prize winners is less than that represented by the prizes stored in the prizes array.
This is considered medium severity because:
claimPrizesForRound()will revert if there aren’t enough funds to transfer the prize to the winner, altering the user- the owner can mitigate this by simply “refilling” the prize as many times as needed
Proof of Concept
- A prize is set with a certain amount of WETH and USDB for a specific round and prize index, intended for multiple winners.
- Multiple users enter the round with tickets that end up winning this prize.
- The first user to call
claimPrizesForRound()for this round and prize index successfully claims the entire prize amount. - Subsequent winners attempting to claim their share of the prize for the same round and prize index find that they cannot, as the prize has already been fully distributed to the first caller.
Recommended Mitigation Steps
It is unclear whether the amounts passed to setPrize() are meant to be distributed among all winners of the given prize or to be paid out to each winner, but the cleaner approach would be the latter. In that case, the amount pulled from the owner can simply be scaled by the number of winners:
function depositPrize(address _from, uint64 _numWinners, uint256 _amountWETH, uint256 _amountUSDB) internal {
WETH.transferFrom(_from, address(this), _amountWETH * _numWinners);
USDB.transferFrom(_from, address(this), _amountUSDB * _numWinners);
emit DepositedPrizes(_numWinners, _amountWETH, _amountUSDB);
}
jooleseth (Thruster) confirmed and commented:
I agree with the Warden’s evaluation.
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 claim function transfers the full prize amount per winning ticket without dividing by the number of winners or tracking how much each winner should receive.
Impact
Other winners may be denied their winnings, and claims could revert if the contract lacks sufficient funds, though the owner can mitigate by refilling the prize.
What the attacker needed
A prize set for multiple winners; multiple winning tickets for that prize; at least one winner claims first
The fix
The amount pulled from the owner should be scaled by the number of winners so that each winner receives the intended amount.
How it was found
- A prize is set with a certain amount of WETH and USDB for a specific round and prize index, intended for multiple winners.
- Multiple users enter the round with tickets that end up winning this prize.
- The first user to call claimPrizesForRound() for this round and prize index successfully claims the entire prize amount.
- Subsequent winners attempting to claim their share of the prize for the same round and prize index find that they cannot, as the prize has already been fully distributed to the first caller.
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 smart contract, a prize pool might be set up for multiple winners. This bug means the first person to claim takes the whole prize, leaving nothing for the others. That is unfair and can block later winners from getting their reward.
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.