Skip to content

A Transaction Nonce | The Role and Management of Nonces

Posted on:September 14, 2019 at 03:22 PM

Introduction

Each transaction contains a nonce, which is a counter that can only be processed once, dynamically in a transaction account based on the number of confirmed transactions.

Comparatively, it is used to construct and develop blockchain technology. In general, blockchain platforms use one type of transaction that is known as sending an order using a nonce to recognize that the transaction is being verified and that a block is confirmed. The nonce starts at 0 and increases incrementally for each transaction.

Mathematical Proof of Nonce Ordering

An equation proves that the nonces must be in order by induction. In mathematical induction, let P(k) be a propositional function which may or may not be true for every natural number integer k. It is based on the rule of deduction that P(k) is true for all positive integers k (denoted as Z⁺), if P(1) and for all k, P(k) implies P(k + 1) are true, then for all k, P(k) is true.

As you may know, induction has two parts or cases:

  1. Basis (Initial) Step: I would add a basis step as a privacy step, so the privacy step is to verify that P(k) is true.
  2. Inductive Step: This is to prove the following assertion, which is to verify the conditional statement P(k) implies P(k + 1) is true for all k ∈ Z⁺. If P(k) is true, then P(k + 1) is true.

The Proof Theorem

  1. First, a transaction with nonce P(1) is true.
  2. Then, the miner or validator knows that P(2) is true for the next transaction because P(1) enforces P(2).
  3. Thus, the next transaction must be P(k + 1), which cannot be false.

Thus, when the first transaction holds nonce 1, the second transaction must hold the next larger integer.

Transaction Processing

From sender to miner, each transaction is stored in a queue known as a memory pool in the miners. If the transaction has enough fee and is error-free, and if the nonce is the next in sequence, this transaction gets verified by miners. Then the sender can send the next transaction with a new nonce. An account-based platform such as Ethereum allows the sender to continue transmitting transactions and accept all transactions present in order.

There is no overwritten nonce if a transaction is already verified; however, an overwritten transaction occurs when both transactions have the same nonce and those transactions are pending in the memory pool, and one transaction may have a higher fee than the others. For instance, node A has sent two transactions that have the same nonce; one transaction may get verified, and the others rejected. A nonce value is a unique identifier for a transaction that has to be confirmed in nonce order to avoid double-spending.

Errors with Nonces

Errors occur with nonces in three cases:

  1. Reusing nonce: The same nonce is used on the next transaction.
  2. Duplicating nonce: Two transactions are used with the same nonce from the same account.
  3. Non-sequential nonce: Leaving a gap between nonces will not be processed until the gap is closed; however, if a missing transaction occurs in a gap due to a lower fee on a transaction or if a miner/validator drops it after a timeout, this will cause a non-sequential nonce.

The verification rule does not allow skipping the sequence order of nonces. Additionally, the blockchain platform always tracks accounts’ nonces. Subsequently, all transactions with a lower nonce can never be used again. This prevents sending a transaction that was previously sent and, therefore, is one way of reducing and stopping the opportunity for replay attacks.

Protocol Idea

The idea of the protocol is to ensure that the transaction has been verified and received currently before initiating a new nonce for the next transaction. The protocol obliges and compels the nonce.

For example, node A sends transactions with nonces from 0 to n - 1 in the first N transactions. The nonce is satisfied with equal opportunity on:

N = N_min(t1) + n - 1

where the transaction has N = n - 1 and N_min at the time t1 is 0; where n is the number of transactions that have been verified. If node A sent t1 and if N_min is 0, then the next transaction will be at t2, where:

t2 = N_min(t1) + n

A miner/validator cannot accept or verify a transaction (i + n) until transaction (i) is verified. A new account starts with N = 0 as an initial value. If the sender (from the same account) continues to send more than one transaction at one moment, all transactions can get verified in the order as numbered sequentially, no matter what gas fee the next transaction has.

Analysis of Using This Algorithm in the Inductive Proof

If an account attempts to send 10 transactions per second, 10 blocks must be created. Also, if one account transmits a lot of transactions, those transactions will wait to be confirmed, which evolves over time. This strategy is not very useful for modern transactions because this protocol only uses nonces to provide basic reliability, and the performance is completely slow and has limited possibility.

Suggestions for Improvement

The suggestion is to bring questions to the table to work towards a solution such as a smart memory pool. Validating multiple transactions from one account can be specified and verified by using an axiom system of temporal logic for safety and liveness to be satisfied. Segments contain nonces of line segments s₁, s₂, …, sₙ. This segment is called side size, or space size in geometric theory, as window size, thanks to a Go-Back-N protocol. The previous protocol allows only one transaction to be verified at a time in an account. To allow more than one transaction at a time from the same account, a protocol uses a range of transactions, and each range has a nonce that is known by the miners and the sender as a parameter that determines how many transactions can be sent.

Smart Memory Pool Mechanism

The user can send a segment that contains transactions, and each transaction has its own nonce. It has to ensure that the transferring amount is less than or equal to the account balance, and each transaction has a different nonce in an account. Thus, there are two nonces:

Both count for an account. When a space is filled with three transactions and each transaction contains a nonce, a miner will not accept or verify space (i + N) from an account until the space has been verified.

The space of N contains t transactions, from t to t + n - 1, that the transmitter has sent. This protocol uses a mechanism where a range of transactions can be sent within a space protocol, which keeps track of two integer variables:

The smallest transaction nonce is N_min that has not been verified. The next transaction nonce is N_max to be verified and accepted. This is similar to the previous protocol, but the goal is to allow N_min to N_max - 1. The nonce, N, is sent in the header of the space in each transaction. An account or a smart contract sets the integer variables N_min and N_max to 0. This requires additional functions for rearrangement. The verified transactions must also be able to identify the block with which they are associated. Every address account uses two integer variables, N_min and N_max, to keep track of its operations. The smallest transaction nonce is N_min that has been verified. The next transaction nonce is N_max, which is varied. This is similar to the previous protocol, but the goal is to transmit N_min to N_max - 1.

Conclusion

This article fully explores transaction nonces and their key role in blockchain ordering. Delving into the mathematical proof underscores the need to maintain sequential nonce order to ensure transaction reliability and prevent double-spending and replay attacks. The discussion extends to transaction processing within blockchain systems, highlighting common nonce-related errors and their implications on network integrity.

The proposed protocol demonstrates an innovative approach to improving transaction processing by enabling multiple transactions to be processed concurrently. Through detailed protocol implementation logic validation, the article shows a deep understanding of blockchain technology’s theoretical and practical aspects.