services
Get a key

library / Use cases / Gaming / UC0130

Commit-reveal match audit

Check a commit-reveal game's settlement from chain data alone. A read-only Node script labels each transaction as commit, reveal or settle, groups them by match account and flags any match whose steps landed out of order.

By Carbium · Gaming · UC0130 · updated 2026-11-23

01

What a match audit checks

A commit-reveal game settles in three steps. A player commits a hash of their shot, later reveals the shot and the salt that produce that hash, and a crank that anyone may run settles the match against an oracle price and writes the score into the match account. The program holds nobody's funds, so an audit has little to say about balances. It has a lot to say about order and outcome.

Three properties show up in chain data alone.

  • Order. A reveal in an earlier slot than its commit, or a settle before its reveal, means the program accepted a step it should have refused. Players can then pick their shot after seeing the price.
  • Outcome. A transaction that carries an error changed no state beyond its fee. A failed reveal followed by a good one is a retry. A failed settle that nobody retried is a match stuck in the middle.
  • Who signed. Commit and reveal come from the player's key. The settle comes from whoever ran the crank, so many different fee payers on settles is the expected picture for a permissionless design, and one payer on every settle tells you who your crank really is.

The oracle check and the scoring happen inside the program, and you cannot re-run them from outside without the program's source. What you can do from outside is confirm that the steps landed in the order the program claims to enforce, on the matches that actually played.

02

What the script reads

  • getSignaturesForAddress on the program lists the newest transactions that touched it, newest first, with slots and error flags.
  • getTransaction on each signature returns the log lines, the account list with signer and writable flags, the slot, and the error if there was one.
  • The log lines carry the instruction name. Anchor programs print Program log: Instruction: Reveal and similar, so the script matches the phase names you pass in. A program that logs differently needs different match text.

A match account is the writable account in the transaction that is neither a signer nor the program. Every step of one match touches the same one, so grouping by it rebuilds each match's history. If your program writes two such accounts per step, pick the one that holds the match state and change the find line.

Every call in the script asks for finalized. Kit would send confirmed for a call that names no level, and a verdict you show a player should rest on blocks that cannot roll back. Finalized now trails the newest slot by one at most, so the audit loses almost nothing in freshness. Solana commitment levels covers the three levels.

getTransaction takes maxSupportedTransactionVersion: 1. Mainnet carries v1 transactions, and with the value absent or 0 the call answers -32015 for one of them, uncharged. The script passes 1.

03

The audit script

The script takes a program address and, optionally, a comma-separated list of phase names in the order the game runs them. The default is commit, reveal, settle. It reads the 10 newest transactions, fetches them in parallel and settles each call, so one failed fetch prints a line and the rest still count.

main.ts
// UC0130 · Commit-reveal match audit// https://carbium.sh/library/usecase/commit-reveal-match-audit// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: label a program's newest transactions by phase and check each match account saw them in order.import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const [programArg, phaseArg = "commit,reveal,settle"] = process.argv.slice(2);if (!programArg) { console.error("Usage: node main.ts <program-address> [phase,phase,...]"); process.exit(1); }const program = address(programArg);const phases = phaseArg.split(",").map((p) => p.trim().toLowerCase());const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));// kit would fill in confirmed; an audit reads at finalized, so say so on every call.const commitment = "finalized";type Tx = {  slot: bigint | number;  meta: { err: unknown; logMessages: string[] | null } | null;  transaction: { message: { accountKeys: { pubkey: string; signer: boolean; writable: boolean }[] } };};const sigs = await rpc.getSignaturesForAddress(program, { limit: 10, commitment }).send();const txs = await Promise.allSettled(sigs.map(async (s) =>  (await rpc.getTransaction(s.signature, { encoding: "jsonParsed", maxSupportedTransactionVersion: 1, commitment }).send()) as unknown as Tx | null));const matches = new Map<string, { slot: number; phase: number; sig: string }[]>();txs.forEach((r, i) => {  const sig = sigs[i].signature.slice(0, 12);  if (r.status === "rejected") return console.log(sig, "call failed:", String(r.reason).slice(0, 80));  const tx = r.value;  if (!tx?.meta) return console.log(sig, "unavailable (null from getTransaction)");  const logs = (tx.meta.logMessages ?? []).map((l) => l.toLowerCase());  const phase = phases.findIndex((p) => logs.some((l) => l.includes(`instruction: ${p}`)));  const keys = tx.transaction.message.accountKeys;  // The match account: writable, not a signer, not the program. Every step of one match touches it.  const match = keys.find((k) => k.writable && !k.signer && k.pubkey !== programArg)?.pubkey ?? "none";  const label = tx.meta.err ? "failed" : phase < 0 ? "other" : phases[phase];  console.log(sig, `slot ${tx.slot}`, label.padEnd(8), `match ${match.slice(0, 8)} signer ${keys[0]?.pubkey.slice(0, 8)}`);  if (!tx.meta.err && phase >= 0) matches.set(match, [...(matches.get(match) ?? []), { slot: Number(tx.slot), phase, sig }]);});for (const [match, steps] of matches) {  steps.sort((a, b) => a.slot - b.slot);  let top = -1, topSlot = -1, bad = 0;  for (const s of steps) {    // Same-slot steps have no known order, so only a strictly later slot counts.    if (s.phase < top && s.slot > topSlot) { bad++; console.log(`out of order: ${phases[s.phase]} after ${phases[top]} on ${match.slice(0, 8)} (${s.sig})`); }    if (s.phase > top) { top = s.phase; topSlot = s.slot; }  }  console.log(`match ${match.slice(0, 8)}: ${steps.length} steps, ${bad} out of order`);}console.log(`${sigs.length} transactions read at ${commitment}; ${matches.size} match accounts labelled`);

