The claimThrone function is intended to allow a new player to claim the throne by sending the required claim fee, updating the game state, and distributing a portion of the claim fee to the previous king as an incentive, as indicated by the comment: “If there’s a previous king, a small portion of the new claim fee is sent to them.” However, the code initializes previousKingPayout to 0 and never updates it, failing to implement the payout logic for the previous king.
Likelihood:
Occurs every time a new player claims the throne when there is an existing currentKing, as the previousKingPayout is always set to 0 and no funds are allocated to the previous king.
Affects all claims after the first in each game round, since the logic for rewarding the previous king is entirely absent.
Impact:
Breaks the intended game mechanic of rewarding the previous king, which could discourage players from participating if they expect a payout for their time as king.
Note: This POC cannot be executed with the current contract since the bug requires 2 kings and the first one to be dethroned in order to get the payout, but the primary claimThrone logic bug prevents anyone except the current king from claiming the throne. If you correct this line in Game.sol:
Then the test would work perfectly and prove the missing payout bug:
Alice claims first (works because Alice != address(0))
Bob claims from Alice (works because Bob != Alice)
Alice gets 0 payout (proves the bug - she should get some portion)
The test would pass and demonstrate that:
aliceWinningsBefore = 0
aliceWinningsAfter = 0
Alice received no compensation for being dethroned
All of Bob's 1.1 ether went to pot + platform fees instead of giving Alice her deserved cut
Introduce a configurable reward percentage for the dethroned king, and update the payout logic accordingly:
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.