Provable fairness & verification
Every BetPlug round commits to its randomness before any wager is placed (api/openapi.yaml). Operators, players, and auditors can replay any revealed round server-side via GET /v1/ or offline using @betrail/verifier, the BetPlug Fairness Verifier web app, or standard SHA/HMAC primitives in any language.
1. Commit-reveal seed lifecycle#
Each (player_ref, game) holds a SeedState (GET /v1/ or GET /v1/session/seeds):
current(SeedPairCommitted):{ server_seed_hash, client_seed, nonces_used }.server_seed_hashis lowercase hexSHA-256(ascii(server_over the 64-character lowercase hex server seed (never hex-decoded 32 bytes).seed)) next(SeedPairCommitted): Pre-committed next server seed hash plus the player's chosen nextclient_seed(PUT /v1/).players/ {player_ref}/ client-seeds/ {game} previous(SeedPairRevealed | null): After rotating (POST /v1/with an empty body), revealsplayers/ {player_ref}/ seeds/ {game}/ rotate server_seedalongsideserver_seed_hash,client_seed, andnonces_used.
Security: Never trim or Unicode-normalize
client_seed(3..64raw UTF-8 bytes, no C0/DEL/C1 controls or unpaired surrogates). NFC"ñ"(c3 b1) and NFD"n\u0303"(6e cc 83) hash to completely different outcomes. When displaying untrustedclient_seedorplayer_refvalues to humans, escape bidirectional overrides (U+202A..U+202E,U+2066..U+2069) and zero-width characters (U+200B..U+200F,U+FEFF).
Seed rotation & GET /v1/rounds/{id}/verify rules#
- Rotation blocked while unfinished (
409 round_open): Rotating while any round on the current pair isreserved,debiting,open, or has an unresolved placement returns409 round_openso an active round's seed never leaks mid-play. - Pre-reveal check (
409 seed_not_revealed): Calling/verifybefore rotating returns409 seed_not_revealed. - Server replay verdict (
200): Once rotated,/verifyreplays every step from the storedengine.Record(v: 1) and returns HTTP200{ result: "ok", record }— or{ result: "verify_mismatch", detail, record }(a mismatch is always a200verdict, never masked as a5xx). Verifyrecord.tablesSHA-256 fingerprints against the published game paytable and confirmsteps[0].outcome.with contiguoustrace. from === 0 trace.from/trace.toacross steps.
Pre-draw vs post-draw void rounds#
Nonces are reserved atomically before engine.Open and wallet debit, so failed attempts never reuse a nonce and may leave gaps:
| Void class | Trigger | Stored record | GET /v1/ after rotation |
|---|---|---|---|
Post-draw void | debit_refused or debit_unknown (wallet declined or timed out after draw) | Contains record.steps[0] | 200 { result: "ok", record } — proves voiding never cherry-picked outcomes |
Pre-draw void | persist_error or engine_error during Open (before any draw recorded) | Empty {} (0 steps) | 409 closed ("This round voided before any draw recorded an outcome.") — audit via GET /v1/rounds/{id} + rotated seed state |
2. RNG streams across the catalog#
Warning: BetPlug preserves five exact legacy RNG recipes alongside
FairRandomand live reverse hash chains. Never substitute one game's RNG or rounding rule for another.
record.stream.kind | Games | Digest construction (server_seed = 64 ASCII hex chars) | trace counter |
|---|---|---|---|
dice-sha512 | dice (DICE) | Plain SHA-512(server_seed + ":" + client_seed + ":" + nonce) (128 lowercase hex chars) | digests (0..1) |
hmac-nonce | limbo, roulette, diamonds | HMAC-SHA256(key = ascii(server_seed), msg = client_seed + ":" + nonce) (32 bytes, no :cursor) | digests (0..1) |
plinko-hmac | plinko (PLINKO) | HMAC-SHA256(key = ascii(server_seed), msg = client_seed + ":" + nonce + ":" + c) (c = 0 for 8 pins; c = 0, 1 for 9..16 pins) | digests (1 or 2) |
fairrandom | All other Instant, Stateful, Originals Slots & stack-o-pass | HMAC-SHA256(key = ascii(server_seed), msg = client_seed + ":" + nonce + ":" + cursor) (8 big-endian uint32 words/block) | u32 words |
Reverse SHA-256 hash chain | Shared live shows (trapdoor, kombat-multiplayer, crash, meme-trade) | link_{k} = SHA-256(ascii(link_{k+1})) anchored at s_0 + external public block salt | per-show FairRandom |
Legacy recipe 1 — DICE (dice-sha512)#
- Multiplier & paytable:
chancein"0.01".."94.05"(W = chance * 100in1..9405),P = floor(950_000_000 / W)in10^-5units (W = 4798->"1.97999"). Paytable fingerprint:7c145a94276eb256705c4c6d326824f70891fbc1120b33eea0433f432f702b4e. - Roll (
0..9999): ComputeH = hex(SHA-512("${server_. Scan 25 windowsseed}:${client_ seed}:${nonce}")) k = 0..24of 5 hex chars (H[5k .. 5k+5]); the first value< 1_000_000islucky. If all 25 are>= 1_000_000, take the 3-hex tailparseInt(H.(slice(125, 128), 16) 0..4095). Thenroll = lucky % 10_000. - Settlement:
"under"wins iffroll < W;"over"wins iffroll >= 10_000 - W. Winning profit in atoms for stakeband max-profit capC:profit = min(floor(b * P / 100_000) - b, C),payout = b + profit.
Legacy recipe 2 — LIMBO (hmac-nonce, 12-decimal bcdiv trap)#
- Compute
D = HMAC-SHA256(ascii(server_(noseed), "${client_ seed}:${nonce}") :cursor). - From the first 4 bytes
b0, b1, b2, b3, compute the exact 12-decimal truncated byte sum:S = floor(b0 * 10^12 / 256) + floor(b1 * 10^12 / 65536) + floor(b2 * 10^12 / 16777216) + floor(b3 * 10^12 / 4294967296) roll = floor(S / 10^6) // 0 .. 999,999 crash_hundredths = floor(97_000_000 / (roll + 1)) - Critical
bcmath-12trap: Never replacefloor(S / 10^6)withfloor(u * 10^6 / 2^32)— per-byte 12-decimal truncation differs at 4,224 values ofu! Wins iffcrash_hundredths >= target_hundredths(101..100_000_000, i.e.1.01x..1000000.00x).
Legacy recipe 3 — ROULETTE (hmac-nonce)#
- Compute
D = HMAC-SHA256(ascii(server_andseed), "${client_ seed}:${nonce}") SfromD[0..3]. Pocketspin = floor(37 * S / 10^12)(0..36, proven identical tofloor(37 * u / 2^32)). - Two-floor settlement over total stake
Band winning-chip return sumW:q8 = floor(W * 10^8 / B),gross = floor(B * q8 / 10^8), capped atB + max_profit_atoms.
Legacy recipe 4 — DIAMONDS (hmac-nonce)#
- Compute
D = HMAC-SHA256(ascii(server_. Read the first 20 bytes as 5 groupsseed), "${client_ seed}:${nonce}") g = 0..4(u_g = uint32be(D[4g..4g+4])):gem_g = floor(7 * u_g / 2^32)(0..6). - Sorted colour counts map to the 7 canonical hands:
[5]->ALL_DIAMONDS(40x),[4,1]->FOUR_DIAMONDS(5x),[3,2]->THREE_(DIAMONDS_ TWO_ DIAMONDS 4x),[3,1,1]->THREE_DIAMONDS(3x),[2,2,1]->TWO_(DIAMONDS_ TWO_ DIAMONDS 2x),[2,1,1,1]->TWO_DIAMONDS(0.1x),[1,1,1,1,1]->NOTHING(0x).
Legacy recipe 5 — PLINKO (plinko-hmac)#
- Compute
D_c = HMAC-SHA256(ascii(server_forseed), "${client_ seed}:${nonce}:${c}") c = 0 .. Math.floor((pins + 7) / 8) - 1(1digest for8pins,2digestsD_0 || D_1for9..16pins). - Concatenate bytes
B. Pini(0..pins-1) steps right (1) iffB[4 * i] >= 128.bucket = sum(step_i)(0..pins) indexes the(pins, risk)paytable.
FairRandom cursor stream#
FairRandom(HMAC-SHA256(server_): Default byte stream across all other Instant games (seed, client_ seed: nonce: cursor) PACKS,RANGEDICE,WHEEL,DRILL,SLIDE,CASES,BARS,KENO,DARTS,TAROT,BACCARAT,KABOOM,TILT), every Stateful Session game (CHICKEN,PUMP,MINES,TOWERS,BLACKJACK,HILO,SNAKES,FLIP,RPS,MOLES,VIDEOPOKER,SKYRUSH,DEADSHOT,KOMBAT,STACKPACKS), every Originals Slot (GRIMOIRE,PHARAOH,SHOGUN— one nonce per paid spin including bonus rounds), andSTACKOPASStable hands.- Primitives:
Int(n) = (u * n) >> 32(for games likemines,towers,blackjack,snakes); exact rejectionUniform(n, maxDraws)(rejectingu >= n * floor(2^32 / n)intotrace.rejectedforbaccarat,video-poker,moles,darts,hilo,stack-packs,trapdoor, and all Originals Slots);SuffixedBlock(cursor, k)(hilorehash when all 8 words reject); splice Fisher-YatesPickUnique(n, k)/Shuffle(n); andAlignToCursor()advancing to the next 8-word boundary.
Live hash chains vs stack-o-pass per-player seeds#
- Shared live shows (
trapdoor,kombat-multiplayer,crash,meme-trade): Pre-commit a reverseSHA-256chain (SHA-256(ascii(seed)) === commit, walking back to terminal anchors_0) salted by an external public block beacon (salt_source, e.g."bitcoin:<height>") announced before betting opens. Any unplayed link is broadcast viaskipped_link. Seed derivation:trapdoorusesClient = "trapdoor:" + salt, Nonce = gate;kombat-multiplayerusesClient = salt, Nonce = index;crashusesClient = "crash:" + salt, Nonce = index;meme-tradeusesClient = "meme-trade:" + salt, Nonce = index. - Per-operator live tables (
stack-o-pass): Uses each player's ownFairRandomseed pair (not a shared show hash chain), verified after the player rotates their seed pair.
Tip: All catalog games are mounted and served across
sandboxandlive(404 unknown_gameapplies only to unrecognized slugs;409 not_offeredapplies to disabled brand games, missing live hourly FX rates, live demo launches, or theMINES (12, 11)preset).
3. Standalone multi-recipe verifier (runnable sample)#
Verify SHA-256 server-seed commitments, DICE (dice-sha512 including paytable fingerprint & 26th-read tail), LIMBO (hmac-nonce exact bcmath-12 byte sum), and PLINKO (plinko-hmac) in pure BigInt:
import assert from "node:assert/strict";
import crypto from "node:crypto";
const TEN12 = 1_000_000_000_000n;
const B_POW = [256n, 65_536n, 16_777_216n, 4_294_967_296n] as const;
function diceMultiplierScaled(w: bigint): bigint {
return 950_000_000n / w; // exact floor in 10^-5 units
}
function diceRollFromDigest(digestHex: string): { lucky: number; roll: number; windowsRead: number } {
for (let k = 0; k < 25; k++) {
const v = Number.parseInt(digestHex.slice(5 * k, 5 * k + 5), 16);
if (v < 1_000_000) return { lucky: v, roll: v % 10_000, windowsRead: k + 1 };
}
const tail = Number.parseInt(digestHex.slice(125, 128), 16);
return { lucky: tail, roll: tail % 10_000, windowsRead: 26 };
}
function limboCrashHundredths(serverSeed: string, clientSeed: string, nonce: number): bigint {
const d = crypto.createHmac("sha256", Buffer.from(serverSeed, "ascii")).update(`${clientSeed}:${nonce}`, "utf8").digest();
let s = 0n;
for (let k = 0; k < 4; k++) s += (BigInt(d[k]!) * TEN12) / B_POW[k]!;
const roll = s / 1_000_000n;
return 97_000_000n / (roll + 1n);
}
function plinkoBucket(pins: number, serverSeed: string, clientSeed: string, nonce: number): number {
const count = Math.floor((pins + 7) / 8);
const bytes = Buffer.concat(
Array.from({ length: count }, (_, c) =>
crypto.createHmac("sha256", Buffer.from(serverSeed, "ascii")).update(`${clientSeed}:${nonce}:${c}`, "utf8").digest(),
),
);
let bucket = 0;
for (let i = 0; i < pins; i++) if (bytes[4 * i]! >= 128) bucket += 1;
return bucket;
}
// 1. DICE paytable fingerprint across all 9,405 targets
const fpLines = Array.from({ length: 9405 }, (_, i) => `${i + 1}|${diceMultiplierScaled(BigInt(i + 1))}`);
const fingerprint = crypto.createHash("sha256").update(`betrail-dice-paytable/1\n${fpLines.join("\n")}`, "utf8").digest("hex");
assert.equal(fingerprint, "7c145a94276eb256705c4c6d326824f70891fbc1120b33eea0433f432f702b4e");
// 2. DICE commitment + reference vector (roll = 3317, payout = 0.00019799 BTC) + 26th-read tail
const seed = crypto.createHash("sha256").update("betrail/l2/dice/boundary", "utf8").digest("hex");
const seedHash = crypto.createHash("sha256").update(seed, "ascii").digest("hex");
assert.equal(crypto.createHash("sha256").update(seed, "ascii").digest("hex"), seedHash);
const diceDigest = crypto.createHash("sha512").update(`${seed}:betrail-dice:1`, "utf8").digest("hex");
assert.equal(diceRollFromDigest(diceDigest).roll, 3317);
assert.equal((10_000n * diceMultiplierScaled(4798n)) / 100_000n, 19_799n);
assert.deepEqual(diceRollFromDigest(`${"f".repeat(125)}abc`), { lucky: 0xabc, roll: 2748, windowsRead: 26 });
// 3. LIMBO bcmath-12 & PLINKO plinko-hmac determinism checks
assert.ok(limboCrashHundredths(seed, "betrail-limbo", 0) >= 97n);
const b16 = plinkoBucket(16, seed, "betrail-plinko", 0);
assert.ok(b16 >= 0 && b16 <= 16);