1

This is not a duplicate of previous, similar questions I've read on StackExchange, since none of those questions, nor the answers, go into the difficulty theory, as espoused on the Bitcoin Wiki.

Basically, I'm trying to calculate the number of attempts a miner needs to find a hash less than the target difficulty, through using some of the technical docs' on the Bitcoin Wiki. Hence, my answer is based on examples on that Wiki, but some of the explanations there are somewhat ambiguous. For example, I'm uncertain if the writer means difficulty1Target (they use difficulty_1_target), or difficulty 1. Therefore, I would be grateful if someone much more knowledgeable than I could run through my reasoning and also check my answer at the end.

The difficulty is calculated thus:

difficulty = difficulty1Target / currentTarget

Where target is a 256-bit (32-byte) number and difficulty1Target represents a hash where the leading 32 bits are zero and the rest are one. That is known as pool difficulty or pdiff. Floating point targets with limited precision allow clients to approximate difficulty. Such approximations are known as bdiff.

Each block stores a packed representation of the hexadecimal target. Supposing a target of 0x1b0404cb, the hexadecimal target is:

0x0404cb * 2^(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000

Where 0x0404cb is a signed value. The largest legal value for that field is 0x7fffff and the smallest value is 0x008000.

The highest possible target, difficulty1Target, is defined as 0x1d00ffff. That gives a hexadecimal difficulty target of:

0x00ffff * 2^(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000

Pooled mining often uses non-truncated targets, giving a difficulty1Target of:

0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Hence, the bdiff difficulty at 0x1b0404cb is given by:

0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x00000000000404CB000000000000000000000000000000000000000000000000 = 16307.420938523983

And the pdiff difficulty is:

0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF / 0x00000000000404CB000000000000000000000000000000000000000000000000 = 16307.669773817162

The following formula shifts the target difficulty so that it is offset against the difficulty1Target:

0xffff * 2^208

And to offset for difficulty D, we have:

(0xffff * 2^208)/D

Since a calculated hash to test against the target will be a random number between 0 and 2**256-1 (SHA-256 is a 256-bit value), for any given difficulty D, the algorithm for estimating the average number of calculations needed before finding a solution, is as follows:

D * 2^256 / (0xffff * 2^208), or just D * 2^48 / 0xffff [@BitcoinWiki_Difficulty_2018].

Hence, the estimated number of calculations needed to find a hash given the bdiff difficulty at 0x1b0404cb is:

16307.420938523983 * 2^48 / 0xffff = 7.0040908e+13

Many thanks!

2
  • Possible duplicate of How many hashes create one Bitcoin?
    – KappaDev
    Oct 3, 2018 at 22:21
  • That question, nor the answers, go into the theory regarding difficulty targets, so this is not a duplicate. Having said that, I like, very much, one of the answers that use the published hash rate. Nice!
    – glowkeeper
    Oct 4, 2018 at 13:13

0

Your Answer

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