Randomness has many uses in science, art, statistics, cryptography, gaming, and other fields. The Cartesi Machine, however, is deterministic and, therefore, can only generate pseudo-random numbers from an initial value, called “seed”. Since the initial machine state is known, it cannot contain the seed, otherwise the entire sequence of random numbers would also be known. The seed must, therefore, be derived from inputs.
A random seed can be generated by a group of participants using a commit-reveal scheme. Ethereum proof-of-stake (PoS) employs a slightly different scheme for randomly selecting block proposers, known as RANDAO. In this scheme, the random number generated by a block proposer is their signature of the current epoch number
n with their own private key. This value is then mixed in (through XOR) with the previous RANDAO value. At the end of the epoch, this value is then used to select the block proposers of epoch
Post-merge, EIP-4339 introduced the
PREVRANDAO opcode, which returns the previous RANDAO value. This EIP also outlined several considerations for application developers that would like to use RANDAO values as a source of randomness for their applications. The main takeaway is that RANDAO values only get more random over time, as random events have more time to interfere: block proposers accidentally missing slots, effective balance fluctuations, validators turning active/inactive, etc. The EIP suggests applications to wait at least 4 epochs, and an additional 2–4 slots for the next RANDAO value.
Solidity 0.8.18 introduced the
block.prevrandao keyword for retrieving the previous RANDAO value.
block.prevrandao to the input metadata schema.
We argue that numbers generated by the RANDAO are a “good enough” source of randomness for most DApps. There are several considerations related to the safe usage of
PREVRANDAO by application developers, which can be found in the resources linked at the end of this text.
High-level frameworks (HLFs) can help developers decode input metadata (to extract the
prevrandao field) and manage delayed “dice rolls” (for the suggested amount of epochs and slots, in terms of blocks).