How do commit and reveal schemes lock a spin in on-chain roulette?

by Erin Imogen

A commit and reveal scheme locks a spin by having each side publish a hash of a secret before the bet, then publish the secret itself after, so that neither side can change its input once the other side’s input is known. The winning pocket is computed from both secrets together. The house cannot pick a pocket because it does not know the player’s secret when it commits, and the player cannot pick one because the house’s secret is already committed. It needs no oracle and costs three transactions per spin.

The three phases below show what each side does and what the chain records. Reviews of the best crypto roulette sites that run on-chain usually note which draw method a table uses.

Phase one – Commit

  • House – Generates a random secret for the next spin, hashes it, and publishes the hash by calling the contract’s commit function. The hash is stored against a round number. The secret stays off-chain. Many contracts keep a queue of committed hashes ready.
  • Player – Reads the current round’s house hash from the contract, generates a secret of their own, and calls the bet function with the stake, the chosen pocket and the hash of their secret. The contract records all three. At this moment, both hashes are on-chain, and neither secret is.

Phase two – Reveal

  • Player – Calls the reveal function with the secret. The contract hashes it, compares the result with the hash stored at bet time, and rejects the reveal if they differ. A matching secret is stored.
  • House – Calls its own reveal function with its secret for that round. The contract performs the same check against the house hash committed in phase one. A matching secret is stored.

Phase three – Settle

  • Contract – Combines the two revealed secrets, usually by hashing them together, and reduces the result to a pocket from 0 to 36. It compares the pocket with the player’s bet and pays out or keeps the stake. Anyone can recompute the pocket from the two secrets now visible on-chain.

The scheme is only as safe as its timeouts, because either side could refuse to reveal after seeing that the round would go against it. Three rules close that gap:

  • House fails to reveal – If the house has not revealed within a set number of blocks after the player’s reveal, the contract treats the round as a player win and pays the bet’s maximum payout. A house that withholds a losing secret loses more than it would have by revealing.
  • Player fails to reveal – If the player has not revealed within the window, the contract treats the round as a loss, and the stake goes to the house. A player cannot avoid a losing round by walking away.
  • Both reveal late – The contract uses the first reveal’s block as the start of the window for the second, so that neither side can wait for the other indefinitely.

Compared with a VRF draw, commit and reveal needs one more transaction from the player and trusts the timeouts rather than proof. In return, it has no dependence on any service outside the chain, and every input to the pocket is visible on the explorer once the round is settled.

Related Articles