Technical Science Series|Why Is It Difficult to Obtain Random Numbers on The Blockchain?
As we advertised, ZKCHAOS is not only an anonymous transaction protocol, but also a fair game platform. In addition to explaining layer2 and zero-knowledge proof, we will also try to explain the technical logic of the game in the series of technical science articles. Now let’s talk about the key factor of fair game, random numbers, and explain why it is difficult to obtain random numbers on the blockchain.
First of all, we need to answer what is a random number? Simply put, random numbers are unpredictable numbers. For example, you must have played a coin toss game and you can’t accurately predict whether the above is a word or a pattern until the result is announced. This is a kind of randomness, but it is difficult to apply this method to the computer. No one is sitting in our computer and throwing coins.
Many times, our computer will collect chip noise, user’s unconscious operation (such as the sliding of the mouse) and so on as random seeds, and then use algorithms to make this seed longer and larger.
In your computer, you can easily convince yourself that this number is unpredictable. However, in the world of blockchain, decentralization makes things more complicated. In order to maintain consistency, the blockchain is designed to be a completely deterministic system, and deterministic input will bring deterministic output. This certainty makes it difficult for the blockchain system itself to produce random numbers. The general method is to upload the random number generated off-chain to the blockchain. This brings up another problem that it is difficult to prove to others that the number you provide is chip noise or unconscious operation.
Most of the random numbers on the blockchain now use the Hash promise method, which generate a random number off-chain and record it on the blockchain after the hash function operation, and then display the number when needed. It’s like when you go to a bar to play dice with others, you just cover the dice cup first. This only ensures that the source of the number will not be replaced, but it does not guarantee fairness.
Therefore, when using random numbers, we need to use the Hash function again. Use the pre-prepared dice in the dice cup as a seed, and choose as many other seeds as possible, such as the address of the smart contract, the public key of the player participating in the game, the price of ETH at the time, etc. After using these seeds to perform a hash function operation, you can get a relatively fair random number. And the more seeds that participate in this Hash operation, the fairer the random number obtained will be.
When you participate in a fair game on ZKCHAOS, the random numbers used are generated by this principle, so you don’t have to worry about whether the game is really fair. More detailed game settings will be announced in the rules statement when the beta version is launched. Let’s wait and see.