Difference between revisions of "Target"

Line 16: Line 16:
  
 
===How is the target stored in blocks?===
 
===How is the target stored in blocks?===
Each block stores a packed representation in its block header (called hello) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:
+
Each block stores a packed representation in its block header (called [[Block hashing algorithm|bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:
 
  0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000
 
  0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000
  

Revision as of 14:19, 10 January 2020

See also: Difficulty

The target is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 hash of a block's header must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more difficult it is to generate a block.

It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again.

The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.

Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.

Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block.

The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners.

It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.

How is the target stored in blocks?

Each block stores a packed representation in its block header (called bits) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:

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

Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.

What is the maximum target?

The maximum target used by SHA256 mining devices is:

0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Because Bitcoin stores the target as a floating-point type, this is truncated:

0x00000000FFFF0000000000000000000000000000000000000000000000000000

The maximum target is the target used in the Genesis Block and represents a difficulty of 1.

Since a lower target makes Bitcoin generation more difficult, the maximum target is the lowest possible difficulty.

Related Links

See also Difficulty