8

Currently, target is stored in each block. Why is that? Why it is not simply computed by each client based on the previous timestamps from previous blocks? Why it has to be stored within the block?

In other words, doesn't allowing miner to choose the target remove that it is exponentially harder to create a new block? Other miners might have to mine 256 consequent blocks, but I have only to be lucky once and get one block with 8 more zeroes to replace those 256 blocks. While it is less probable, it grows linearly (256x less probable) and not exponentially.

1 Answer 1

9

You're presenting it as a choice between either allowing miners to choose the difficulty, or having it be implied by previous history.

In fact, neither is true. The target is determined by history (for the reasons you bring up), and the target stored inside the block header has to match the value determined by history.

At this point, there is no good reason for this anymore, and a design from scratch could IMO drop the nBits value from the header.

I don't know the original reason, but my guess is that it allowed for stronger contextless validation of block headers. Before version 0.10, Bitcoin Core did not use headers-first synchronization, and thus often did not have all parent headers available when a particular block was being received. Being able to verify that the block has valid PoW (even though the difficulty might be wrong) was a very valuable mechanism for preventing DoS attacks.

6
  • Sorry for beating the dead horse. May I know why there's no more reason to include the target in each block? Thanks
    – Viet
    Commented Oct 24, 2017 at 17:46
  • Name me a reason why it would be needed? Commented Oct 24, 2017 at 19:33
  • Sorry, I'm new to this so I'm sitting on the fence and trying to understand how removing the target improves the current design. I didn't mean to challenge or question your judgement. Thanks.
    – Viet
    Commented Oct 25, 2017 at 9:19
  • 1
    I didn't mean to offend, and didn't say it improves the design - it's just unnecessary now. You're asking why is it no longer needed. I explained why it used to be needed (contextless validation of headers) and why that doesn't apply anymore (headers-first synchronization since 0.10). The only (known) reason it was needed is gone, so it's not needed anymore. Commented Oct 25, 2017 at 9:27
  • 1
    Could you please reference the code which validates the target to match a correct difficulty. I can't find it. I can only see that nodes check the range of the target value. github.com/bitcoin/bitcoin/blob/master/src/pow.cpp#L74 Commented Apr 3, 2018 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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