How is problem calculated? – Bitcoin Stack Change

0
53


Meni’s reply is nice. I simply wish to give some sensible element methodology about problem calculation, maybe useful for future views of this query’s reply.

Let’s check out Satoshi’s genesis block header (a part of associated information):

$ bitcoin-cli getblockhash 0
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

$ bitcoin-cli getblockheader 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
{
  ...
  "peak": 0,
  ...
  "bits": "1d00ffff",
  "problem": 1,
  ...
}

As we are able to see above, the genesis block has a ‘1’ problem and ‘1d00ffff’ bits. The bitcoin bits means the ‘goal’ hash worth, the brand new generated block should meet a situation: block header’s double SHA-256 hash worth should lower than this ‘goal’ worth.

The ‘1d00ffff’ bits worth in genesis block means the ‘goal’ worth:

[0x00000000,0xffff,{0x00..0x00}]
                   {0x00..0x00} at above has 26 bytes 0x00.

Then, to discover a new block, you could search that 32 bits nNonce worth (and nTimes and the hashMerkleRoot additionally) till the block hash worth has 4 bytes zero main.
By the best way, the nNonce is likely one of the fields in block header construction:

struct header_structure{            // BYTES   NAME
    uint32_t nVersion;              // 4       model
    uint8_t hashPrevBlock[32];      // 32      earlier block header hash
    uint8_t hashMerkleRoot[32];     // 32      merkle root hash
    uint32_t nTime;                 // 4       time
    uint32_t nBits;                 // 4       goal
    uint32_t nNonce;                // 4       nonce
};

As a result of SHA-256 algorithm (in addition to any cryptographically safe hash algorithm) produces output that can seem like an uniformly random sequence, the sensible ‘trial and error’ methodology is the one method to discover a new block to fulfill the situation. The chance to discover a block with the 4 bytes zero main hash worth is 1/(2^32), which means the typical ‘trial and error” numbers are precisely 2^32 (i.e. 4G).

For human straightforward understanding about this ‘goal’ hash worth, We outline the time period ‘problem’, which implies the typical ‘trial and error” numbers to discover a block to fulfill the ‘goal’ situation. And we outline the ‘problem’ unit:
1 ‘problem’ = 4G hashes

Then, until at the moment, the bitcoin blockchain peak attain 501509, let’s check out its header:

$ bitcoin-cli getblockheader 0000000000000000006c5532f4fd9ee03e07f94df165c556b89c495e97680147
{
  ...
  "peak": 501509,
  ...
  "bits": "18009645",
  "problem": 1873105475221.611,
  ...
}

The block 501509’s bits = 0x18009645, it is the compact format of 256 bits integer, its 256 bits format is:

[0x00000000,0x00000000,0x009645,{0x00..0x00}]
                                {0x00..0x00} at above has 21 bytes 0x00.
that's  0x009645 * (256 ^ 21) 
The genesis block's goal is  ( 0x00ffff * 256 ^ 26 )which is the issue unit '1.0'.
So, the issue 
= (0x00ffff * 256 ^ 26)/ (0x009645 * 256 ^ 21)
= 65535/38469 * (256^5)
= 1.703579505575918 * 2^40
= 1873105475221.611

Up to now, you might have all of the element about tips on how to calculate the ‘problem’.
In some circumstances, we additionally use the easy format 1.7T to say the issue, in above instance:

(1.703579505575918 * 2^40) = 1.703579505575918T
1T = 2^40 = 1024^4

LEAVE A REPLY

Please enter your comment!
Please enter your name here