The createGameWithToken
function in the Rock Paper Scissors contract allows players to create a game using an ERC20 WinningToken
. However, it performs a transferFrom
call without verifying that the contract has sufficient allowance to transfer the token on behalf of the user. This omission can result in transaction reverts, degrading user experience and potentially exposing denial-of-service behavior.
The vulnerable code is located in the createGameWithToken
and in the joinGameWithToken
function:
This line attempts to transfer a token from the caller (msg.sender
) to the contract without confirming that an allowance has been granted using approve
.
While the function checks that the user has at least 1 token via:
…it does not check if the WinningToken
contract's allowance for the RPS contract is sufficient:
If the allowance is insufficient or not set, the transaction will revert with ERC20: insufficient allowance
.
Denial of Service (DoS): Any user attempting to create a game without a prior approve()
call will have their transaction reverted. This can confuse users and block gameplay.
Poor UX: No clear error message or guidance on setting the allowance, resulting in failed transactions that users may not understand.
Silent Failures: Without an allowance check, it becomes difficult to debug or anticipate errors.
Manual code review
Add a check for sufficient allowance before calling transferFrom
:
Full fix:
createGameWithToken and joinGameWithToken functions will revert because they attempt transferFrom without requiring the user to first approve
createGameWithToken and joinGameWithToken functions will revert because they attempt transferFrom without requiring the user to first approve
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.