If player A or B is a contract and not an EOA, it can do something malicious (e.g. always revert) when it receives ETH, breaking the functionality of the system.
If player A or B is a contract that has a receive function that always revert when receiving ETH, _finishGame
, _handleTie
, _cancelGame
will always fail when dealing with games created with ETH.
In the case when the game was created by ETH, the game will not be able to properly finish and will always revert.
VSCode
We can mitigate this issue by using a pull pattern instead of a push pattern. This method prevents the whole system from crashing, letting the revert only happen in a totally seperate function rather than inside the core game logic.
First we make a seperate mapping storage,
And in _finishGame
update the storage when someone earns money,
Finally make a seperate withdraw function to withdraw funds,
Also, we can enhance security by adding a claim mechanism. For instance, implementing a function like claimFunds(address recipient) lets players transfer funds to a chosen address (e.g., a third party) instead of receiving ETH directly, reducing risks from malicious contracts.
Malicious player wins a game using a contract that intentionally reverts when receiving ETH, the entire transaction will fail
Malicious player wins a game using a contract that intentionally reverts when receiving ETH, the entire transaction will fail
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.