For some reason I was re-reading a particular section in a book called Mastering Bitcoin by Andreas M. Antonopoulos (http://chimera.labs.oreilly.com/books/1234000001802) and came across this paragraph:
This means that a valid block for height 277,316 is one that has a block header hash that is less than the target. In binary that number would have more than the first 60 bits set to zero. With this level of difficulty, a single miner processing 1 trillion hashes per second (1 tera-hash per second or 1 TH/sec) would only find a solution once every 8,496 blocks or once every 59 days, on average.
It seems innocent enough and I thought to myself, let me try the numbers to get 59 days. It’ll be a 10 minute job and I can then get on with my life.
Unfortunately, it didn’t quite work that way. I ended up getting some help from Stack Exchange and it was very worthwhile as it showed me that I didn’t really understand what the target meant.
How it works
If you follow the section on difficulty representation, there is a formula to derive the target. I even blogged about it here. The issue was that with a target, and with a hash rate, how would you determine duration?
The key point to understand is that the target means you need to find a number from 1 -> 238,348 * 2^176 and there are 2^256 possibilities. Therefore, your chances are (238,348 * 2^176)/(2^256).
This results in 238,348 * 2^-80 or 1.9715 * 10^-19 to 4 dp.
Analogy
You can compare this to rolling a dice. If I gave you a target of 2, meaning you had to roll a number that is 2 or less, your chances are 2 out of 6. So theoretically speaking, if the entire universe was perfectly balanced, all the planets were aligned and the moon was blue, on 6 rolls of the dice, 2 of them would result in a 1 and a 2.
How to get 59?
Once you have this sorted, to get 59 days is easy. To cycle through 238,348 * 2^176 possible values at a speed of 1 TH/s (1 x 10^12) it is a straight multiplication. Then you just convert to a sensible unit by multiplying appropriately.
What about the 60 leading zeros?
If you convert any number between 1 -> 238,348 * 2^176 to hexadecimal, you will discover that you’ll have more than 60 leading zeros which means the target is satisfied.
eg 2^100 = 1267650600228229401496703205376
which in hex is: 0x10000000000000000000000000
Because the target is 256 bits in length, the hex needs to be padded to 64 characters meaning 38 leading zeros. This equates to 152 bits with the value of ‘0’ thereby meeting the requirements of “more than the first 60 bits starting with zero’.