Grails Help

Provably Fair guide

How Grails picks every pull, what the four inputs are, and how to verify any pull yourself with the same code we run.

Every pull on Grails is Provably Fair. That means you can see how the result was generated and recreate it yourself. No trust required. This page is the full guide. The short version is in How do I know the pulls are fair?

Quick link: the verifier on OneCompiler, our exact code hosted on a third-party site so you can run it without trusting us.

What is Provably Fair?

When you open a pack, we generate a random number from 0 to 999,999 and it lands on one of the items in the pack according to the odds. A Provably Fair algorithm lets you see every input that produced that number and run the same math yourself, so you can be sure nothing was rigged after the fact.

How does it work?

We use a cryptographic hash function (HMAC-SHA512) with four inputs. Cryptographic as in cryptography, not blockchain.

  1. Server seed. A long random string we generate once a day (UTC). Every pull that day, by every user, uses it. We don't show the seed itself until the day ends. Instead you see its hash in advance, which proves the seed can't change after your pull.
  2. Client seed. A string you control. We generate one when you sign up, and you can change it anytime in CURRENT SEEDS on your pull history page.
  3. Salt. A random string created with your account. It never changes.
  4. Nonce. A counter that goes up by one with every pull. A 6x open uses six nonces in a row: if yours is 10 before the open, it's 16 after.

The hash of those four inputs gives a number from 0 to 999,999.

How the number picks an item

Before any pull, we "shuffle" the pack's item list in a repeatable way driven by that day's server seed. Then each item gets a range of numbers proportional to its odds.

Say a pack has three items:

  • Item A: 20% odds
  • Item B: 50% odds
  • Item C: 30% odds

The ranges would be:

ItemRange
Item A0 – 199,999
Item B200,000 – 699,999
Item C700,000 – 999,999

If your inputs produce 432,836, that falls in Item B's range, so you pulled Item B.

Verify a pull yourself

  1. Open your pull history and tap the pull you want to check. Its details show the server seed (or its hash, if the day hasn't ended yet), your client seed, your salt, and the nonce.
  2. Open the verifier on OneCompiler. Paste your four values into the marked lines at the top.
  3. Run it. The console prints your generated result. It should match the result number on the pull's details page. It also checks that the server seed hashes to the hash you were shown before you pulled.

If the day hasn't ended, you can verify the hash now and come back for the full seed after the day rolls over.

The code

This is the same function that runs on our servers. You can also run it locally with Node.js.

import { createHash, createHmac } from 'node:crypto';
const RESULT_RANGE = 1_000_000n;

const serverSeed = '<paste server seed>';
const serverSeedHash = '<paste server seed hash>';
const clientSeed = '<paste client seed>';
const salt = '<paste salt>';
const nonce = 0; // your nonce

verifyServerSeedHash(serverSeed, serverSeedHash);
console.log('Your generated result:', uniformResult(serverSeed, clientSeed, salt, nonce));

// Uniform random number in [0, RESULT_RANGE - 1]
function uniformResult(serverSeed: string, clientSeed: string, salt: string, nonce: number): number {
  const message = `${clientSeed}:${salt}:${nonce}`;
  const hmac = createHmac('sha512', serverSeed).update(message).digest(); // 64 bytes

  // Rejection sampling: read 8 bytes at a time until one falls under the limit
  const limit = (1n << 64n) - ((1n << 64n) % RESULT_RANGE);
  let byteOffset = 0;
  let x = hmac.readBigUInt64BE(byteOffset);
  while (x >= limit) {
    byteOffset += 8;
    if (byteOffset + 8 > hmac.length) return Number(x % RESULT_RANGE); // astronomically rare
    x = hmac.readBigUInt64BE(byteOffset);
  }
  return Number(x % RESULT_RANGE);
}

function verifyServerSeedHash(serverSeed: string, serverSeedHash: string): void {
  const generatedHash = createHash('sha512').update(serverSeed).digest('hex');
  console.log('Generated hash:', generatedHash);
  console.log('Provided hash: ', serverSeedHash);
  console.log(`Match: ${generatedHash === serverSeedHash}`);
}

Questions?

Ask in the Grails Discord or email sup@grails.gg.

On this page