3

If you want to start a private net with Geth, then you need to create a Genesis Block. You specify the attributes of this block through a config file. One of these configurations is 'difficulty'.

An example I've seen is this: "difficulty": "0x0400".

My question is, what does this number represent? From what I've gathered, it means set the target such that there's a 1/1024 chance in finding a hash that meets the target.

1
  • I am having trouble understanding something related to this. Target difficulty is described as 2^256 / difficulty . The difficulty of the genesis block is notated as 0x0400 which is equal to 1024. So if we take 2^256: (115792089237316195423570985008687907853269984665640564039457584007913129639936) and divide by 1024 we get : 113078212145816597093331040047546785012958969400039613319782796882727665664 Then we have the block hash for the Ethereum genesis block: 0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3 If you convert this hexadecimal into decimal/integer value it is: 96
    – Poseidon
    Commented May 4, 2022 at 6:58

1 Answer 1

4

The difficulty value here is the reciprocal of the probability that the hash for mining the first block is "good" and that the block gets included in the blockchain. For example, in the Ethereum main net, this value is 0x400000000, or 17179869184 in decimal. So about one in 17179869184 hashes lead to a valid block. If the total hash power of miners is 1717986918 hashes per second (one tenth of the genesis block's difficulty), then it would take about 10 seconds to mine a block.

The value was set much higher than you would use for a private net because there was projected to be a lot more competition for mining main net Ethereum at the very beginning than most/all private chains to date would see.

If the genesis block's difficulty is too low for a decentralized set of miners with relatively high latency, the effects of "instamining" (blocks found very quickly) would lead to extreme blockchain forking. This is not a problem on a private network with one computer or very few computers in a higher-latency environment; forking is less of an issue (or not at all on one computer) and the automatic difficulty retargeting should readily adjust the difficulty so as to avoid future forking. Setting this value too high means it would take considerable time to mine the first several blocks before the difficulty retargeting algorithm makes block times more reasonable.

Otherwise, this difficulty is no different from the difficulty of any other block.

3
  • 1
    Thanks, lungj. So if this is the reciprocal, then we're saying there's a 1 in 1024 chance of getting the hash of a block such that it gets included in the blockchain. Correct?
    – Bastien
    Commented Jul 20, 2017 at 14:46
  • Yes, you were correct in your initial post. I've updated my answer to be a bit clearer on that front.
    – lungj
    Commented Jul 20, 2017 at 14:49
  • Is it only for Ethash algorithm or for clique as well? Does difficulty affects clique algorithm as well?
    – NinjaMAN
    Commented Mar 31, 2021 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.