inicasino.netContents

On-chain games · 11 / 23

On-chain randomness and who can influence it

A program on a public blockchain has no private memory and no dice. Every random number it uses comes from somewhere outside its own state, and each source has someone who sees it first.

Diagram that pairs each item with its counterpart. Block data, commit-reveal and VRF oracles, with the party that can influence each: Data of a block that already exists; Data of a later block; Operator commit-reveal; Commit-reveal combined with later block data.; VRF through an oracle.
Block data, commit-reveal and VRF oracles, with the party that can influence each.

Why this is hard

Every node that validates a block runs the same program on the same inputs and must reach the same result. A program therefore cannot hold a secret seed, and it cannot call a random function that returns something different on each node. Whatever it uses has to be data that all nodes agree on.

Sources of randomness and who can influence them
SourceHow it is usedWho can influence itWhat they can do
Data of a block that already existsThe program reads a recent hash while it executesAnyoneThe value is public before the bet is sent, so the outcome can be computed first and the bet sent only when it wins
Data of a later blockThe bet names a block that does not yet exist and its hash decides the resultThe producer of that blockSees the value first, can change it by changing the block's contents, and can decline to produce the block
Operator commit-revealThe operator commits to a secret before the bet and reveals it afterwardsThe operatorKnows its own secret and may leave a round unsettled
Commit-reveal combined with later block data. This is the kind of design the publisher of this site uses for its own games; see the Solana section below.The result is a hash of the operator's secret and a value from a later blockThe operator and that block's producerThe producer sees the block value first and can still change it by changing the block's contents or skipping the block, though without the operator's secret it cannot tell which result it is choosing. The operator knows the result as soon as the block exists, before it settles, and can leave the round unsettled. The two acting together can predict and select results.
VRF through an oracleAn outside service signs an input with a secret key, and the program verifies the proofThe oracleKnows the output as soon as it knows the input, and can delay or withhold it. Depends on how the key is kept.

No row is free of a party that can at least withhold, and that includes the publisher's own row. Designs differ in who that party is, what it would gain, and what the protocol does when a value never arrives.

Is a block hash random?

A block hash looks random and passes statistical tests. The trouble is who knows it and when. For a past block, everybody does. For a future block, its producer does before anyone else.

Ethereum's EIP-4399 puts numbers on this for the randomness value that chain exposes to programs. It says the mechanism “gives every block proposer 1 bit of influence power per slot”: a proposer can publish its block or skip it, and so choose between two outcomes at the price of the skipped block's income. It advises applications to rely on future randomness “with a reasonably high lookahead”. The point carries over to other chains. Block data is cheap to read and never free of the producer's influence, so the stakes it decides have to be small next to what a producer would give up.

VRF explained simply

A verifiable random function is a keyed hash with a public key. RFC 9381 describes it in those terms: only the holder of the secret key can compute the output, and anyone with the public key can verify that it is correct. For one key and one input there is a single valid output, a property the RFC calls uniqueness, so the key holder cannot pick among results. The RFC notes that for its RSA-based variant this holds only when the key was generated honestly.

Two conditions sit outside the mathematics. The input must be something the key holder could not choose or see early enough to act on. And the result has to arrive: a key holder that dislikes an output can still fail to deliver it, so the protocol needs a rule for that case. The comparison with commit-reveal schemes goes through the differences.

Solana and the SlotHashes account

Solana divides time into slots, and one validator, the leader, produces the block for each slot. The network keeps a system account named SlotHashes at the address SysvarS1otHashes111111111111111111111111111. The validator documentation says it “contains the most recent hashes of the slot's parent banks” and that it “is updated every slot”.

A slot hash is a different value from the blockhash that a transaction carries. Solana's confirmation guide defines a blockhash as the last Proof of History hash for a slot, and transactions use it as a timestamp. An explorer shows the blockhash in a transaction's details. The slot hash has to be read from the SlotHashes account or from the program's own logs.

A game can use the hash of the slot in which a bet landed as an input that did not exist when the bet was signed. The account holds recent entries only, so the value has to be recorded while it is still there. The leader of that slot is the party who sees the value first, and since the hash depends on the block's contents, the leader is also the party who could alter it. A design that mixes this value with an operator's committed secret, which is what the publisher of this site does in its own games, needs both of them to cooperate before anyone can predict a result. It does not stop the leader from altering the value blindly, and it does not stop the operator, who knows the result once the block exists, from leaving a round unsettled. Such a design has to state what happens to a round that is never settled.

What to check in an on-chain game

List diagram. What to check in an on-chain game: Which inputs enter the result, and when each one becomes fixed and…; Who sees the result first, and what that party can do other than…; What the program does with a round that is never settled, and…; Whether the program can be changed, and by…
What to check in an on-chain game
  1. Which inputs enter the result, and when each one becomes fixed and visible.
  2. Who sees the result first, and what that party can do other than publish it.
  3. What the program does with a round that is never settled, and whether such rounds are counted in public.
  4. Whether the program can be changed, and by whom. The page on audit reports explains how to look.
  5. Whether you can recompute a round from a transaction. The page on reading a Solana transaction walks through it.

A round you can recompute shows how that round's number was made. It does not show the odds, the operator's share or whether the program will be the same tomorrow. The general list is on the page about what provably fair leaves open.

Questions people ask

Can validators manipulate on-chain randomness?

A block producer can influence any value derived from its own block. It sees the value first, can alter the block's contents and can skip the block. How much that matters depends on what the producer would gain compared with what skipping costs.

Is a VRF oracle free of these problems?

It removes the block producer's influence over the value and adds reliance on the oracle: on how its key is kept, and on its delivering every result, including the ones that are unwelcome to someone.

Why can a program not just hash the current time or block number?

Those values are known to everyone before the transaction is sent. A caller can compute the outcome first and send the bet only when it wins.

Sources

How we checked: statements about a named body link to that body's own page and carry the date we read it. Numbers in worked examples are computed by the site's build from the formulas shown, with routines covered by its test suite.