Gridcoin V8 difficulty and what it tells you

12 days ago

There has been some confusion before and after Gridcoin switched to stake kernel V8 regarding the total amount of coins staking and the probabilities to stake a block. I present some estimates you can calculate from the difficulty provided by the wallet. Keep in mind that these are estimates and staking is a probabilistic process. Therefore the time it takes you to stake a block might very well be different from the estimate.

So at first lets define some variables:

  • blockSpacing=90s, the time between two blocks
  • hash is the hash value calculated by the kernel (proofHash) not the hash value of the block header, with a value between 0 and 2^256 (thanks @tomasbrod for pointing that out)
  • target is a very large number that is altered to make it harder or easier to create a valid hash value, in order to keep the blockSpacing of 90 seconds
  • maxTarget=2^224 is the maximum allowed target value
  • diffis the difficulty to find a valid hash, being defined as diff = maxTarget/target
  • timeMask=16s, the time you have to wait until it is possible to create a new hash value with your coins
  • COIN=100000000 is a constant used for internal calculations since the amount of coins is stored internaly multiplied by this factor
  • nCoins the amount of coins you stake with
  • wTarget=target*(nCoins*COIN/1250000), the weighted target, the more coins you have the easier it is to create a valid hash

So in order to create a block every wallet tries to create a hash value that is smaller than wTarget. It gets easier to find a valid hash with the number of coins you use to stake. But every set of coins is only allowed to create a different hash every 16 seconds. Once you have found a valid hash you are allowed to create the next block. The target value is now altered depending on the time since the last block has been created. If the time is less than 90 seconds it has to become more difficult, if the time is more than 90 seconds it has to become easier.

Probability to stake a block

The probability to stake with one try is:

pb = wTarget/2^256

But since we can try every 16 seconds and the block spacing is 90 seconds we can try multiple times.
From the Bernoulli chain we get the probability to get at least one hit with n tries: p = 1-(1-pb)^n
Now we get the probability to stake a block pbB by replacing n with the number of tries we can do in 90 seconds:

pbB = 1-(1-pb)^(blockSpacing/timeMask)

No if we put in all the variables we get:

pbB = 1-(1-(maxTarget/diff)*(nCoins*COIN/1250000)/2^256)^(90/16) 
    = 1-(1-ncoins/diff*0.0000000186264514923095703125)^(90/16)

You can also replace the 90 seconds value in the equation to get the probability to stake in an arbitrary amount of seconds. For example replace it with 86400 to get the probability to stake within the next day.

Time to stake a block

Since we can create a unique hash every 16 seconds the number of tries equals tries*16 seconds. We are dealing with the geometric distribution in this case. We assume that the probability of finding a block on any one trial to be greater than zero. Now we can view each attempt to create a hash to be independent form each other and it is repeated until the first success. That gives us the average time to stake a block:

t = timeMask/pb

Again putting in all the variables gives us:

t = 16/((maxTarget/diff)*(nCoins*COIN/1250000)/2^256)
    = 16/(nCoins/diff*0.0000000186264514923095703125) 
    = 16*diff/(nCoins*0.0000000186264514923095703125) 
    = diff/nCoins*858993459.2

So if you have a balance of 4000 GRC and the difficulty is 2 you would expect to stake after t = 2/4000*858993459.2 = 429496.7296 seconds = 4.97 days.

Amount of coins staking

Last but not least we can estimate the amount of coins currently staking in the gridcoin network. We can just take the equation from the previous section. But now we solve the equation for nCoins instead of t:

nCoins = (16*2^256*1250000*diff)/(t*maxTarget*COIN)

Now if we set t=90 we get the amount of coins needed to stake every 90 seconds at the current difficulty. If we put in all the variables we get:

nCoins = diff* 9544371.769

If we have a difficulty of 2, there are about 19 million coins currently used to secure the network.
These calculations were not possible before V8 because of the magnitude being involved in the stake mechanism. There has been no way to reliably estimate the amount of coins used for staking. I find it quite alarming that we have such a low stake participation. With only 5-8% of the 394 million total coin supply staking there is a great risk of attacks. We should not only worry about the time it takes new users/users with a low balance to stake a block. But also think about the security of the blockchain. Without a secure blockchain all your efforts to gather Gridcoins become worthless.

Please note that some of these calculations have to be performed for each UTXO(unspent transaction output) separately to be correct.
If you find any errors please let me know and I will fix them.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  trending

Few correction.
What you refer to hash in your article, is not hash of the block header, It is proofHash, calculated by hashing Kernel. If the hash would be hash of header, we would have a PoW coin. Components of the kernel, read Stake V8 wiki article.
Second, are you sure that diff if maxTarget/target, I did not know how the difficulty value was calculated until now.
Your formula for calculating the amount of coins staking will be very useful in next development, especially to calm down @erkan. Please post your formula to Github, so it is not lost!
Thank you for your research, you did a great job!

I find it quite alarming that we have such a low stake participation.

I am glad someone else is finally saying this. When PhilD comes online and stakes his 50,000 GRC POS in a string of consecutive blocks, he makes up well over half of the net weight with his tens of millions of GRC.

Very Value Information - I Didn't Know It Before - Thank You for sharing :)

Very nice information that you bring up with this post! This should go to the Gridcoin Wiki!

https://github.com/gridcoin/Gridcoin-Research/blob/master/doc/stake-miner.txt

  • For version 7 blocks, 1 GRC and 0 Mag equals to 800 of weight.
  • For version 8 blocks, 1 GRC equals to 80 of weight.

Nice! Thanks for sharing the math!
So if I were to plug in my unbelievably large pot of 250 GRC into the time-to-stake equation also at 2 difficulty, it looks like I'll stake in 79.5 days!
And a big thanks to all the people who don't leave their wallets running! ;)