Bitcoin Forum
August 03, 2025, 11:01:13 PM *
News: Latest Bitcoin Core release: 29.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Question about mining difficulty and leading zeros  (Read 237 times)
sz.xph (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 10, 2024, 09:06:27 PM
 #1

 So i understand that the difficulty is adjusted every 2016 blocks with regards to how fast the blocks were mined previously, and to my best understanding it is done by increasing or decreasing the number of leading zeros that has to be contained in the block's hash.

However, one thing is not clear to me and i wanna bring an example.

At block 850.000 (2024-06-29) the difficulty was 83,6 trillion. The block’s hash is 00000000000000000002a0b5db2a7f8d9087464c2586b546be7bce8eb53b8187.

At block 874.152 (2024-12-10) the difficulty was a bit above 103 trillion. The block’s hash is 00000000000000000001262c8ad33d784be82d12082825ef9f98fe6683d65ad6.

The increase is 23,2%. Yet, in both cases the leading number of zeros in the block’s hash is 19. So how was the difficulty adjusted when the leading zeros didn’t change?

Mia Chloe
Hero Member
*****
Online Online

Activity: 784
Merit: 1284


Contact me for your designs...


View Profile
December 10, 2024, 09:26:12 PM
Merited by vapourminer (4), mikeywith (4), ABCbits (2), hosemary (2), JayJuanGee (1), hugeblack (1), DdmrDdmr (1)
 #2

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.

sz.xph (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 10, 2024, 09:56:02 PM
 #3

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?
hosemary
Legendary
*
Offline Offline

Activity: 2842
Merit: 6313



View Profile
December 10, 2024, 09:56:13 PM
Merited by vapourminer (4), mikeywith (4), JayJuanGee (1), ABCbits (1), hugeblack (1), DdmrDdmr (1)
 #4

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.

CLOUDBET
▀██████▄██████████████▐███████▌██████████████▄██████▀
▀████████████████▌█████████████▐████████████████▀
▀█████████▐█████████████████████████▌█████████▀
▐█████▌████████████▐█████▌████████████▐█████▌
█████████▐█████▌██▐█████▌██▐█████▌█████████
█████████▐█████▌███████████▐█████▌█████████
█████████▐█████▌███████████▐█████▌█████████
█████████▐█████▌███████████▐█████▌█████████
█████████▐█████▌██▐█████▌██▐█████▌█████████
▐█████▌████████████▐█████▌████████████▐█████▌
▄█████████▐█████████████████████████▌█████████▄
▄████████████████▌█████████████▐████████████████▄
▄██████▀██████████████▐███████▌██████████████▀██████▄
█████████████████████████████
 

 
WELCOME     
OFFER
█████████████████████████████
█████████████████████████████
 
 
  PLAY NOW  
pooya87
Legendary
*
Offline Offline

Activity: 3892
Merit: 11824



View Profile
December 11, 2024, 01:57:52 PM
Last edit: December 11, 2024, 02:35:01 PM by pooya87
Merited by vapourminer (4), hugeblack (4), hosemary (4), mikeywith (4), JayJuanGee (1), DdmrDdmr (1)
 #5

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.
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.

Quote
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.
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.

Now my only question is that where can i find the target hash for each block?
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).

mikeywith
Legendary
*
Offline Offline

Activity: 2674
Merit: 7016


Privacy is not a crime.


View Profile
December 11, 2024, 06:09:04 PM
Merited by hugeblack (8), vapourminer (4), pooya87 (4), hosemary (4), JayJuanGee (1), DdmrDdmr (1), DYING_S0UL (1)
 #6

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.

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.

The maximum difficulty would be about 2^224, that is unrealistically huge, and the current 90T diff is a tiny fraction of that.

I think it would make sense when you understand what a target is, target is what the logic is built on, we store the target in the block header and not the difficulty, the difficulty is just an easier representation of the target, so mining becomes more difficult when the target is smaller and vice versa, so as silly as it sounds, when you see difficulty goes up, it simply means target went down.

So an easy target would be infinity, which means anything that you guess below infinity would be valid, a difficult target would be 0, which means there is nothing smaller, the lower the target goes the smaller the number of valid hashes.

The current target is
Code:
00000000000000000003255b0000000000000000000000000000000000000000
in decimal (more human-readable format) that is
301319254070149585548971905645948786445483268317904896   


The target in the previous epoch was

Code:
000000000000000000033d760000000000000000000000000000000000000000
in decimal
310338180674118587457206844748640968959780028040609792

Notice that the target in the previous epoch was larger (difficulty was lower).

to make things a lot clearer, here is the target of the first block Satoshi mined
Code:
00000000ffff0000000000000000000000000000000000000000000000000000
in decimal
26959535291011309493156476344723991336010898738574164086137773096960

now since Difficulty= maximum target/given target, if you apply that on the first block it would give you  difficulty of 1 (target was too huge, difficulty was too low, you basically guess anything and get a block Cheesy), apply it for the current target and you get 89T

Now if you read the post I quoted in my previous reply, you would understand how it's easier to hash a number that has less leading zero than more, i.e, it's easier to find larger numbers than smaller ones, think of it this way, you have a box that has an infinite number of pieces of paper ranging from 1 to infinity, I tell you if you manage to pick any piece of paper that is smaller than 1000000000000000000000000000000000, I 'l give you the prize, that would certainly be easier than if I told you the number you need is smaller than 10 because then there would be only 9 chances out of the infinite numbers in the box.

I know it's easier to understand difficulty than to understand the target, but really, if you don't understand the target, there will always be missing pieces in your comprehension of how this works, now when you say high share, it's actually a small target share which then translate to a high diff share.

So if you are required to find a number smaller or equal to 1000 and you find 1, then that's a very small target which is a very high diff, so when you see blocks getting a high share they technically found a hash a lot smaller than they had to win a block, so the smallest the target can be would be a 256-bit number, which is just right above 0, so when you ask how high share can be, it can be as high as 2^224.


░░░░▄▄████████████▄
▄████████████████▀
▄████████████████▀▄█▄
▄██████▀▀░░▄███▀▄████▄
▄██████▀░░░▄███▀▀██████▄
██████▀░░▄████▄░░░▀██████
██████░░▀▀▀▀▄▄▄▄░░██████
██████▄░░░▀████▀░░▄██████
▀██████▄▄███▀░░░▄██████▀
▀████▀▄████░░▄▄███████▀
▀█▀▄████████████████▀
▄████████████████▀
▀████████████▀▀░░░░
 
 CCECASH 
 
    ANN THREAD    
 
      TUTORIAL      
sz.xph (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 13, 2024, 06:30:56 AM
 #7

I understand the concept now. Thank you for your answers everyone, im really grateful
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!