The first difficulty adjustment on the network happened at block 32256
. The time for block 32255
(one block before the adjustment) is 1262152739
and the time for block 30239
(2016 blocks before the adjustment is 1261130161
.
The bits
for all blocks up until 32255
is 1d00ffff
, which gives the target 00000000FFFF0000000000000000000000000000000000000000000000000000
. For reference, I arrived at it by doing the following:
% echo "ibase=16; 00FFFF" |bc
65535
% echo "ibase=16; 1D" |bc
29
% echo "ibase=10; 65535 * 2 ^ (8 * (29 - 3))" | bc
26959535291011309493156476344723991336010898738574164086137773096960
% echo "obase=16; 26959535291011309493156476344723991336010898738574164086137773096960" |bc
FFFF0000000000000000000000000000000000000000000000000000
After arriving at the current target, I multiplied it by 1022578
(time it took to mine the blocks from 30239
to 32255
) and then divided by 1209600
(2 weeks in seconds):
% echo "obase=16; 26959535291011309493156476344723991336010898738574164086137773096960 * 1022578 / 1209600" | bc
D86A528BC8BC8BC8BC8BC8BC8BC8BC8BC8BC8BC8BC8BC8BC8BC8BC8B
Now here is where things get confusing for me: from my understanding, the "bits" should be generated by picking up the first three significant bytes from the target, which would be D86A52
and then add the size of the target as the prefix, which would be 1C
(28
in base 10), but
when I retrieve the block 32256
using Bitcoin Core, I get 1d00d86a
for the bits
field.
The difference between the targets would be pretty much irrelevant:
% echo "ibase=10; obase=16; 14182994 * 2 ^ (8 * (28 - 3))" | bc
D86A5200000000000000000000000000000000000000000000000000
% echo "ibase=10; obase=16; 55402 * 2 ^ (8 * (29 - 3))" | bc
D86A0000000000000000000000000000000000000000000000000000
I imagine these types of things happen because there's not a single source of truth for the target value of the network, meaning each node calculates the target independently and as such, these small differences can occur, but because the difference is so small the nodes would just have accepted it if I mined block 32256
using 1cd86a52
as the bits
, but I don't know if this reasoning is correct.
1cd86a52
is invalid because it represents a negative number, but then how do I get to1d00d86a
? – Pedro Martins Timóteo da Costa Nov 11 '23 at 13:310x7f
, I should prepend a zero digit and then the compact form would be1d00d86a
– Pedro Martins Timóteo da Costa Nov 11 '23 at 13:37