I get that the mining difficulty tweaks every 2016 blocks based on how quickly the previous ones were mined. From what I understand, this is all about changing the number of leading zeros that a block's hash needs to have.
But there’s something that’s got me puzzled.
For instance, at block 850,000 (on June 29, 2024), the difficulty was around 83.6 trillion. The hash for that block is 00000000000000000002a0b5db2a7f8d9087464c2586b546be7bce8eb53b8187.
Then, at block 874,152 (on December 10, 2024), the difficulty jumped to just over 103 trillion. The hash here is 00000000000000000001262c8ad33d784be82d12082825ef9f98fe6683d65ad6.
So, while the difficulty increased by 23.2%, the number of leading zeros in both hashes stays at 19. How does that work if the leading zeros didn’t change?
Mining Difficulty and Leading Zeros Explained
6 replies 130 views
SwiftMinerSenior Member
Posts: 259 · Reputation: 1036
#2Oct 15, 2021, 03:07 PM
Op you have a point however I think you are kind of mixing things up. the target hash is actually a 256-bit number that determines the difficulty and it's calculated based on the previous block's hash and the difficulty adjustment.
The number of leading zeros in the block hash is actually kind of an indirect indicator of the difficulty A higher difficulty means a lower target hash which in turn means more leading zeros are required in the block hash. However, the number of leading zeros is not actually a direct measure of the difficulty.
In your example, the number of leading zeros actually remained the same but the difficulty increased.This is actually because the target hash decreased, making it more difficult to find a block hash that meets the particular target. That simply means the number of leading zeros didn't change because the target hash didn't decrease enough to require more leading zeros.
Thank you for your answer, now it makes sense, and i think i get it.
Now my only question is that where can i find the target hash for each block? So where do i find the target hash value which had to be greater than the hashes of the 2 blocks in my example?
To add to Mia Chloe's reply:
The target in block number 850,000: 000000000000000000035d250000000000000000000000000000000000000000
The target in block number 874,152: 00000000000000000002b5630000000000000000000000000000000000000000
If you compare the block hashes, you will see that they are both below the target.
Target is a number not a hash. It is also calculated not based on previous block's hash or hashes but based on the time it took to mine the past 2016 blocks. Basically if we are at 2016 block height interval (height % 2016 == 0) we take the timestamp in the header of the last block and the block 2016 block-deep. If the difference is more than 2 weeks the difficulty is increased, otherwise decreased.
It is best to not think about number of leading zeros at all when talking about difficulty and target because it has no significance. We compare the block's hash interpreted as a number with the target (as a number). If it were smaller than or equal to the target, that block has a valid proof of work.
If you use number of zeros it can have exceptions:
3 > 2 (00000011 > 00000010) while they both have equal number of leading zeros in an 8-bit binary. If the target were 2 and block hash were 3, this block would be rejected.
In the case of opposite meaning if target were 3 and block hash were 2, that block would be valid because [00000010 <= 00000011] is true.
The target is included in each block's header as it is mined. In the 80-byte block header structure (the byte array starting from index 0) it is the bytes 72 to 75 (a 4 byte integer in little-endian order).
More so the last 2015 blocks, there is a bug in the code (not fixed to date) that ignores the first block of each epoch.
Allow me to quote myself in my attempt to explain target vs difficulty, I think reading that along with what the other members explained above would clear any confusion.
I understand the concept now. Thank you for your answers everyone, im really grateful
Related topics
- Bitcoin mining difficulty jumps 7.6% to new record as hashrate increases 10
- Understanding the Impact of Difficulty on Mining Efficiency 1
- Check Out Our Unique VR Tour of a Bitcoin Mine | Meet Verakari Mining 0
- mining info on bitcoin.org needs an update 3
- Eco-Friendly Mining: Exploring Solar-Powered Bitcoin Opportunities 9
- Need some guidance for my thesis on Bitcoin mining 14