Coin flip guide
Diamond Coin Flip: checking a toss from its hash
Diamond is a label left on this URL from an earlier version of the site. It means nothing about the game. This page shows, step by step, how a hash-based coin toss can be verified by anyone.
Why a hash helps
An online coin toss has no physical coin. The result comes from a number. If the service picked that number after seeing your call, it could pick against you. Commit-reveal schemes stop this. Before play, the service publishes the SHA-256 hash of a secret server seed. After play it reveals the seed. Because nobody can find a different seed with the same hash, the published hash pins the service to one seed in advance.
One toss in full
| Server seed (revealed later) | diamond-srv-91c2-flip |
|---|---|
| Commitment shown before play: SHA-256(server seed) | 89b43430bc6e2609d2bd5671201869dedbeb1c6cb32876caab8711776b7054b2 |
| Client seed : nonce : round | diamond-viewer-seed:7:0 |
| HMAC-SHA256(server seed, message) | d24368ee24bdf98d6040b3e537818fc15f330df5c0c744643464c40f325bbbd7 |
| First 4 bytes (8 hex digits) | d24368ee = 3,527,633,134 |
| Float = value / 2^32 | 0.8213410932 |
| Coin: float < 0.5 is heads | tails |
One common construction, shown for teaching. Real services document their own message format; check theirs before verifying.
The steps are: hash the revealed seed and compare it with the commitment; build the message from your client seed, the nonce and a round counter; compute HMAC-SHA256 with the server seed as the key; take the first eight hex digits; divide by 2^32 to get a number between 0 and 1; call it heads if it is below 0.5.
Eight tosses from one seed pair
The nonce counts bets. Each new bet raises it by one, so the same seeds produce a fresh result every time. The table repeats the method for nonces 7 to 14.
| Nonce | First 8 hex digits | Float | Result |
|---|---|---|---|
| 7 | d24368ee | 0.821341 | tails |
| 8 | 831665ec | 0.512061 | tails |
| 9 | 7f519fb6 | 0.497339 | heads |
| 10 | d1645281 | 0.817937 | tails |
| 11 | 1a3da373 | 0.102503 | heads |
| 12 | 432cd0c7 | 0.262403 | heads |
| 13 | 072d1610 | 0.028032 | heads |
| 14 | 59afae9d | 0.350337 | heads |
Computed with Python's hmac and hashlib. One common construction, shown for teaching.
Do it yourself
- Copy the revealed server seed and run SHA-256 on it. The output must match the commitment shown before play.
- Write the message exactly as the service documents it, for example client seed, colon, nonce, colon, round.
- Compute HMAC-SHA256 of that message keyed with the server seed.
- Convert the first 8 hex digits to an integer and divide by 4,294,967,296.
- Apply the documented rule, here below 0.5 is heads.
If any step gives a different answer from the result you were shown, the toss was not produced the way the service claims. The general method is on the hash fairness guide.