---
id: BI0144
title: "Provable fairness verifier"
url: https://carbium.sh/library/blockchainideas/provable-fairness-verifier
collection: Blockchain ideas
category: Games
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Provable fairness verifier

A future blockhash is unknown when a bet is placed, yet the leader that builds its slot can steer or skip it. This verifier checks a published seed commitment and the reveal slot's blockhash, read from Carbium.

## Who uses it

Three readers ask this question. A studio building a dice roll, a card deal or a loot drop wants players to trust the result. A player who lost a round wants to know whether the house could have picked the outcome. A developer who has read that a blockhash is hard to predict wants to know why that is not enough.

The verifier answers the player for one round. It takes the commitment the house published before bets, the seed it revealed afterwards and the two slots the round uses. It recomputes the outcome and reports which steps hold. Nothing is signed and no funds move.

A studio runs the same check on its own rounds before launch, so a broken round shows up in staging instead of in a support ticket.

## Why a future blockhash fails

A blockhash closes a slot. Before the leader of that slot produces it, nobody can read it, so a bet placed earlier cannot be tuned to the result. That part of the idea holds. The weak point is who shapes the value once it exists.

The leader of the reveal slot chooses which transactions enter its block and in what order. Those entries feed the hash chain that ends in the blockhash, so the leader can change the blockhash by changing the block. A leader that does not like the result can also skip the slot, which leaves no block and no blockhash, and the chain continues from the parent. A game that pays real stakes on one slot is handing that choice to whoever leads it.

The verifier checks the part of the design it can check. The seed must match an earlier commitment, and the outcome must follow from the seed and the blockhash of a slot that came after the commitment. Steering by a leader is a separate question, covered under where it ends.

## The four checks

The check runs four steps in order. Each step prints its result, so a failure names the step.

| Check | What it reads | Passes when |
|---|---|---|
| Commitment | sha256 of the revealed seed, against the commitment published first | the two hashes are equal |
| Order | the commit slot and the reveal slot of the round | the commit slot is before the reveal slot |
| Blockhash | the blockhash of the reveal slot, from getBlock at confirmed commitment | the slot has a block; a skipped slot leaves the round unresolved |
| Outcome | sha256 of the seed bytes and the blockhash text, first four bytes modulo 100 | the printed number matches the game's record |

The outcome rule belongs to the game and must be published with the commitment, so a player can rerun it. The code uses a four-byte read of the hash modulo 100. A game with another rule changes the last line of the check and nothing else.

## The build

