High Stakes Roulette on Ethereum

At the core of the contract will be a commitment scheme. If you want to learn more about randomness on the blockchain, check out my previous tutorial here. But in summary, there is no good direct source for randomness in the blockchain, since all code has to run deterministically.

Solution for low stakes: Using a future block hash is a possible solution, but miners have some influence on this value. They can choose to not publish a new block, foregoing the block reward. But if they are meanwhile playing a very high stakes game of Roulette, withholding a block might be the better strategy for them.

Solution for high stakes: So for a high stakes setup we need a better randomness generator. Luckily in a setup with two participants (bank and player), we can use the commitment scheme. Each player commits to secret random number by first sending the keccak256 commitment hash of that number. Once both hashes are in the contract, players can securely reveal the actual random number. The contract verifies that keccak256(randomNumber) == commitment hash, ensuring both parties cannot change the random number anymore. The final random number will be randomNumberBank XOR randomNumberPlayer. More details about this are explained in the linked tutorial above.

Latest posts