2

I have come up recently with "how to mine bitcoin using python" or "how to mine bitcoin using golang" and as I have been observing all these source code, not only I'm confused but also have some questions.

Some developers using python keep saying that difficulty calculates the leading 0s on the hash which after coming to blockchain explorer I think it is not true as the current difficulty is wayy too high to be leading 0s on the hash which determines that "we mined a block". Also bitcoin wiki of difficulty just explains it plain short.

So how does it treats it? Does the mining software puts difficulty in the hashing algorithm?

10
  • 2
  • @RedGrittyBrick so true man, you are right but I have been said that I shouldn't edit questions once I made one. Tbh that's why I included that edit even after I knew exactly what I wanted to know. Thanks for the link i think it will come in handy. Jul 30 at 16:59
  • Hi thecow milk, our site works best when a topic is focused on one question only. You can find a description of how our site works in our tour. I think that all of your questions have answers on this site separately, see e.g. bitcoin.stackexchange.com/q/8806/5406, bitcoin.stackexchange.com/q/23912/5406, bitcoin.stackexchange.com/q/5838/5406, and bitcoin.stackexchange.com/q/8031/5406.
    – Murch
    Aug 2 at 15:35
  • Please feel free to edit this question to focus on a single topic, if any remain unanswered after you read the linked topics. Please ask additional remaining questions as separate topics. Thank you.
    – Murch
    Aug 2 at 15:37
  • @Murch yea you are right buddy. sorry for asking multiple questions at once but I thought it would clear my thoughts and I will be more careful the next time. I'm pretty confused if I should edit my question because it is stated in the rules that once asked you can't go back because the answers/comments will be irrelevant. I'm requesting to delete this question if possible because it may be misleading in the future. Thanks. Aug 2 at 18:08
2

The difficulty is really a human readable expression. Under the hood, the Bitcoin protocol uses the target. The target is a custom 4-byte float value encoding an exponent and a mantissa that is to represent a number used as the upper bound for the block hash of valid blocks.

The target is updated every 2016 blocks after the last block of a difficulty period has been found. It depends on the timestamps of the first and the last block of the difficulty period and the previous target:

new_target = old_target × (t_last - t_first)/14 days

Every full node that has seen these two blocks can calculate the new target.

Miners assemble unconfirmed transactions into block templates, create coinbase transactions and fill up the remaining header fields to produce block candidates, test each block candidate by hashing its header and comparing the candidate's hash to the target to determine whether a block has been found. The current target since height 693,504 is 0x17136aa2 which is a compact representation for 0x000000000000000000136aa20000000000000000000000000000000000000000. If I counted right, this hexadecimal number would translate to a binary number with 75 leading zeroes. At the current hashrate of about 109.7 EH/s, the network will try about 6.6×1022 block candidates until a block is found.

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.