Instantly share code, notes, and snippets.

Embed
What would you like to do?
Coinflip game hints

Your task:

  • Build a secure coinflip betting game between two players on Ethereum.

ONLY READ THIS DOCUMENT IF YOU WANT TO SPOIL BUILDING THE GAME. FIRST TRY TO BUILD IT YOURSELF, THEN SEE IF IT SURVIVES THE FOLLOWING ATTACKS.

.

.

.

.

.

.

.

.

.

.

.

.

  1. If you use the block timestamp as a source of randomness, that's directly manipulable by miners.

.

.

.

.

.

.

.

.

.

.

.

.

  1. If you use the block hash, an attacker who controls enough hashing power could withhold a mined block if the prize in the bet would make it worth it. There are non-miner-manipulable schemes you can use instead here.

.

.

.

.

.

.

.

.

.

.

.

.

  1. Commit-reveals!

.

.

.

.

.

.

.

.

.

.

.

.

  1. But if your commitments are too small, they're easy to brute-force. You have to ensure the commitments are sufficiently large, or have nonces appended.

.

.

.

.

.

.

.

.

.

.

.

.

  1. Can the second player withhold their reveal and stop the game? How can you avoid this?

.

.

.

.

.

.

.

.

.

.

.

.

  1. What if an adversary submits the same hash as the first player? How can they manipulate the outcome?

.

.

.

.

.

.

.

.

.

.

.

.

Long story short: creating a secure coinflip game is surprisingly nontrivial! See if you can build a solution that survives all of these attacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment