Description:
Impact: High
Likelihood: Low
The MysteryBox::claimAllRewards()
function is vulnerable to DoS, since no parameters are set of any minimum amount of players before rewards can be redeemed. Should any player draft a SilverCoin
or especially a GoldCoin
during the initial phase of mystery box the contract is not able to pay the reward.
Vulnerable Code:
Impact:
Users of the protocol might not be able to withdraw their rewards for an unknown amount of time.
Tools Used:
Manual Review, ChatGPT for the math
Proof of Concept:
Understanding the Scenario:
10 players participate in the game.
Each player pays 0.1 ETH to join.
The total collected funds are 10 * 0.1 ETH = 1 ETH.
The win probabilities are:
75% chance of winning nothing
20% chance of winning 0.1 ETH
4% chance of winning 0.5 ETH
1% chance of winning 1 ETH
Calculating Expected Winnings per Player:
Expected winnings = (0.75 * 0) + (0.20 * 0.1) + (0.04 * 0.5) + (0.01 * 1)
Expected winnings = 0 + 0.02 + 0.02 + 0.01
Expected winnings = 0.05 ETH
Calculating Total Prize Pool:
Total prize pool = 0.05 ETH/player * 10 players
Total prize pool = 0.5 ETH
Assessing the Risk of Insufficient Funds:
Difference: 1 ETH (collected funds) - 0.5 ETH (expected prize pool) = 0.5 ETH
With this payout structure, the probability that the game will not be able to pay out the rewards (i.e., the total payout exceeds the 1 ETH collected) is approximately 13.47%. (Thanks, ChatGPT)
Additionally the following test shows such a scenario. The First user buying a mystery box found a silver coin worth 0.5 ether. The user could obviously not redeem his reward.
Used Parameters for this Test in foundry.toml:
Conclusion:
With the win probabilities, the expected total prize pool is now 0.5 ETH, which is exactly equal to the total collected funds. This means that the game is theoretically balanced in terms of expected payouts. However, it's important to note that:
Randomness: The actual outcomes of the game can vary significantly from the expected values due to randomness. There's still a possibility of the prize pool exceeding the collected funds in a particular round.
Large Deviations: While the expected prize pool is 0.5 ETH, there's a chance of rare events where the actual prize pool is much higher or lower than expected.
Recommended Mitigation:
Set an initial deposit of 0.5 ETH or better 1 ETH into the contract to cover this edge cases.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.