<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Fairdrum</title>
    <description>The latest articles on DEV Community by Fairdrum (@fairdrum).</description>
    <link>https://dev.to/fairdrum</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4255271%2F2eccfc27-0133-4a7b-a663-c8e4350a1c3c.png</url>
      <title>DEV Community: Fairdrum</title>
      <link>https://dev.to/fairdrum</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fairdrum"/>
    <language>en</language>
    <item>
      <title>Verifiable randomness on Solana without an oracle: commit-reveal with a Merkle root and SlotHashes</title>
      <dc:creator>Fairdrum</dc:creator>
      <pubDate>Fri, 20 Nov 2026 08:36:34 +0000</pubDate>
      <link>https://dev.to/fairdrum/verifiable-randomness-on-solana-without-an-oracle-commit-reveal-with-a-merkle-root-and-slothashes-16ng</link>
      <guid>https://dev.to/fairdrum/verifiable-randomness-on-solana-without-an-oracle-commit-reveal-with-a-merkle-root-and-slothashes-16ng</guid>
      <description>&lt;p&gt;Disclosure: I work on FAIRDRUM, the project this scheme was built for. The code below is from our public checker, published under the MIT licence.&lt;/p&gt;

&lt;p&gt;A game that settles on a blockchain needs a random number that nobody can know or choose in advance: not the player, not the operator. The usual answer is an outside randomness service. That adds one more party to trust, one more fee and one more thing that can be down.&lt;/p&gt;

&lt;p&gt;This article describes a scheme that needs nothing outside the Solana network itself. It is running on mainnet, and at the end you can check a real round with twenty lines of JavaScript.&lt;/p&gt;

&lt;p&gt;Two halves of one number&lt;/p&gt;

&lt;p&gt;The random value of a round is a hash of two inputs:&lt;/p&gt;

&lt;p&gt;value = SHA-256( "fairdrum-round-salt-v1" || secret || salt )&lt;br&gt;
secret is chosen by the operator and committed to the program before the bet.&lt;br&gt;
salt is the value the network records for the slot that carried the bet. It does not exist until the bet is in a block.&lt;/p&gt;

&lt;p&gt;Before the bet the operator knows the secret and nobody knows the salt. After the bet the salt is public and the secret can no longer be changed. Nobody holds both halves at a moment when they could still act on it.&lt;/p&gt;

&lt;p&gt;Committing to a million secrets with one hash&lt;/p&gt;

&lt;p&gt;Writing a fresh commitment for every round would cost a transaction per round. Instead the operator generates a list of 1,048,576 secrets (2^20), builds a Merkle tree over them and writes only the 32-byte root into the program.&lt;/p&gt;

&lt;p&gt;leaf = SHA-256( 0x00 || index (u64, little-endian) || secret )&lt;br&gt;
node = SHA-256( 0x01 || left || right )&lt;/p&gt;

&lt;p&gt;The 0x00 and 0x01 prefixes keep a leaf from being passed off as an inner node. The index is part of the leaf, so a secret is bound to its position.&lt;/p&gt;

&lt;p&gt;Every bet takes the next index in order, and the program records which root was active. At settlement the operator reveals the secret together with its Merkle proof: 20 sibling hashes. The program walks the proof, compares the result with the recorded root, and only then computes the value.&lt;/p&gt;

&lt;p&gt;js&lt;br&gt;
import { createHash } from "node:crypto";&lt;/p&gt;

