When learning about bitcoin and the mining process, you are bound to come across various new terms, one of which is nonce. To understand what a nonce is, we need to first learn what a hash is.
Hash is an alphanumeric code used to represent a word, message, or data. In a proof-of-work, or bitcoin mining process, a valid hash must meet certain criteria. Each hash must begin with a series of zeros, or the hash has a low value, according to the proof-of-work criteria. As a result, proof-of-work is difficult to accomplish.
Let’s take the example of the word ‘pintu’. If it hashed with SHA-256 hash algorithm, the result will always be: 24d52030496d5935c5929564269fae1194db553c0ca3e2ede7a4ecc836f134d3
So how do you get the word ‘pintu’ to have a hash starting with the number 0?
To get a hash with a small number, the miner must enter data known as nonce. Then, what is nonce, how does nonce work and the use of nonce in cryptocurrency? Learn more about it in this article.
Nonce is the only data that a miner can add. A nonce is an additional number entered by the miner to change the hash output so that it has a low value or equal to the mining target. Miners can only guess the nonce numbers to produce a hash target that starts with the number 0. So, you can say nonce is a brute force way to achieve mining targets.
Let’s take an example of how nonce works by looking at the following block simulation.
As a requirement for a valid proof-of-work block, the resulting hash must have a small number or start with a few digits of 0 according to the difficulty target. For example, let’s say the difficulty target is the block must have 4-digit number 0 in the beginning.
With Nonce number 1 (Figure B), the resulting hash with the same data will be 306b…ba6a. This hash is still considered invalid because it does not meet the difficulty level (starting with 0000) . The miner will try to change the nonce numbers one by one from 1,2,3… , and so on (Figure C), running the SHA 256 hashing algorithm until it gets a small valid hash that matches the mining difficulty level.
After various attempts, a nonce with the number 16,663 produces a hash with a small value that starts with a 4-digit zero number in front of it.
This process of using hashing algorithms and adding nonces is what we call mining. Miners compete with each other to guess the nonce and perform hashing according to the target. The fastest miner who can create a valid block (i.e. find a nonce that makes a block hash smaller than the difficulty target) will get a block reward or reward in the form of Bitcoin.
Bitcoins are mined every 10 minutes on average and this should be constant in the long run. With the increasing computer power, it is certain that miners will find it easier to find hashes. To ensure that Bitcoin is mined constantly every 10 minutes, the mining difficulty must be adjusted as well, so that if the number of computer hardware and the miners increase, it will not affect the time to find new blocks. The higher the mining difficulty, the smaller the value of the valid hash (or the more zeros in front of the hash).
Mining difficulty is adjusted every 2016 block, or approximately every 2 weeks. If the miner finds the hash faster than 10 minutes then the difficulty level will be added, but if the miner finds the hash slower than 10 minutes then the difficulty level will be reduced.
For example if we have to find a hash that is less than or equal to 0xxx then we have 65,536 possible hashes. But if we have to find a hash less than or equal to 000xx, then we only have 256 possible hashes. So the less the target difficulty, the less likely the miner can find the appropriate hash. The more leading zeros (the smaller) the more difficult it will be to find a suitable hash.
With the current difficulty target, miners have to try to guess the nonce and run the hashing algorithm quadrillion times to find a hash that matches the difficulty target. If the target difficulty increases then the effort required to find the appropriate hash will be twice as difficult. This makes the Bitcoin network even more secure.
In addition to guessing the nonce and running hashing algorithms, miners must also validate blocks. In the next explanation, we will see how the relationship between hashing in a blockchain.
Share