Rock Paper Scissors

First Flight #38
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: medium
Invalid

No fees for cancelled ETH games leading to the contract not making profit

Description: The _cancelGame function doesn't charge fees for any cancelled ETH games while the docs state that there should be "10% protocol fee on all ETH games".

function _cancelGame(uint256 _gameId) internal {
.
.
if (game.bet > 0) {
(bool successA,) = game.playerA.call{value: game.bet}("");
require(successA, "Transfer to player A failed");
if (game.playerB != address(0)) {
(bool successB,) = game.playerB.call{value: game.bet}("");
require(successB, "Transfer to player B failed");
}
}
.
.

Impact: The contract is missing on accumulating fee profits from all cancelled ETH games. When two users don't reveal their moves, the game gets cancelled but no fees are charged for that game.

Recommended Mitigation: Charge a 10% fee when cancelling a game and return the rest of the betted ETH to the player(s).

function _cancelGame(uint256 _gameId) internal {
Game storage game = games[_gameId];
game.state = GameState.Cancelled;
// Refund ETH to players
if (game.bet > 0) {
uint256 totalPot = game.bet * 2;
uint256 fee = (totalPot * PROTOCOL_FEE_PERCENT) / 100;
uint256 bettedETH = totalPot - fee;
accumulatedFees += fee;
emit FeeCollected(_gameId, fee);
(bool success,) = _winner.call{value: bettedETH/2}("");
require(success, "Transfer failed");
if (game.playerB == address(0)) {
uint256 returnedBet = bettedAmount;
(bool successA,) = game.playerA.call{value: returnedBet}("");
require(successA, "Returned transfer to player A failed");
} else {
uint256 returnedBet = bettedAmount / 2;
(bool successA,) = game.playerA.call{value: returnedBet}("");
require(successA, "Returned transfer to player A failed");
(bool successB,) = game.playerB.call{value: returnedBet}("");
require(successB, "Returned transfer to player B failed");
}
}
.
.
Updates

Appeal created

m3dython Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.