Kleros is as a pioneering platform for decentralized dispute resolution. Jurors are randomly selected to rule an arbitration, with the chances of being chosen proportional to the amount of tokens staked. At the core of Kleros' juror selection is randomness -- this is to keep the selection process fair and transparent.
At present, the selection of jurors relies on random numbers derived from the blockhashes of Ethereum blocks. Although it's impossible to foresee these values, miners have the option to withhold a block if the resulting random numbers are not to their advantage, at the cost of losing a block reward. To create random numbers that are impervious to manipulation by large miners, the Verifiable Random Function (VRF) service provided by Chainlink can be a solution.
VRF is a cryptographic function that generates pseudorandom numbers based on data input and provides a proof, which anyone can verify. Here's a simple explanation of how Chainlink's VRF contracts work and integrate with Kleros:
Chainlink's Coordinator contract generates a
preSeedusing a fixed algorithm based on the parameters of Kleros' random number request. It also records theblockNumberof the current transaction and then sends thepreSeedas the content of an event log to Ethereum.After ChainLink Oracle detects the event log, it retrieves the
preSeedfrom the log. It can also obtain theblockHashof the block containing the previous step's transaction (It's important to note thatblockHashcan only be obtained after the block is mined. In the contract, it's not possible to get the current block'sblockHash, onlyblockNumber. This is why the Coordinator contract in the previous step can only recordblockNumber, notblockHash).After a specified number of block confirmations, ChainLink Oracle uses its private key to generate a proof with parameters including the
preSeedandblockHash, and then submits this proof back to the Coordinator contract.The Coordinator contract verifies the proof. Since
blockNumberwas recorded in the first step, the contract can now use the functionblockHash(blockNumber)to get the historical block'sblockHash. TheblockHash, along with thepreSeedgenerated by itself, is used to verify the proof submitted by ChainLink Oracle.If the verification is successful, a tamper-proof parameter from the proof (
proof.gamma) is used as the seed for random number generation. The VRF contract will then serve the random number to Kleros contract in a fallback function.
The reason that VRF can generate unpredictable random number primarily lies in the use of two factors:
blockHash, which is unknown before a block is confirmed by miners and becomes determinable only after it has been packed.The proof submitted by ChainLink Oracle, whose corresponding private key is unknown.
If the generation of random numbers relies solely on blockHash as the seed source, miners could potentially manipulate it; similarly, if it relies only on the proof from ChainLink Oracle, the oracle nodes might act maliciously. Therefore, ChainLink VRF ingeniously combines these two sources, ensuring the unpredictability of the random number seed.
For Kleros, looking to optimize its random number generation in juror selection, VRF presents a viable solution.
