This article provides a more profound review of nonces and how they assist the blockchain in maintaining order while preventing duplicate blocks.
This article assumes the reader understands the information in the following articles:
In most blockchains, there are two types of nonces. One is called an “account nonce,” while the other is a “proof of consensus” nonce—an account nonce functions as a queue for transactions relating to a wallet’s address. The first block added would have an account nonce of 1, and the second block would have the account nonce of 2, counting up continuously. By maintaining the record of account nonces, any system interacting with that chain knows what the next account nonce is to keep this order.
Proof of consensus nonces are numbers calculated to create the desired “next” hash from the current block. After the account nonce is determined, the “previous” hash is recorded, and transactions are written; a block needs a “next” hash so the chain may continue. If the “next” hash must start with a specific sequence, such as 0x0000… the only way to achieve this is by adding a number into the block until the generated “next” hash meets the required standard. This generated number is the proof of consensus nonce. When validators use their software to process blockchain transactions, they often do the math necessary to determine the nonce of a block so it may be added to the chain. Once the math to achieve the correct nonce is complete, validators that found the next block are generally rewarded with the blockchain’s cryptocurrency.
Nonces allow for extra security for transactions since no one can make an exact copy of trade for themselves. This is known as a replay attack. In a replay attack, a bad actor will copy an attempted and approved transaction but change part of it in their favor. Because the proof of consensus nonce must be calculated to add the block to the chain, the original must be written first. Once written, the account nonce ensures the transaction is one-of-a-kind and cannot be copied to resend later. Account nonces also prevent duplicate or overlapping transactions, known as double spending, where a user may attempt to resend a transaction several times to spend more than what they have in their wallet. Since there is a unique account nonce for each transaction, it will only accept one and reject the rest when the blockchain sees the same nonce on several attempts. Each transaction is made secure with both account nonces for uniqueness and proof of consensus nonces to sign hashes and protect blocks from replay attacks.