The verifier is one file. It needs `@solana/kit` and the Node 24 built-ins, and it reads the chain through [JSON-RPC calls](https://carbium.sh/docs/rpc) at `https://services.carbium.sh`, with the key in the `x-api-key` header.

1. Read the head slot with getSlot at confirmed commitment. It is one of the cached reads, at 1 cell.
2. Take the four round values from the arguments. With none, the demo round uses the slots 20 and 10 behind the head and a seed the code makes up.
3. Hash the seed and compare the result with the commitment.
4. Read the reveal slot with getBlock at confirmed commitment, json encoding, transactionDetails none and maxSupportedTransactionVersion 1, because mainnet carries v1 transactions.
5. Hash the seed with the blockhash, read the first four bytes and print a number from 0 to 99.

`main.ts` (run: `CARBIUM_KEY=<YOUR_KEY> node main.ts`)

```ts
// BI0144 · Provable fairness verifier
// https://carbium.sh/library/blockchainideas/provable-fairness-verifier
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { createHash } from "node:crypto";
import { createDefaultRpcTransport, createSolanaRpcFromTransport, type Slot } from "@solana/kit";

const token = process.env.CARBIUM_KEY ?? "";
if (token === "") {
  console.error("Export CARBIUM_KEY first.");
  process.exit(1);
}

const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": token },
  }),
);

const digest = (chunks: Array<string | Buffer>): Buffer => {
  const hasher = createHash("sha256");
  chunks.forEach((chunk) => hasher.update(chunk));
  return hasher.digest();
};

// argv: commitment seed commitSlot revealSlot. Without them, a demo round is built around the head slot.
const args: (string | undefined)[] = process.argv.slice(2);
const [commitIn, seedIn, commitSlotIn, revealSlotIn] = args;
const seedBytes = Buffer.from(seedIn ?? Buffer.from("carbium-demo-seed").toString("hex"), "hex");
const publishedCommit = commitIn ?? digest([seedBytes]).toString("hex");

const head = await rpc.getSlot({ commitment: "confirmed" }).send();
const commitSlot = commitSlotIn !== undefined ? BigInt(commitSlotIn) : head - 20n;
const revealSlot = revealSlotIn !== undefined ? BigInt(revealSlotIn) : head - 10n;
if (commitSlot >= revealSlot) {
  console.error("The commit slot must come before the reveal slot.");
  process.exit(1);
}

const seedMatches = digest([seedBytes]).toString("hex") === publishedCommit;
console.log(`seed hashes to the published commitment: ${seedMatches}`);
console.log(`order ok: commit slot ${commitSlot} is before reveal slot ${revealSlot}`);

try {
  const block = await rpc.getBlock(revealSlot as Slot, {
    commitment: "confirmed",
    encoding: "json",
    maxSupportedTransactionVersion: 1,
    transactionDetails: "none",
    rewards: false,
  }).send();
  if (block === null) {
    console.log(`slot ${revealSlot} has no block, so the round is unresolved`);
  } else {
    const roll = digest([seedBytes, block.blockhash]).readUInt32BE(0) % 100;
    console.log(`reveal blockhash: ${block.blockhash}`);
    console.log(`outcome from 0 to 99: ${roll}`);
  }
} catch (err) {
  console.error("getBlock failed:", err instanceof Error ? err.message : err);
  process.exit(1);
}
```

Run it with `CARBIUM_KEY` set. A real round passes the house's commitment, seed, commit slot and reveal slot as four arguments, in that order. [Slot to timestamp](https://carbium.sh/library/howsolana/slot-to-timestamp-conversion) covers how a slot number maps to wall-clock time when a round is shown to players.

## What it costs

A run makes one getSlot and one getBlock, two calls in all. getSlot is a cached read at 1 cell, and the Free plan allows 5 cached reads a second. [Limits are per account](https://carbium.sh/docs/limits), so a game that checks every round on its own board shares that budget with its other calls.

A game that verifies its whole history makes one getBlock per round, and the plan's rate for those calls sets how fast that history can be read. [Confirmation time](https://carbium.sh/library/blockchainideas/confirmation-time-estimator) shows how long a round takes to settle at the same commitment level, which sets how soon a reveal can be checked.

## Where it ends

- The verifier checks arithmetic and order. It cannot prove the house published its commitment before bets closed, unless the commitment sits somewhere a player can read it with a timestamp.
- A leader can skip its slot or steer the contents of its block. A steered block still passes, because the check confirms the arithmetic and not the leader. Designs that resist steering combine several slots, so one leader cannot settle a round alone, and that rule lives in the game.
- getBlock answers null for a skipped slot and for a slot the node no longer serves. The verifier reports the round as unresolved and does not pick another slot.
- Finality arrives quickly. Since the Alpenglow switch on mainnet, a slot is about 200 ms and finalized sits 0 to 1 slots behind processed, so a reveal slot is final almost as soon as it is made. The code reads at confirmed.
- The code holds no state. It checks one round per run and writes nothing to disk.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The commitment does not match the revealed seed. | The house published a different seed, or hashed it as text. The check hashes the seed as hex bytes, so compare the bytes the house hashed, not their display form. |
| getBlock returns null for the reveal slot. | The slot was skipped, or the node no longer serves it. Treat the round as unresolved, and do not move to another slot to get a better number. |
| getBlock answers -32015. | The call lacks maxSupportedTransactionVersion 1. Mainnet carries v1 transactions, and the code sets the value. |
| Two runs print different outcomes. | The blockhash is fixed once its slot is produced, so the slots moved. Pass the commit and reveal slots as arguments so both runs check the same round. |
| getBlock answers 429. | Read the retry-after hint and wait that long before running again. A run makes few calls, so the rate is rarely the limit, but other calls on the same account draw on the same budget. |

## Questions

### Why can't I use a future blockhash for randomness at all?

Nobody can read it before its slot exists, which keeps a player from tuning a bet to it. The leader that builds the slot chooses its contents and can skip it, so one party can try a few outcomes, and a game needs a seed the house cannot change once bets are placed.

### Does the verifier prove the house was fair?

It proves that the revealed seed matches the commitment, and that the outcome follows from the seed and a block the chain produced. It does not prove the commitment came before the bets, so the game has to publish it somewhere with a time.

### Can I run it on the Free plan?

Yes. One run makes a getSlot and a getBlock, and getSlot is a cached read that the Free plan allows at 5 a second. A player checking a few rounds stays well inside that.

### What changes if my game uses a different outcome rule?

Only the last hash line of the check. Publish the rule with the commitment so a player can rerun it on the same two slots and seed.

## Related

- [Slot to timestamp conversion](https://carbium.sh/library/howsolana/slot-to-timestamp-conversion) (How to use Solana, HS0062)
- [Confirmation time estimator](https://carbium.sh/library/blockchainideas/confirmation-time-estimator) (Blockchain ideas, BI0111)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
