Commit-reveal on Solana
Commit-reveal is a two-step scheme: first a fingerprint of a secret is published, and later the secret itself is revealed. At FAIRDRUM the hash of the bet's block is added to the secret, and the smart contract computes the round number from that pair.
Commit-reveal in one paragraph
A commit-reveal scheme lets you lock in a value in advance without showing it. First the hash of the value is published: that is the commit. Later the value itself is published: that is the reveal. Anyone can compute the hash again and see that the value has not changed.
- The houseCommit. A fingerprint of all round secrets is recorded in the contract before the bets.
- YouBet. It lands in a block of the Solana network. The hash of that block becomes the second part of the round number.
- ContractReveal. The secret is published in the settlement transaction. The contract checks it against the fingerprint and settles the round.
Build the scheme yourself
The tool repeats every step on a practice tree of 8 secrets. The formulas are the same as in the contract.
The tool makes practice secrets from the word. Real round secrets are 32-byte values. Secret numbers start from zero, as in the contract. The tool runs in your browser. No wallet or bets are needed. The units here are practice chips with no value.
Step 1. A fingerprint of every secret
A leaf is the SHA-256 of the secret's index and the secret itself. The secret cannot be recovered from the leaf.
| Number | Secret | Fingerprint (leaf) |
|---|---|---|
| 0 | 613ffae561d4892d… | aa74227d94486540… |
| 1 | ece2a57820445db8… | 64a3f42202556945… |
| 2 | bd183d8d77ffc8b6… | 395cfd90e032ffb8… |
| 3 | f0dcdb349c3eedf2… | aa1ec3ffe5183237… |
| 4 | ced4a9979ab050c7… | ec4cfa2556182d85… |
| 5 | 1b74ec4e8158ad33… | 25e42a2c7c757cfe… |
| 6 | 1fdf87cc320d8207… | 6fc4dddcdb105e02… |
| 7 | 879c5507d0b064f5… | 87279230c51ffb0c… |
Step 2. Commit: the tree and the root
Neighbouring fingerprints are joined in pairs until only one is left. That is the root. It is recorded before the bets.
9adf4a41eaf4604a2f0131bd6f19aa74164a32395c3aa1e4ec4c525e466fc478727rootnodes from the revealed secret up to the rootsibling nodes: the path
Root: 9adfd66fc0f737bb5cb5be138c716db29199ff32126e14b592d5c24171c6f6c2
Step 3. Revealing secret number 5 and checking it
Secret presented: 1b74ec4e8158ad332a1837d44aad8770c4ed9a1e8604d85d40021a58805615f7
Path to the root, 3 nodes: ec4cfa2556182d85… → 6f19406234985859… → 4a41e5eac40d7eb1…
Root from the secret and the path: 9adfd66fc0f737bb5cb5be138c716db29199ff32126e14b592d5c24171c6f6c2
The recomputed root equals the root recorded before the bet. The contract accepts this secret and settles the round.
Step 4. The round number
Hash of the bet's block: 3627276c1bb174e0cad3bba3c331a4003042817678190840267892674e3309c4
Round number: f78add45117f3edf8a5bcb5fde76f949d6ac214e4817a64a7c71a306244751bc
The commit is one fingerprint for many secrets
Recording a fingerprint of every secret in the contract separately would be expensive. So the fingerprints are assembled into a Merkle tree. Its top, the root, is a single hash 32 bytes long. It depends on every secret and on its number.
The root is recorded in the contract before the bets. At the moment of a bet the contract writes into it the number of the next secret in sequence and the current root. From that moment the round's secret is locked in, although it has not been published yet.
The bet lands in a block that does not exist yet
The secret's fingerprint is recorded in the contract before the bet. The contract takes the second part of the round number later: it is the hash of the block the bet landed in. At the moment of the bet that block does not exist yet, and nobody knows its hash in advance.
The contract does not allow a round to be settled in the same block: the block hash is not ready yet. Settlement comes in a separate transaction. The smallest round on the site is 0.1 SOL, which is 10 bets of 0.01 SOL. There is one round number for the whole round.
Formula. Round number = SHA-256("fairdrum-round-salt-v1" + secret + block hash). What happens to this number next is shown on the page “From hash to result”.
At the reveal the contract checks the secret
The settlement transaction brings the round secret and the path from it to the root. The contract recomputes the root itself and compares it with the one recorded in the bet. The contract will not accept any other secret.
In the same transaction the contract computes the payout and publishes the RoundRevealed event: the secret number, the root, the secret and the hash of the bet's block. This data is enough to repeat the check in a browser. The “Verify a round” page does it for any round, yours or someone else's.
If settlement does not arrive in time
A round has a deadline. If there is no settlement within that time, the contract refunds the bet in full to the game balance. Any participant of the network can close such a round.
Every refund increases the contract's public counter. The number of refunds over all time is shown on the status page. The deadlines are listed on the “Contract” page.
What is known and when
Locked in by the root in the contract, not published
The block does not exist yet
Nobody knows it in full
The secret number and the root are recorded in the bet
Determined by the bet's block
Determined, not yet published
Published in the settlement transaction
Published in the same place
Anyone can recompute it
The player cannot back out of a round after the bet: settlement does not need a second signature from them.
Commit-reveal, a VRF oracle and a server seed
| Scheme | Who provides the randomness | What is visible on the network | What a round depends on |
|---|---|---|---|
| The operator's server seed | The operator and the client seed | Usually nothing: settlement happens on the operator's server | The operator shows a hash before the bet and reveals the server seed afterwards |
| VRF, a verifiable random function | An external provider of random numbers | A request for a number and a reply signed by the provider | The provider answers a request; its public key is known in advance |
| A secret in advance plus a block hash (FAIRDRUM) | A secret created in advance and the hash of a Solana block | The root before the bets; the secret, the block hash and the payout in the settlement transaction | Settlement arrives in time; otherwise the bet is refunded |
The table does not rank the schemes. It shows what exactly the player can check on their own in each of them.
What the scheme shows and where to look for the rest
The scheme answers one question: is the revealed secret the one that was locked in before the bet. Other questions are answered by other public data.
- Odds and prizes. The tables of all 16 games are on the page “Odds in all games”.
- The price of play. About 7% of bets goes to the project. In detail: project's share and return.
- The reserve for payouts, and refunds. Both are shown on the status page from network data.
There has been no external audit. Whether the program's source code has been published, and where, is stated in this place when the page is opened with scripts enabled. How the contract is built is described on the “Contract” page.
Questions
What is a commit-reveal scheme?
It is a way to lock in a value in advance and reveal it later. First the hash of the value is published, then the value itself. The hash is computed again, and you can see the value has not changed. At FAIRDRUM this is how round secrets are locked in.
Why add the block hash?
The secret's fingerprint is recorded in the contract before the bet. The block hash appears only together with the block the bet landed in. Until that block exists, nobody knows the round number in full. That is why the result cannot be computed before the bet.
What happens if a round is not settled in time?
The contract refunds the bet in full. The refund goes into the contract's public counter: the all-time number of refunds is shown on the status page.
Is a VRF oracle better than commit-reveal?
They are different ways of getting a number, and they are checked differently. With a VRF oracle the player checks the signature of an outside provider. In the scheme with a secret and a block hash the player checks that the secret matches the root recorded before the bet. What matters is that you can repeat the check yourself.
What is a Merkle root, in one sentence?
It is a single hash that locks in many values at once: any of them can later be presented and checked along a short path without revealing the rest.
Can the project pick a secret to suit my bet?
No. The secret number is the bet's sequence number, and the contract counts it. The number and the current root are written into the bet at the moment of the bet. At settlement the contract accepts only the secret that matches this root under this number.
Read on
18+. On average players get back less than they bet. Play only with SOL tokens you are prepared to lose.