A malicious actor can create a contract to act as Player A with a gas-intensive fallback function that consumes nearly all available gas when receiving ETH. This can prevent Player B from successfully completing critical game actions that involve ETH transfers to Player A, potentially forcing Player B to lose by timeout.
The RockPaperScissors contract uses low-level call
to transfer ETH in several functions:
When ETH is transferred to an address, if that address is a contract, its fallback function (receive()
or fallback()
) is executed. A malicious contract can implement a gas-intensive fallback function that consumes nearly all available gas, causing subsequent operations to fail due to out-of-gas errors.
A malicious Player A could deploy a contract like this:
This vulnerability can be exploited in several scenarios:
Forced Timeout: Player A (malicious contract) commits and reveals their move, but when Player B tries to reveal their move, the transaction fails due to out-of-gas when _determineWinner
is called and attempts to transfer ETH to Player A. Player B cannot complete their reveal before the deadline, allowing Player A to claim a win by timeout.
Blocked Timeout Claims: If Player B attempts to call timeoutReveal()
when Player A has revealed but Player B hasn't, the function would try to send ETH to Player A, triggering the gas-consuming fallback function and causing the transaction to fail.
Prevented Game Cancellation: If Player B attempts to join a game and then Player A tries to cancel it, the _cancelGame()
function would fail when trying to refund Player B, potentially locking funds.
This is a high severity issue because it can lead to direct fund loss for Player B through manipulation of the game mechanics, effectively allowing Player A to steal Player B's bet.
Manual code review
Analysis of gas consumption patterns
Smart contract interaction simulation
Implement one of the following solutions:
Use the Pull Pattern Instead of Push: Instead of directly sending ETH to winners, implement a withdrawal pattern where players can claim their winnings:
Set a Gas Limit for ETH Transfers: If you must use direct transfers, set a gas limit to prevent malicious contracts from consuming all gas:
Code suggestions or observations that do not pose a direct security risk.
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.