"Provably fair" sounds like marketing until you look at the arithmetic. Underneath it is a small, checkable protocol: the operator commits to a secret before you bet, every result is derived from that secret plus inputs you can see, and the secret is revealed afterwards so you can recompute every round yourself.
This post works through the whole derivation — commitment, digest, dice, crash — with code that runs on a stdlib-only Python 3 and again in the browser with Web Crypto. Then it covers the part most write-ups skip: what a matching result actually proves, and what it doesn't.
The three inputs
| Value | Held by | Published |
|---|---|---|
server_seed | operator | SHA-256 hash before play; the seed itself after rotation |
client_seed | player | before the round, usually editable |
nonce | both | starts at 0 or 1, increments per round in the session |
Step 1 — the commitment
Before the first bet, the operator shows you the SHA-256 hash of a server seed it has already fixed. You cannot reverse the hash, but when the seed is revealed later you can confirm the hash matches — which proves the operator did not swap seeds mid-session.
import hashlib hashlib.sha256(b"cgb-demo-server-seed").hexdigest() # '3cfac31a5087c94846427e92046e793adb2a6ea5cb51d338c129ce8e21e71c74' That is the entire commitment mechanism: a one-way fingerprint, published early, checked late.
Step 2 — deriving the round digest
Results are not computed from that commitment hash. Each round's digest is derived with HMAC-SHA256, using the server seed as the key and the player-controlled values as the message:
digest = HMAC_SHA256(key = server_seed, message = f"{client_seed}:{nonce}") Why HMAC rather than a plain SHA-256 of the concatenation? Two reasons that matter here:
- The server seed is a key, not a message prefix. HMAC's inner/outer padding construction is built for exactly this shape and avoids the length-extension properties of
SHA-256(prefix || message). - The colon separator fixes the message layout. Without a delimiter,
("player", 1)and("player1", "")can collapse to the same string; with it, the boundary is unambiguous.
In Python this is three lines:
import hashlib, hmac def round_digest(server_seed: str, client_seed: str, nonce: int) -> str: message = f"{client_seed}:{nonce}".encode() return hmac.new(server_seed.encode(), message, hashlib.sha256).hexdigest() round_digest("cgb-demo-server-seed", "player-1", 1) # 'ea6a35e15852de7f78fb34381e1314eb2afc98803c2dd9e0f4985cdf92885588' Sixty-four lowercase hex characters, 256 bits. Everything downstream reads only the front of this string, which is fine: the leading bits of a cryptographic hash are uniformly distributed, and different game families deliberately consume different amounts of them.
Dice: mapping 32 bits onto a 10,001-point lattice
A dice roll is displayed to two decimals between 0.00 and 100.00 — 10,001 possible outcomes — so the natural mapping is:
def dice_roll(server_seed: str, client_seed: str, nonce: int) -> float: d = round_digest(server_seed, client_seed, nonce) bits = int(d[:8], 16) # first 32 bits, 8 hex chars return (bits % 10001) / 100 # 0 -> 0.00, 10000 -> 100.00 Run it on the demo seed:
roll = dice_roll("cgb-demo-server-seed", "player-1", 1) print(f"{roll:.2f}") # 59.10 Walk through it once by hand and the scheme stops being mysterious:
- the digest starts
ea6a35e1… -
int("ea6a35e1", 16)= 3,932,829,153 - mod 10,001 = 5,910
- divide by 100 → 59.10
Note the modulo bias: 2**32 is not a multiple of 10,001, so 7,843 of the 10,001 outcomes have one extra preimage. The relative spread is about 0.000233% — roughly 4,000× smaller than a 1% house edge, but it is there, and a purist implementation would rejection-sample instead. Some operators do; the roll you see is unaffected.
The house edge in dice does not live in this mapping. It lives in the payout: at a 1% edge a 49.5% win chance pays 2.00×, and 0.495 × 2 = 0.99.
Crash: 52 bits, inverse survivorship, and a floor
Crash reads the first 52 bits instead of 32, because it needs a uniform number with enough resolution to support multipliers in the millions:
def crash_point(server_seed: str, client_seed: str, nonce: int, edge: float = 0.01) -> float: d = round_digest(server_seed, client_seed, nonce) bits = int(d[:13], 16) # first 52 bits, 13 hex chars u = bits / 2**52 # exact: an IEEE-754 double has a 52-bit significand return max(1.00, (1 - edge) / (1 - u)) The 52 is not arbitrary. A double carries a 52-bit significand, so dividing a 52-bit integer by 2**52 is exact in every language that uses doubles — no rounding drift between your machine and the server.
For the same seed pair and nonce, u is 0.915683143154, and at a 1% edge:
print(f"{crash_point('cgb-demo-server-seed', 'player-1', 1):.2f}x") # 11.74x Two properties fall out of the formula:
- Survivorship.
P(crash >= t) = (1 - edge) / t. Cashing out at any fixed targettreturnst * (1 - edge) / t = 1 - edgein expectation, which is why "safe" targets do not exist. - The floor. When
u < edge— 1% of rounds at a 1% edge — the formula would produce less than 1.00, so it is clamped. Those are the rounds that bust instantly at 1.00×, and that is exactly where the edge is collected.
Verifying the same thing in the browser
You do not need Python to check a roll. Web Crypto computes HMAC in the tab, offline:
async function diceRoll(serverSeed, clientSeed, nonce) { const enc = new TextEncoder(); const key = await crypto.subtle.importKey( "raw", enc.encode(serverSeed), { name: "HMAC", hash: "SHA-256" }, false, ["sign"] ); const sig = await crypto.subtle.sign("HMAC", key, enc.encode(`${clientSeed}:${nonce}`)); const hex = [...new Uint8Array(sig)] .map(b => b.toString(16).padStart(2, "0")).join(""); const bits = parseInt(hex.slice(0, 8), 16); return (bits % 10001) / 100; } diceRoll("cgb-demo-server-seed", "player-1", 1).then(r => console.log(r.toFixed(2))); // 59.10 Two practical notes from building one of these:
-
crypto.subtleexists only in a secure context — https or localhost. Open the same file overfile://and it isundefined, which is the usual reason a local copy "does not work". -
parseInt(hex.slice(0, 8), 16)returns a double, not a 32-bit int, so a value above2**31— 3,932,829,153 here — stays exact. Reach for bitwise operators instead and it wraps negative: a classic bug in half-finished verifiers.
What a match proves — and what it doesn't
Recomputing 59.10 from the seed pair proves the result follows from those three values. It does not prove the seed was fixed before the bet: an operator that reveals an arbitrary seed afterwards can always produce a result consistent with it.
Closing that gap is the commitment check, and it takes both halves:
- Save the server seed hash the operator published before you played.
- After rotation, hash the revealed seed and compare it with the saved value.
- Recompute your nonces in order; every result should match your bet history.
Step 1 is the one players skip, and it is the one that makes the other two mean anything.
Reproducing this
Everything above is implemented, with tests, in a small MIT-licensed tool:
- Python CLI (standard library only) and browser build: provably-fair-verifier on GitHub
- Live verifier, nothing to install: kuldar-k.github.io/provably-fair-verifier
- For the house-edge side of the same arithmetic — survivorship curves, RTP and simulated sessions — there is an interactive Originals RTP lab
The CLI's selftest checks its digests against an independent HMAC implementation, so the check is not circular. Run it before you trust it with a real session.