1

bitcoin noob here.

I was wondering why is the nonce increased from 0 to n while searching for a blockhash?

Why not start at some other integer > 0 for example?

My background is in ethereum-dev, so I know why the nonce needs to change, but I don't get why from 0 to n?

Thanks in advance.

2 Answers 2

2

It doesn't matter which nonces you test or in what order that other than you need to avoid testing the exact same block header twice (since that would obviously be a waste of time).

It's useful to test all the nonce values since if you don't test them all you will need to update extranonce more often, though not critical.

Even though miners increment their nonces in similar ways this doesn't result in the duplication of work between miners: there are a myriad number of differences between the candidate blocks miners attempt, foremost being where their reward is paid. (And pooled miners that happen to pay to the same place get different extranonce ranges assigned by the pool). As a result there is never any work duplication across miners unless something is embarrassingly broken.

Starting at 0 and incrementing until the maximum value is simply a convenient way to change the nonce that cannot duplicate and minimizes extranonce updates. Many devices assign distinct ranges to different chips, and so don't simply increment in a simple 0 to 2^32-1 manner.

A mining device could save a negligible amount of power by changing using a linear feedback shift register instead of an adder, but no one seems to have bothered with that optimization.

2
  • Thank You for that answer, this was really helpful. But if I'm right everyone races to find a hash < target, and the first one to find such a hash gets the reward. When everyone starts at 0 and with the same extranonce, the one with most calculation-power always is first, right? If I have less calculation-power than other ppl, wouldnt I want to try to "cheat" by not starting at 0 because other ppl would get the reward always? Did I miss something with this assumption? Nov 7, 2018 at 10:39
  • I added a paragraph ("Even though...") to address that question.
    – G. Maxwell
    Nov 7, 2018 at 11:02
-1

Why not start at some other integer > 0 for example?

Why would you? Going from 0 to n where n is the maximum possible value means that the miner will search through all possible values for the nonce. Starting anywhere else and going to n means that some nonce values will be skipped, which means that it is possible to miss the nonce value that will get you a block.

If you wrap around back to 0 when you reach n, then that is no different from going from 0 to n. It's just harder to implement. Going from 0 to n is the simplest to implement and guarantees that you will search through all possible nonces.

1
  • 3
    "means that it is possible to miss the nonce value that will get you a block." That's not how this works. Every nonce has an equal chance of constructing a valid block; the fact that you skip some doesn't affect your chances, as long as you try the same number of candidates per time unit. The right point is that if you reduce the range of nonces, you need to change the extranonce more frequently to reach the same number of candidates per second, which is more work. Nov 6, 2018 at 15:49

Your Answer

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

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