Spunk Odds Reference

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

Worked hash example (coinflip), computed with Python's hashlib; nonce 7
Server seed (revealed later)diamond-srv-91c2-flip
Commitment shown before play: SHA-256(server seed)89b43430bc6e2609d2bd5671201869dedbeb1c6cb32876caab8711776b7054b2
Client seed : nonce : rounddiamond-viewer-seed:7:0
HMAC-SHA256(server seed, message)d24368ee24bdf98d6040b3e537818fc15f330df5c0c744643464c40f325bbbd7
First 4 bytes (8 hex digits)d24368ee = 3,527,633,134
Float = value / 2^320.8213410932
Coin: float < 0.5 is headstails

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.

Server seed diamond-srv-91c2-flip, client seed diamond-viewer-seed, first float of each nonce
NonceFirst 8 hex digitsFloatResult
7d24368ee0.821341tails
8831665ec0.512061tails
97f519fb60.497339heads
10d16452810.817937tails
111a3da3730.102503heads
12432cd0c70.262403heads
13072d16100.028032heads
1459afae9d0.350337heads

Computed with Python's hmac and hashlib. One common construction, shown for teaching.

Do it yourself

  1. Copy the revealed server seed and run SHA-256 on it. The output must match the commitment shown before play.
  2. Write the message exactly as the service documents it, for example client seed, colon, nonce, colon, round.
  3. Compute HMAC-SHA256 of that message keyed with the server seed.
  4. Convert the first 8 hex digits to an integer and divide by 4,294,967,296.
  5. 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.