What is the PREVRANDAO system
The PREVRANDAO System in Ethereum
The term PREVRANDAO refers to a specific change implemented in the Ethereum protocol following The Merge, which transitioned the network from Proof-of-Work (PoW) to Proof-of-Stake (PoS) .
Function and Purpose
PREVRANDAO is the new name and function for the old DIFFICULTY opcode (0x44) .
- Randomness Source: Post-Merge, the
DIFFICULTY opcode was updated and renamed to PREVRANDAO .
- Output: The
PREVRANDAO opcode returns the output of the randomness beacon provided by the beacon chain .
- Use Case: This opcode serves as a stronger, though still biasable, source of randomness for application developers to use compared to the older
BLOCKHASH opcode .
- Implementation: This change was formalized in EIP-4399 .
Technical Details
The value exposed by PREVRANDAO is stored in the ExecutionPayload .
- Storage Location: It is stored in the field that previously contained
mixHash, a value associated with PoW computation .
- Field Renaming: The payload's
mixHash field was also renamed to prevRandao .
- Execution Payload: The
ExecutionPayload structure includes PrevRandao as a 32-byte field .
Before The Merge, the 0x44 opcode returned the difficulty field in the block header. After The Merge, the opcode, renamed to PREVRANDAO, points to the header field that now stores the prevRandao value from the beacon chain state .