Search code examples
blockchainbitcoinnonceconsensus

Is it always possible to find a nonce for target hash?


I was wondering if it is always possible to find a nonce, while mining a block in a blockchain, for the target hash? Because nonce, being max. 32 bits, can only have 2^32 different possible values. What if we don't get our target hash for any nonce?


Solution

    1. Modify the timestamp of a block, here is a practice Ntime Rolling. But it is not that sufficient now since a block will not be accepted if it's timestamp is not in a period(about 3 hours) of time, see timestamp.

    2. Add/remove some transactions or alter the order of transactions as long as they are still in topological order (If transaction A spend one of the outputs of transaction B, then B must precede A in the transaction list)

    3. Change the coinbase transaction. The prevout script of coinbase txinput is an arbitrary byte array of 2 to 100 bytes. This script will not be executed, so you can put any data you want. Note that it has to start with a byte of a correct push of the block height, see bip34.

    So basically you can say it's always possible to find a valid nonce with the combination of all of these above.