Demos / Under the hood

Technology

Provably fair results

When a game uses our commit-reveal system, the result is locked before the player bets. After the round we reveal the secret seed, and anyone can hash it and recompute the result to check that nothing changed.

CommitSHA-256 hash of a secret server seed
ResultHMAC-SHA256 of server seed, client seed and nonce
CheckRuns in the player's browser
Fairness labSession ready
1 · Seeds
Server seed hash shown before you play...
Server seed secret until revealed
Nonce goes up by one each result0
2 · Generate a result
Result
Ready
Float.
HMAC, first 32 hex.
3 · Verify
  1. Hash the revealed seedReveal the server seed first
  2. Compare it to the commitment.
  3. Recompute every result.
History
NonceTypeResult
No results yet

Everything here runs in your browser with the Web Crypto API, so you can inspect every step. In production the server seed stays on the server until it is revealed.

How it works

Four steps, and the player can check every one.

01

We commit

Before any bet, we create a secret server seed and show its SHA-256 hash. The hash locks the seed in without giving it away.

02

The player adds a seed

The player can set their own client seed. Because it is mixed into every result, we cannot work out the outcome in advance either.

03

The result is computed

Each result is HMAC-SHA256 with the server seed as the key and client seed, nonce and cursor as the message. Same inputs, same output, every time.

04

We reveal

After the session we reveal the server seed. If its hash matches the commitment and the results recompute the same, the game was fair.

The math

The function behind every result.

The first 13 hex characters of the HMAC become a float between 0 and 1. Every game maps that float to its own outcome: a dice roll, a crash point, a card position, a keno ball.

async function generateFloat(serverSeed, clientSeed, nonce, cursor = 0) {
  // Combine both seeds with the bet counter
  const input = `${clientSeed}:${nonce}:${cursor}`;
  const hash = await hmacSha256(serverSeed, input);
  // 13 hex characters give 52 bits of precision
  const value = parseInt(hash.slice(0, 13), 16);
  return value / parseInt('fffffffffffff', 16);
}
Where we use it

On games that need a random result.

This is the RNG we put on games with a random outcome. Contests that settle on real game scores don't need it for the score, and our slots on Stake use Stake Engine's own certified system.

Keno and CrashThe draw and the crash point come from the seeds, with a verify button after each round
Chain Reaction and The VaultThe hidden grid and the secret code are committed before play
Card gamesShuffles for Blind 21 and the battle card games
Fight Night and Horse RacingSimulated events can be driven from committed seeds
Not used forSquares, pick'em, survivor and brackets, which settle on the real score, and slots on Stake