&lt;p&gt;const sha = (...parts) =&amp;gt; {&lt;br&gt;
  const h = createHash("sha256");&lt;br&gt;
  for (const p of parts) h.update(p);&lt;br&gt;
  return h.digest();&lt;br&gt;
};&lt;br&gt;
const u64le = (n) =&amp;gt; {&lt;br&gt;
  const b = Buffer.alloc(8);&lt;br&gt;
  b.writeBigUInt64LE(BigInt(n));&lt;br&gt;
  return b;&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;// Root reached from a revealed secret and its proof (sibling hashes, bottom to top)&lt;br&gt;
export function rootOf(index, secretHex, proofHex) {&lt;br&gt;
  let h = sha(Buffer.from([0]), u64le(index), Buffer.from(secretHex, "hex"));&lt;br&gt;
  let i = BigInt(index);&lt;br&gt;
  for (const sib of proofHex) {&lt;br&gt;
    const s = Buffer.from(sib, "hex");&lt;br&gt;
    h = (i &amp;amp; 1n) === 0n ? sha(Buffer.from([1]), h, s) : sha(Buffer.from([1]), s, h);&lt;br&gt;
    i &amp;gt;&amp;gt;= 1n;&lt;br&gt;
  }&lt;br&gt;
  return h.toString("hex");&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// The number every outcome of the round is derived from&lt;br&gt;
export function roundValue(secretHex, saltHex) {&lt;br&gt;
  return sha(&lt;br&gt;
    Buffer.from("fairdrum-round-salt-v1"),&lt;br&gt;
    Buffer.from(secretHex, "hex"),&lt;br&gt;
    Buffer.from(saltHex, "hex"),&lt;br&gt;
  ).toString("hex");&lt;br&gt;
}&lt;br&gt;
Where the salt comes from&lt;/p&gt;

&lt;p&gt;Solana keeps a system account called SlotHashes. For each recent slot it holds the hash the network recorded for that slot. The program reads the entry for the bet's slot from that account itself and accepts no value from whoever sends the transaction.&lt;/p&gt;

&lt;p&gt;Two details matter in practice:&lt;/p&gt;

&lt;p&gt;A bet and its settlement cannot share a slot. The hash of the bet's slot exists only once the next slot has started, and the program rejects a same-slot settlement.&lt;br&gt;
SlotHashes is not the "blockhash" an explorer shows. It is the slot's bank hash, so the two values differ. If you check a round by hand, read the SlotHashes account, or take the value from the settlement's own event.&lt;/p&gt;

&lt;p&gt;SlotHashes keeps a slot for a few minutes only. So the first step after a bet is to seal the round: record the slot's hash in the round's account. Anyone may send that transaction.&lt;/p&gt;

&lt;p&gt;What if the operator does nothing&lt;/p&gt;

&lt;p&gt;Only the operator knows the secrets, so only the operator can settle. A scheme like this has to say what happens when it does not:&lt;/p&gt;

&lt;p&gt;A round that is neither sealed nor settled within a few minutes can be closed by anyone, and the stake is refunded in full.&lt;br&gt;
A sealed round whose secret is still not revealed after about 24 hours is refunded in full.&lt;br&gt;
A round settled later than about 20 minutes after the bet pays ordinary prizes and takes no part in the jackpot draw. Without this rule the operator could look at the outcome first and delay only the rounds it dislikes.&lt;/p&gt;

&lt;p&gt;Every refund increments a public counter in the program.&lt;/p&gt;

&lt;p&gt;A real round&lt;/p&gt;

&lt;p&gt;Here is a round settled on mainnet on 19 November 2026:&lt;/p&gt;

&lt;p&gt;secret  f221d16862b7775bcb3c05c8b239faa05d101219c52b617c89a109090b56fe19&lt;br&gt;
salt    cb72e80dca5a27e375997bfe3aa1061da805f6a7b1007d9a105742ae69c58bd7   (slot 471,370,228)&lt;br&gt;
index   195&lt;br&gt;
root    cd9a329f4f7d897d8907332f6dbf2ab589ffa8df3b0e39d3a5f16817d805e9bc&lt;br&gt;
js&lt;br&gt;
roundValue(&lt;br&gt;
  "f221d16862b7775bcb3c05c8b239faa05d101219c52b617c89a109090b56fe19",&lt;br&gt;
  "cb72e80dca5a27e375997bfe3aa1061da805f6a7b1007d9a105742ae69c58bd7",&lt;br&gt;
);&lt;br&gt;
// 596ea9246dac9ac73d970d48baa74d96f30b16828d8f3fcb64593e1bd8192aca&lt;/p&gt;

&lt;p&gt;That is the round number the program recorded. The settlement transaction, which also carries the Merkle proof, is:&lt;/p&gt;

&lt;p&gt;5UtsEXy5RoQsX4KvWTKyn5x9zFhDqKDBevGYLAVHKdmPjE8JcGHCF3y4BoKF49o2zPGdXCtMHaUrG4Wc9aGNvktw&lt;/p&gt;

&lt;p&gt;The checker reads everything from that one transaction:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
git clone &lt;a href="https://github.com/fairdrum/fairdrum-verify" rel="noopener noreferrer"&gt;https://github.com/fairdrum/fairdrum-verify&lt;/a&gt;&lt;br&gt;
cd fairdrum-verify&lt;br&gt;
node verify.mjs --tx 5UtsEXy5RoQsX4KvWTKyn5x9zFhDqKDBevGYLAVHKdmPjE8JcGHCF3y4BoKF49o2zPGdXCtMHaUrG4Wc9aGNvktw --rpc &lt;/p&gt;


&lt;p&gt;It has no dependencies and needs Node.js 18 or newer. The program also publishes the inputs of each settlement in an event, so the same tool recomputes the prizes of the round and compares them with what the program credited.&lt;/p&gt;

&lt;p&gt;What this scheme does not give you&lt;/p&gt;

&lt;p&gt;It is worth being exact about the limits.&lt;/p&gt;

&lt;p&gt;The producer of the bet's block sees the salt first and can influence it by choosing what goes into the block. Alone that predicts nothing. An outcome can be known in advance only by someone who holds both halves: the holder of the secrets acting together with the producer of that very block. Block producers follow the network's public schedule and change every few slots; the scheme does not exclude such cooperation.&lt;br&gt;
The operator decides whether a round is settled. The refund and late-settlement rules above limit what that is worth, and every case is counted on-chain.&lt;br&gt;
A verified round says the outcome was fixed fairly. It says nothing about the odds, the operator's share, or whether the program can be upgraded. Those are separate questions with separate answers.&lt;br&gt;
If a node cuts the transaction log, the events are gone and the round cannot be recomputed from that transaction. Treat such a round as unverified.&lt;br&gt;
Why bother&lt;/p&gt;

&lt;p&gt;One 32-byte write commits a million rounds. Settlement is a single transaction that carries its own proof. The player needs no account with a third party, and a check needs nothing except the transaction and SHA-256.&lt;/p&gt;

&lt;p&gt;The contract's source is at github.com/fairdrum/fairdrum-program and the checker with tests and diagrams at github.com/fairdrum/fairdrum-verify. The same check runs in the browser on fairdrum.to/verify.html.&lt;/p&gt;

&lt;p&gt;If you see a hole in the scheme, I would like to hear about it: open an issue in the checker's repository.&lt;/p&gt;

</description>
      <category>solana</category>
      <category>blockchain</category>
      <category>cryptography</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
