In the “Proof of work,” consensus algorithms are arbitrary sets of numbers, each used only once – these are called a “Nonce.” These Nonces are four-byte fields in a block header, with its value being adjusted by miners to keep the hash of the block equal to or less than the current hash target set by the network.
“Hash: A hash is a function that converts an input of letters and numbers into an encrypted output of a fixed length. A hash is created using an algorithm and is essential to blockchain management.” – Investopia definition
According to the Bitcoin protocol, the formatting of the serialized headers is part of the Bitcoin consensus rules. They are serialized into an 80-byte format then hashed as part of Bitcoin’s “proof of work” algorithm.
An example format of a block header, with the Bitcoin nonce included, is seen below:
|4||Version||The block version number dictates which set of consensus rules to follow.|
|32||Previous block header hash||Including the previous block header hash ensures no previous block can be changed without also changing this block’s header.|
|32||Merkle root hash||The Merkle root derives from the hashes of all transactions included in this block, ensuring that none of those transactions are modified without modifying the header.|
|4||Time||The block time is when the miner began hashing the header. This time must be higher than the median time of the previous 11 blocks. Full nodes on the network will not accept blocks with headers, which are more than two hours in the future according to their computer clock.|
|4||nBits||An encoded version of the target threshold. This block’s header hash must be less than or equal to the target hash value set by the network.|
|4||Nonce||An arbitrary number that miners change in order to modify the header hash and produce a hash that is less than or equal to the target hash value set by the network.|
Bitcoin Nonce & Proof of Work
A distributed network of anonymous peers maintains the Bitcoin blockchain. The individual who adds a block to the blockchain must first go through the proof of work mining process. The miner (the individual who is participating in this mining process) is required to take the data from the block header (input) then run it through the cryptographic hashing algorithm repeatedly. For Bitcoin systems, this is called Secure Hash Algorithm 256 (SHA-256)
Miners hash slight variations of the input data (the nonce) until the hash of the header block is a hash equal to or less than the target hash value that is set by the network. To find such a hash value in the mining process is to find the “Golden Nonce.”
Any bad actor who seeks to modify past blocks would have to work much harder to change ANY previous block. The reason is to change transactions included in previous blocks; this bad actor would have to change all subsequent blocks that came before it. Therefore, the cost to replace blocks increases with each new block added to the blockchain, thereby multiplying the “Proof of Work” process.
The target hash value is known as network difficulty. This feature reveals how difficult it is to find a hash rate that is below the network target hash rate. Network difficulty is altered every 2,016 blocks, depending on how long it took to find the last 2016 blocks. Then calculations are made on the number of seconds it took between the generation of the first and last of those previous blocks. It takes approximately two weeks to mine 2016 blocks. So, should the blocks be found in less than two weeks, the difficulty level increases. On the other hand, if it takes longer than two weeks to discover the 2016 blocks, the network difficulty decreases. Adding new blocks to the blockchain is only done if the hashed value is at least as challenging in difficulty as expected by the consensus protocol.