What does this protect against? And why 4 in particular?
I know an adjustment of this magnitude is not likely to take place at this stage, but I'm wondering why this was implemented in the first place.
You need restrict how much difficulty can change. Imagine if someone managed to forge the timestamps on the block that they were creating, and make it so that it appeared that it only took one second to generate 2016 blocks. Should difficulty then go up by 1209600? Clearly, that would be ridiculous.
On the other hand, you need to make the adjustment flexible enough to adapt to unforeseen advances. 4 is an arbitrary value picked as a compromise between these two requirements.
Difficulty is essentially calculated as ...
difficult adjustment
proportional to actual time / ideal time
From the Bitcoin Wiki's Difficulty article, an example of calculating one of the difficulty values, ie actual time or ideal time:
0x0404cb * 2^(8*(0x1b - 3))
This is essentially k * 2^(8*(0x1b - 3))
, where k
is a constant.
So notice it's exponents we're dealing with, in base 2, ie 2^(a huge number).
Because the loss of precision occurs with way difficulty is expressed, were essentially dealing with ratios of 2^exponent1
/ 2^exponent2
.
So it has to be a multiple of 4, since we're taking ratios of base 2 exponents. Even if the bottom value were 0, so 2^0 = 1, 2^32/2^0, a multiple of 4