1

So, I understand how the amount of leading 0's are calculated, but how is the hexadecimal that come after the leading 0's calculated? For example, the previous mined blocks hash was 000000000000000000084bc771b929b0780276b1c31cec10a96921b1e53b970a but how was the 84bc771b929b0780276b1c31cec10a96921b1e53b970a after the 0's determined?

I saw this answer: https://bitcoin.stackexchange.com/a/36228/110284 but I'm not gonna lie, I didn't understand it.

2
  • @PieterWuille Unfortunately not because I was under the impression that 3 of the variables (Time, Nonce, and Merkle Root) change or are not present before the block is completed. I thought the Time continues ticking until the block is successfully mined, the Nonce constantly iterates until the correct nonce is found, and the Merkle Root is the hash of all the transactions that occur in that block. So how can the Target Hash for a block be created from those values if the values constantly change prior to the blocks completion? – L M Feb 10 at 4:15
  • @L M I think I see your confusion. I retracted my close vote, and wrote an answer. – Pieter Wuille Feb 10 at 4:38
2

There are two values in play here, and the way your question is phrased makes me think you're confusing them.

Every block has:

  • A hash (computed by double-SHA256 the block header, including timestamp, nonce, version, Merkle root, nBits which encodes the difficulty, and previous block hash)
  • A target (computed from the difficulty only)

000000000000000000084bc771b929b0780276b1c31cec10a96921b1e53b970a is the hash of block number 669945. Just feeding the block's header exactly to double-SHA256 gives you this output (including the zeroes up front). It gets interpreted as a number:

  • 0x000000000000000000084bc771b929b0780276b1c31cec10a96921b1e53b970a (in hex, with zeroes explicit)
  • 0x84bc771b929b0780276b1c31cec10a96921b1e53b970a (in hex)
  • 794600089940753232651370066465976921098309156434843402 (converted to decimal)

The target is the maximum allowed value that hash must have to satisfy the proof-of-work requirement. It is determined entirely by the difficulty(*) (which on its turn is determined by the timestamps of the previous blocks in the chain it is built on). That difficulty is also stored in the block header itself as the "nBits" value. The nBits value for block 669945 is 0x170d21b9; it encodes 0x0d21b9 · 2560x17 - 3, which equals:

  • 0x0d21b900000000000000000000000000000000 (in hex)
  • 1257769770588612382309009370720465882998915202417688576 (converted to decimal)

Since 794600089940753232651370066465976921098309156434843402 (the actual hash's value) is less than 1257769770588612382309009370720465882998915202417688576 (the target value), proof-of-work is valid for this block. And of course it is; if it wasn't, you would never have heard about this (attempted) block candidate.

(*) Technically speaking, the term "difficulty" is only used for representing how hard a block is for human consumption. Internally only nBits and the full target value are ever used. Difficulty is defined as 0xffff·25626 / target. The lower the target, the harder it is to find a block whose hash is below it, and thus the higher the difficulty is.

2
  • 1 question, what do you mean by encodes 0x0d21b9 · 256^0x17 - 3? I understood everything else and it was very helpful, but just confused about that part. Not sure where you go the 0x0d21b9 and 256^0x17 - 3 from. – L M Feb 10 at 5:09
  • That's just how nBits works. If nBits = 0xABCDEFGH, that encodes the target value 0xCDEFGH * 256^(0xAB - 3). I don't know where or how Satoshi came up with it, but that's the definition. – Pieter Wuille Feb 10 at 5:17
2

I think you're confusing a few things.

A SHA-256 hash is a single value that is 64 hexadecimal characters long. This hash can be seen as simply a very long number.

A target hash in cryptocurrencies is the maximum value that a successful block hash should be. Miners are aiming to generate a block where the hash, when seen as a large number, is a smaller number than the target hash.

The entire thing 000000000000000000084bc771b929b0780276b1c31cec10a96921b1e53b970a is a block hash. It is a SHA256 hash, and just happens to be a number that contains a lot of zeroes.

If you want to see how the block hash is calculated, take a look at this article: https://en.bitcoin.it/wiki/Block_hashing_algorithm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.