What is Nonce? | CryptoWallet.com

What is Nonce?

Nonce (number used only once) is an important part of digital security and verification used across a range of different network applications. But what does it mean in crypto? This number represents the culmination of a rather technical process in cryptography, that when successfully completed, rewards the miners for their skills and efforts.

In essence, the nonce is the number that crypto miners are ‘solving’ for, and via this intense and sometimes rather costly process, the block is added to the chain and the value of a block is earned. Understanding nonce, in theory, is one thing, but the technical aspect can be quite complex, so let’s do our best to break it down a bit.

Often, each block on a blockchain will contain a ledger of the entire history of that chain, in normal circumstances this ledger would be massive. However, blockchain technology innovates by ‘flat packing’ all of this data through a cryptographic function called ‘hashing.’ Hashing essentially forces all the data of the ledger through a system that compiles all the stored information into a long string of code.

This code is deterministic, meaning that the code produced will always be the same, as long as the input is the same. Resulting in a long string of code that stores a vast amount of data but in a very efficient manner. It is this process that gives blockchain technology both its security and its stability.

What miners are solving for is a ‘target hash’ which in itself contains other target values and obligations such as the timestamp, block version number, the Merkle root, the nonce, and then eventually the target hash itself. This is a complex process that requires both skill and resources to complete, that if completed results in the block being added to the chain.

The sought-after nonce is a bit value that exists as a cryptographic representation of an encrypted block. By going through vast amounts of cryptographic combinations to find this nonce, a miner fulfills their ‘proof of work’ and earns the rewarded value of the block.

HOW TO FIND THE NONCE

Defining which string of code to use as the nonce requires a lot of trial-and-error, as it is a semi-random string. A miner must guess a nonce, add it to the hash of the current header, rehash the value, and compare it to the target hash. If the resulting hash value meets the conditions, the miner has solved the difficulty level, met its obligations, and is awarded the block rewards.

It is quite impossible for a miner to successfully guess the nonce on the first attempt, so it’s quite likely that a miner is going to have to try and re-try this process many times. The greater the difficulty—a measure of how hard it is to create a hash that is less than the target—the longer it is likely to take to solve the difficulty and ergo value of said block may indeed be greater.

NONCE AND THE DIFFICULTY IN BLOCKCHAIN

The discussion of nonce and its respective difficulty is often centered around the financial reward aspect of finding the value, but this often skips over the importance of nonce to the system. Since each block of a blockchain is a ledger of the entire chain, the overall structure of the system is quite strong. Any change to any block would generate a cascading amount of differing target hash values, thus invalidating the entire chain.

Therefore the complexity of the code used reduces the likelihood of chain instability due to external attacks or internal data doctoring. This generates an intrinsic value to the technology of blockchain and as such adding new blocks to the system must be accordingly difficult. 

Bitcoin for example adjusts its mining difficulty every few blocks that are mined. In the actual coding of the process of mining, this is represented by what is referred to as ‘leading zeros.’ Leading zeros are preceding ‘0’ values that exist in the code before other numerical values are represented. Imagine James Bond’s code name ‘007.’ These leading zeros represent prepotential difficulties innate to the code. You can be amazed by how many leading zeros Bitcoin might have as its difficulty changes over time.

HOW ARE NONCES USED?

Nonces are primarily used as a part of an authentication process, but this process itself has vast amounts of applications.

This can include 2FA, account recovery, confirmation of purchase, and of course crypto mining. But how exactly is it used? Well, let’s take a look at authenticating a purchase.

During an authentication process, a nonce value ensures that old communications from parties are not reused, either by accident or malicious intent. For instance, when a supplier gets the repetition of the same order under one name and with the same purchase information, a nonce is used to give originality to the message such that if the supplier receives any other order from the same person with the same nonce, the supplier could discard the order.