inicasino.netContents

Tools and worked checks · 02 / 23

How to verify a provably fair bet by hand

You need one value saved before play, three values from the bet record and the operator's written rule. With those, any tool that computes SHA-256 and HMAC can check the bet.

Flow diagram with 5 steps: Server seed hash; Client seed; Nonce; Server seed; Conversion rule.
Six steps, one worked example, and commands for the console, Python, Node and OpenSSL.

What to collect

The values a check needs
ValueWhere it comes fromWhen you can have it
Server seed hashShown by the game before any bet under that seedBefore play. Save it yourself, outside the game's pages.
Client seedSet by you, or suggested by the page and accepted by youBefore play
NonceThe bet recordWith each bet
Server seedRevealed by the game after you ask for a new seed pairAfter play under that seed has ended
Conversion ruleThe operator's documentationAt any time

The six steps

  1. Before you play, copy the server seed hash and your client seed to a place the operator cannot edit. A text file or a screenshot will do.
  2. Play. For the bet you want to check, note the nonce and the result the game displayed.
  3. Ask the game for a new seed pair. In the usual design the old server seed is revealed at that moment.
  4. Compute SHA-256 of the revealed seed and compare it with the hash from step 1. If they differ, the revealed seed is not the one that was committed to, and the remaining steps prove nothing.
  5. Compute HMAC-SHA256 with the server seed as the key and the message built from your client seed and the nonce, in the format the operator documents.
  6. Convert the bytes of the digest to a number by the documented rule and compare it with the displayed result.

One example, four ways

The example is test vector V1 under the scheme defined on the verifier page: the key is the server seed as text, the message is reference-client:0:0, and the result is floor(u × 10000 / 2^32). Each set of commands below prints the same four values.

Diagram that pairs each item with its counterpart. Expected values for the example: SHA-256 of the server seed; HMAC-SHA256 digest; Integer from the first four bytes; Result.
Expected values for the example
Expected values for the example
ValueExpected
SHA-256 of the server seed9088b0a58305a44b0ec72f1af9ef3e2e4927d17a516fdbf805707fdebdf69107
HMAC-SHA256 digestfd3f9c652643592c1de6a9a56228cc866eda7f2d26d95c2ee38e1d1e5d3378a3
Integer from the first four bytes4248804453
Result9892
Browser console. Open the developer tools on any page served over HTTPS, paste the lines and press Enter. The last line prints the four values.
const enc = new TextEncoder();
const hex = (b) => [...new Uint8Array(b)].map((x) => x.toString(16).padStart(2, '0')).join('');
const serverSeed = 'reference-test-server-seed-0001';
const clientSeed = 'reference-client';
const nonce = 0;
const commitment = hex(await crypto.subtle.digest('SHA-256', enc.encode(serverSeed)));
const key = await crypto.subtle.importKey('raw', enc.encode(serverSeed), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
const mac = new Uint8Array(await crypto.subtle.sign('HMAC', key, enc.encode(`${clientSeed}:${nonce}:0`)));
const u = new DataView(mac.buffer).getUint32(0);
const result = Number((BigInt(u) * 10000n) >> 32n);
[commitment, hex(mac), u, result];
Python 3, standard library only.
import hashlib, hmac
server_seed = b'reference-test-server-seed-0001'
client_seed = 'reference-client'
nonce = 0
print(hashlib.sha256(server_seed).hexdigest())
mac = hmac.new(server_seed, f'{client_seed}:{nonce}:0'.encode(), hashlib.sha256).digest()
print(mac.hex())
u = int.from_bytes(mac[:4], 'big')
print(u, u * 10000 // 2**32)
OpenSSL and shell arithmetic. Using printf with %s keeps a trailing newline out of the input, which echo would add.
printf '%s' 'reference-test-server-seed-0001' | openssl dgst -sha256
printf '%s' 'reference-client:0:0' | openssl dgst -sha256 -hmac 'reference-test-server-seed-0001'
echo $(( 0xfd3f9c65 * 10000 / 4294967296 ))
Node.js, built-in crypto module.
const crypto = require('crypto');
const serverSeed = 'reference-test-server-seed-0001';
console.log(crypto.createHash('sha256').update(serverSeed).digest('hex'));
const mac = crypto.createHmac('sha256', serverSeed).update('reference-client:0:0').digest();
const u = mac.readUInt32BE(0);
console.log(mac.toString('hex'), u, Number((BigInt(u) * 10000n) >> 32n));

A shell keeps a history of commands, and a seed typed into a command stays in that history. For a revealed server seed this is harmless. It is one more reason never to type a wallet secret phrase or a private key into a command, a script or a web page in order to verify anything.

What a mismatch means

Reading a failed check
What differsLikely causeWhat to do
The hash in step 4The saved hash belongs to another seed pair, the seed was copied with an extra space or line break, or the seed is hex that the operator hashes as bytesTry the readings in the hash checker. If none matches, keep the saved hash and the revealed seed as evidence.
The digest in step 5The message format or the key reading differs from the one you usedRead the operator's description again and compare it with the scheme table.
Only the final numberA different byte-to-number ruleSee the rules and their differences.

A digest or a number that will not match while the commitment holds is usually a question of format. A revealed seed that does not hash to the commitment you saved is the serious case, because catching that is the only purpose a commitment has.

What you have shown at the end

You have shown that one result was computed by the published rule from a server seed that matches the hash you saved. That the result was out of the operator's hands before you bet follows only if you also set your own client seed after the hash was shown and the nonce continued your own count. You have not checked the payout table, the stated return or whether wins are paid. Those limits are set out on the page about what provably fair leaves open. An explanation of the three inputs is on the page about seeds and the nonce.

Questions people ask

Do I have to check every bet?

No. The operator cannot know in advance which bets you will check, so checking a few chosen afterwards already has value. Each seed pair needs its own commitment check, since each has its own hash.

Why does my hash differ when I use echo?

On most systems echo adds a line break to its output, and the line break is hashed with the seed. Use printf '%s' as in the example.

Can I check a bet without the hash I should have saved?

You can still recompute the result from the revealed seed. What you lose is the evidence that this seed was fixed before you bet, and without it the recomputation shows only that the arithmetic is consistent.

Sources

How we checked: statements about a named body link to that body's own page and carry the date we read it. Numbers in worked examples are computed by the site's build from the formulas shown, with routines covered by its test suite.