KAPITAN

Provably fair

Updated:

Provably fair is a way to prove a round’s result was fixed before you bet and not swapped afterwards. Kapitan publishes the SHA-256 fingerprint of your account’s secret seed before your first bet on it, mixes that seed with yours, and reveals it as soon as you change seeds. Crash plays from a chain of results fixed in advance. Anyone can redo the math and compare it with the recorded result.

How it works

  1. A fingerprint before you bet. Your account has its own secret seed for Dice, Plinko, Limbo and Mines, and its SHA-256 hash is published before your first bet on it. The next seed’s hash is published too, before you choose the seed that goes with it. Changing a seed would change its hash.
  2. Your seed. Those results also depend on a seed you choose (a random one to start with), so the server can’t pick an outcome for you. Your bets on a secret seed are numbered 0, 1, 2… with no gaps, so none can be left out.
  3. The reveal. Change seeds whenever you like in the Provably fair panel: the old secret seed is published at once, and anyone can recompute every bet made on it. A Mines game still going on it keeps it locked until it ends.
  4. Crash’s chain. Crash is one round for everyone, so it plays from a chain of results fixed in advance. Each game’s hash is the SHA-256 of the next game’s, and the SHA-256 of game 1’s, the commitment, is published before the chain starts, with the number of a TRON block that doesn’t exist yet. That block’s ID salts every game, so nobody, the house included, could know a crash point when the chain was fixed. Until a chain is in play, Crash uses a shared secret seed revealed every 100 rounds, with the public seed crash; Dice Duels always do, with both players’ seeds.

The formula

Each round computes HMAC-SHA256, keyed with the secret seed, of the string your_seed:round_number. The round number is the bet’s number on your secret seed (0, 1, 2…); Crash and Dice Duels count their own. The first 4 bytes of the result divided by 232 give a number r between 0 and 1.

  • Crash: on its chain, the key is the game’s hash and the string is salt:game_number, the salt being the ID of the chain’s TRON block (off a chain, the shared secret seed and crash:round_number). Multiplier = (1 − house edge) / (1 − r), rounded down to two decimals, at least 1.00x and at most 1000x. The edge is 2% unless the round recorded another.
  • Dice: roll = ⌊r × 100⌋ + 1, from 1 to 100.
  • Plinko: for row i, byte 4 + i decides the bounce: even goes left, odd goes right. The bucket is the number of right bounces; its multiplier comes from the chosen board’s table.
  • Limbo: result = (1 − house edge) / (1 − r), rounded down to two decimals, at least 1.00x and at most 1000x: the Crash formula with your seed. The edge is recorded with every round (2% now).
  • Mines: the tiles are numbered 0 to 24, row by row from the top left. Mine k (from 0) takes rk from the HMAC of your_seed:round_number:k and picks tile ⌊rk × tiles left⌋ among the tiles not drawn yet, in order.
  • Dice Duel: the seed in the string is both players’ seeds, the opener’s first: opener_seed:joiner_seed:round_number. The dice are read from the bytes of the result in order: a byte under 252 gives a die of byte mod 6 + 1, and one of 252 or more is skipped, so every face is equally likely. When the 32 bytes run out, the HMAC of opener_seed:joiner_seed:round_number:k for k = 1, 2, … carries on. Each throw is four dice: two for the player who opened the duel, then two for the one who joined; on a tie the next four are thrown. Both players’ rounds record the same rolls.

Check it yourself

This code for Node.js 18+ checks the fingerprint and recomputes a result. Fill in the revealed seed, your seed and the round number: the Provably fair panel shows them under “What we checked”. For a Crash game, the last lines hash the game’s hash back to the chain’s commitment; a game millions in takes a few seconds.

const crypto = require('crypto');

// The revealed secret seed and its published fingerprint
const serverSeed = '...';
const fingerprint = '...';
// Your seed (for a Crash game on its chain, the chain's salt) and the round number (the game number)
const clientSeed = '...';
const roundNumber = 123456;

// Does it match the fingerprint published before the round?
console.log(crypto.createHash('sha256').update(serverSeed).digest('hex') === fingerprint);

const hmac = crypto.createHmac('sha256', serverSeed).update(`${clientSeed}:${roundNumber}`).digest();
const r = hmac.readUInt32BE(0) / 2 ** 32;

// Crash
const edge = 0.02;
console.log(Math.min(Math.max(Math.floor(((1 - edge) / (1 - r)) * 100) / 100, 1), 1000));
// Dice
console.log(Math.floor(r * 100) + 1);
// Plinko: 0 is left, 1 is right; the bucket is the number of 1s
const rows = 16;
console.log([...hmac.subarray(4, 4 + rows)].map(b => b % 2));
// Limbo: the result is worked out like a crash point, at the house edge the round recorded
const limboEdge = 0.02;
console.log(Math.min(Math.max(Math.floor(((1 - limboEdge) / (1 - r)) * 100) / 100, 1), 1000));
// Mines: tiles 0-24 row by row from the top left; mine k comes from the HMAC with ":k" on the end
const mines = 3; // How many mines the board had
const left = [...Array(25).keys()];
const board = [];
for (let k = 0; k < mines; k++) {
  const rk = crypto.createHmac('sha256', serverSeed).update(`${clientSeed}:${roundNumber}:${k}`).digest().readUInt32BE(0) / 2 ** 32;
  board.push(left.splice(Math.floor(rk * left.length), 1)[0]);
}
console.log(board.sort((a, b) => a - b));

// Crash on its chain: the secret seed is the game's hash. SHA-256 of a game's hash gives the game before it's, and of game 1's, the commitment published before the chain began
const commitment = '...';
let h = serverSeed;
for (let n = roundNumber; n >= 1; n--) h = crypto.createHash('sha256').update(h).digest('hex');
console.log(h === commitment);

One-click check

Every game has a Provably fair panel under it. Tap one of your recent results or type a round ID: the panel redoes the math right in your browser: it checks the revealed seed against its published fingerprint (for a Crash game, hashes back through the games before it toward the chain’s commitment) and shows whether recomputing the round gives the recorded result. For a fully independent check, use the code above.

Play Crash · Dice · Plinko · Mines · Limbo · Dice Duel

Frequently asked questions

Why isn’t the secret seed revealed straight away?

While a seed is in use, it could be used to work out the rounds still to come. Your own seed is revealed as soon as you change seeds, which you can do at any time, but not while a Mines game played on it is still going, since it would give away where the mines are. The shared seed of Dice Duels is revealed once its 100 rounds are played, or the server restarts. A Crash game’s hash is shown as soon as its round is over.

Could the casino pick a seed to suit my bet?

No. Your secret seed’s fingerprint is published before you bet, and the next one’s before you choose the seed that goes with it. A seed can’t be changed without changing its fingerprint. Crash’s results were all fixed by the chain’s commitment before the TRON block that salts them existed.

How is the round number different from the round ID?

The round number is the bet’s number on its secret seed, and it goes into the formula; on Crash’s chain it is the game number. The ID is the record of your bet, used to look the round up in the panel. The panel shows both.