2

I do a sort of bitcoin 101 presentation for folks where I work. In one of the recent sessions, someone asked why the proof of work difficulty requires a minimum number of leading 0s. Why not 1s or something else?

Not understanding the math behind it in-depth, the best answer I can come up with is that the protocol requires that the proof of work hash (hash of nonce and block data) should be equal to or lower than the difficulty target. Hence, you can interpret it as having to contain a certain number of leading 0s.

Is there a better explanation?

Thanks!

7

Not understanding the math behind it in-depth, the best answer I can come up with is that the protocol requires that the proof of work hash (hash of nonce and block data) should be equal to or lower than the difficulty target. Hence, you can interpret it as having to contain a certain number of leading 0s.

This is exactly what it is. The actual calculation has nothing to do with leading 0s. It's entirely just a comparison of integers, which has the effect of producing leading 0s.

3
  • 5
    I think the explanation with "number of zeroes" has a historical reason: hashcash, the original PoW system, had a "difficulty" that was actually the number of zero bits up front in the hash. Bitcoin's proof of work is based on it, but generalized to a big integer comparison. Aug 8 '21 at 22:45
  • @andrew-chow thank you for your answer. Say if difficulty target was 0F in hexadecimal. Then the PoW hash could be anything between 00 to 0E. In this case the number of leading 0s required is 1, but that is not sufficient. The second number needs to be between 0 and E inclusive. Is this correct?
    – septerr
    Aug 8 '21 at 22:59
  • 2
    Correct. Even the earliest instances of the code pay no attention to the number of leading 0s and really have the requirement of being smaller than a given target. Here's a code snippet of how hash target was adjusted (it was effectively multiplied by the ratio of actual time taken over the time desired by satoshi) -- github.com/bitcoin/bitcoin/blob/…. Here's a code snippet where the comparison was actually made -- github.com/bitcoin/bitcoin/blob/…
    – Randy
    Aug 9 '21 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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