Nonce As Simplest Component Of Block
Each block in blockchains is a complex union of different components. These components represent various technological solutions and are intended to solve different tasks. Still, their combination leads to a single goal, which is ledger prolongation.
The whole block content includes standard components, such as a standard start-bit sequence in the block (Magic no), block size, block header, and transactions. Transactions take the biggest part of a block. Their structure is quite simple. They consist of a payment source, payment destination, inputs and outputs, etc. All complex components related to block functions are placed in the header. There are several hashing results, block version, timestamp, complexity, and nonce. This last component is one of the simplest, yet it is very important. Let’s examine it in detail.
What is nonce?
The origin of the “nonce” term is simple. It is a shortening from “number used once”. Simply saying it is the counter incremented under certain conditions. Obviously this counter is used once during some action it is intended to. The nonce is not only used in Bitcoin. For instance Ethereum has two different nonces used in blocks and accounts of both kinds.
Nonce in Bitcoin
The main goal of nonce in Bitcoin is to bring randomness, which is crucial for mining. As we know, mining requires multiple recalculation of the block content. If a hashing result satisfies requirements, mining is successful. Unfortunately, it is hard to get a correct hash result in a single try.
According to Bitcoin rules, an average time of block closing is 10 minutes. This means that all network participants generate one block in 10 minutes regardless of how many hashing facilities are involved. The block has to be recalculated many times. A block with the same content gives the same hash result — thus, we need to change it. There are only a few components that can be changed: transactions, timestamp, and nonce.
The problem is that changes have to be as small as possible to reduce recalculation time. This makes transactions substitution inefficient because of the necessity to recalculate the Merkle tree. A timestamp may have an influence on the choice of the right block in the case of simultaneous mining. Thus, it should not be changed too often. This leaves nonce as the only appropriate option. Changing nonce every time when an unsatisfactory block hash is calculated is the best choice.
Nonce in Ethereum
Ethereum uses nonce in two different ways. The first implementation is similar to Bitcoin. Nonce is a standard component of Ethereum blocks. The second application concerns multiple transactions of a single account. According to the Ethereum glossary, an account nonce is a simple counter of transactions. It is used to strengthen the state change protection and prevent multiple spending attacks.
Nonce for mining pools
Another important implementation area of nonce is the mining pool workload distribution. Each mining pool should avoid multiple calculations of a single block by several participants at the same time. This can be performed in several ways. The pool coordinator can avoid sending timestamp to participants, send different transactions sets to different participants, or give nonce ranges to different participants.
The first approach is risky because all pool members are working around the same time. The second approach requires a lot of extra work performed by the pool coordinator. Thus, the last approach is the most efficient.
By taking “nonce” as an example, we can clearly see that even the simplest component of crypto projects performs significant functions. Removing a nonce would instantly lead to the need to solve many problems without an effective solution being prepared.