run: CARBIUM_KEY=$CARBIUM_KEY node main.ts <program-address> commit,reveal,settle

Each transaction line shows the signature prefix, the slot, a label and the match account. A label of failed means the transaction carried an error. Other means it succeeded but matched none of your phase names. After the lines, each match gets a verdict: how many labelled steps it had and how many arrived out of order.

Two steps in one slot are never flagged. The signature list does not say which of two same-slot transactions ran first, so a comparison there would be a guess. Only a step that lands in a strictly later slot than a step it should have preceded counts as out of order.

Pointed at a program that does not log your phase names, the script still runs. Every successful transaction prints as other and the summary shows zero labelled matches, which is the sign to fix the names.

04

Reading the result

Output lineWhat it meansWhat to do
out of order: reveal after settleA reveal landed in a later slot than the settle of the same matchRead the program's state checks before you read anything else
failedThe transaction carried an error and changed nothing beyond its feeLook for a later success on the same match account
otherA successful transaction that matched no phase nameCheck the log text your program prints
unavailablegetTransaction answered null for a listed signatureSkip it and keep your own event table
call failedThe fetch itself erroredRun again; a 429 clears when its cells refill

A match with a commit and a settle but no reveal is the one to watch. Either the player never revealed and the crank settled on a timeout path, or the reveal sits in a part of the history this run did not reach. Raise the limit or page back with the before field before you decide.

For a scoring audit, take the reveal's slot and the settle's slot, then compare the settle against the oracle account's update in between. The script gives you the signatures to start from. If your game also pays out from a pool, Game prize pool tracker covers the money side.

05

Cost of a run

Calls are charged in cells. One run makes 11 calls, and the 10 getTransaction calls are 500 of the 550 cells.

CallCells eachCalls per runCells
getSignaturesForAddress50150
getTransaction5010500
Total-11550

getSignaturesForAddress runs at 0.24, 1.2, 100 and 500 requests per second on Free, Dev, Business and Pro, and getTransaction at 0.24, 1.2, 5 and 25. A rate class absorbs bursts up to 1,024 cells, so one run fits inside the burst on every plan. The two methods sit in separate rate classes, so a run spends 500 cells of the getTransaction burst and 50 of the getSignaturesForAddress one. On Free, two runs in a row fit. A third straight after them goes over, waits once for cells to refill and then gets a 429 with a retry-after hint.

Free is $0 with 500K credits once, at sign-up. Dev, Business and Pro run $20, $250 and $500 a month for 10M, 50M and 200M credits, as listed on the plans. Audit on a schedule or on new activity, and avoid a tight polling loop.

06

Auditing as matches land

A WebSocket subscription on wss://services.carbium.sh, with ?api-key= in the URL, tells you when a run is worth making. logsSubscribe with a mention of the program streams the logs of every transaction that includes it. Each notification names a signature, so the audit can fetch that one transaction and update only its match account.

A logs-mention subscription opens at 25 credits, then 20 credits per MiB sent. A refused subscription costs nothing. Free carries 5 sockets, so open one socket per service and sort by match account on your side. A busy game can send a lot of logs, and the per-MiB charge follows the volume you receive.

07

Where it ends

  • The script checks order and outcome. It does not check that a commit hash matches its reveal, that the oracle price was fresh, or that the score is right. Those rules live in your program, and only its tests and an audit of its code can vouch for them.
  • Matching on log text depends on the program printing its instruction names. A program that logs nothing, or logs different text, needs a decoder for its instruction data.
  • Two steps in one slot are not ordered by this script. A same-slot reveal and settle needs the instruction index inside the transaction or the block's own transaction order.
  • History comes from an address index that keeps up to 30 days. An empty page past that is the index's age limit, and the address may have older transactions. A listed signature can still come back null from getTransaction, so keep your own record of each match for a permanent trail.
  • The script reads 10 transactions. A program with many matches in flight needs paging, and a notification feed beats re-reading the head of the list.
08

When it goes wrong

what goes wrongwhat to do
Every successful transaction prints as other and no match is labelled.The phase names do not match your program's log text. Print one transaction's log lines, copy the instruction names it logs and pass those as the second argument.
getTransaction answers -32015 for a recent signature.Pass maxSupportedTransactionVersion: 1 with an encoding. With the value absent or 0, mainnet answers -32015 for a v1 transaction.
getTransaction returns null for a signature that getSignaturesForAddress just listed.Treat null as unavailable and carry on. The index reaches below the validator's ledger floor, so older signatures can list without a transaction behind them. Record each step yourself as notifications arrive.
A match shows a reveal and a settle but the script reports no order problem even though it looks wrong.The two landed in one slot, which the script never flags. Fetch the block or read the instruction index to see which ran first.
A third run straight after two others returns 429 on a Free key.On Free, getTransaction runs at 0.24 requests per second and its class holds a 1,024-cell burst. One run spends 500 of those cells, so two runs fit and a third does not. Space the runs out, or audit only the transaction a log notification names.
09

Questions

Can the audit show that a player could not change their shot after the reveal started?

It shows that no commit landed after a reveal on the matches it read. The program's own checks make the guarantee, and a clean audit is evidence that those checks held on those matches.

Why group by match account and not by player?

Commit, reveal and settle all write the match account, while the settle comes from a crank's key and not the player's. The match account is the one thing all three steps share.

Does a permissionless crank make the audit harder?

The settle's signer varies, so the audit does not use it to pair steps. It reads who settled only to show how many different parties run the crank.

Do I need a WebSocket for this?

No. A scheduled run of the script is enough for a report. The subscription helps when you want each match checked soon after it settles, at 25 credits to open plus the per-MiB charge.