SmartContractSecurity / SWC-registry

Smart Contract Weakness Classification and Test Cases
https://swcregistry.io/
MIT License
850 stars 166 forks source link

SWC-136: odd_even_fixed.sol can be locked #258

Open ACaiSec opened 3 years ago

ACaiSec commented 3 years ago

If a player not call the reveal( ) function or he forgets the number or blindingFactor after calling the play( ) function to set the commitment. The OddEven contract of odd_even_fixed.sol would be locked. I don't know if this situation is within your consideration. The above questions are only raised by me as a beginner. Thx

ofirgeller commented 2 years ago

@little-petrol I think you are right, meaning

  1. loser can always tell they are the loser if they wait to reveal second (the number is a transaction parameter)
  2. loser can avoid change to the state after learning that they lost (they already know their number, and now the other party number)

The solution is not in the code but in "game theory", because the loser, being rational, will prefer to lose 1 eth and not 2. so it is better to get back the bond than to leave both the bond and the bet locked in the contract.

If you wanted to reduce the risk of a non rational actor you can add a public function that can only execute after some time has passed and which rewards all the balance to the non offending actor, however I think it is very elegant how you can get the losing party to cooperate post losing and not have to increase both contract and interaction complexity.