When developing smart contracts for Ethereum, it is usually considered that it is unreliable to rely on the block hash as a source of randomness, as the miner can influence the result by selecting the block hash (see Private Information and Randomness , how? )
How great is actually the opportunity for the miner to increase his chances of winning the game in which you need to guess the hash of the block with a certain number (or a certain number produced by the hash of the block)?
The probability to guess a random number in the range from 0 to 9 is 1/10
Suppose for simplicity that the block hash is also a number from 0 to 9.
That is, suppose we get a number from 0 to 9, depending on the hash of the block, or in other words we give the hash of the block to a number from 0 to 9.
For example:
function blockHashToNumberFrom0to9(uint blockNumber) public view returns (uint){ uint random_number = uint(block.blockhash(blockNumber))%10; return random_number; }
Suppose I am a miner with such computing power that every 5th block in the network is mine by me, i.e. my chances are i'm going to mollify the next block 2/10.
For example, one of the largest pools (see https://etherscan.io/stat/miner?range=1&blocktype=blocks ), found a way for all pool members to agree on a total lotto rate, and try to influence the result. In this case, of course, it is necessary to neglect the possible loss of income from mining.
Let's say I made a bet, and I want to influence the result.
If I just zamanyu block with a random hash, it does not affect the result, but suppose I, having calculated the first possible block, reject it, and the next blocks until I find the right one. What are my chances that I will find two valid blocks with different hashes faster than the rest of the network will block the block (one) for this block number?
My chances to find two blocks in a row: 2/10 * 2/10 = 4/100
What are the chances that my second unit will be exactly the one I need?
We reason as follows:
Chances that the same number will fall out 1/10 * 1/10 = 1/100
The chances that another number will fall out 1-1 / 100 = 99/100
Chances are that this number will turn out to be the one that is needed 99/100: 9 = 11/100
The chances that these events will coincide, that is, that I will find two blocks in a row before the rest of the network finds one and my second block will be the one I need: 4/100 * 11/100 = 44/10000
So, picking up the block myself, I increase my chances in the game by 44/10000:
0.1 + 0.0044 = 0.1044
In other words, my chance of winning instead of 10% will be 10.44%
Chances are that I will find the third valid block earlier than the rest of the network will find one and this block will turn out to be the one I need, etc. are calculated in the same way: we add the odds in which the probability is displayed in fraction the numerator of which will be more by one, and the denominator is more by tens, this will not increase the probability by more than 1/10000, in other words, when rounded to two decimal places, it will be the same number: ~ 10.44%
For a player who mines every 10 blocks in the network: ~ 10.11%
However, we proceeded from the fact that: "My chances are that I will find two valid blocks with different hashes faster than the rest of the network will block the block (one) for this block number? 2/10 * 2/10 = 4/100" This is the probability that in general, two blocks in a row will be found by this miner. The likelihood that this will be done faster than the rest of the network will find one - even less.
Accordingly, if the result is specified not by the hash of one block, but say by hashes of a certain number of consecutive blocks (say, we implement the 5 out of 36 lotto, where 36 two-digit digits are obtained from 72 consecutive blocks hashes), then the miner’s ability to influence the result is even less. Thus, if we take hashes of several consecutive blocks as a source of randomness, the chances of a single miner to influence the result are so small that in most cases they can be ignored, even if we are talking about the cash prize (ETH).
It would be interesting to have the opinion of the community how correct this argument is.
UPD:
It seems to me an important point .
Source: https://habr.com/ru/post/345904/
All Articles