# How are blocks added ? -Proof of Work

This time we’ll talk in some detail about the mechanism of consensus algorithm, Proof of Work and about the concept of nonce.

Proof of work algorithm comes from the olden times HASHCASH system developed by **Adam Back**, for limiting email spams and Denial -of -Service attacks.

## What’s Hashcash ?

Well, hashcash algorithms use a cryptographic function or, let’s say a hash function to decrypt the recipient’s email address from a given **hash.** The function takes the input, runs through the hashing algorithm until a required number of zeroes are found, leading the output. This required number of zeroes are called the nonce (click here to know more) and they state the difficulty of the hash problem.

What’s

nonce?What’sdifficulty?urrggghhhhhhh……..

Calm down, you’ll get it. Let’s try to decrypt this ðŸ˜‰

### Math Behind It

Suppose we have a hash input :

**A : 4.1234:sneha@hotmail.com**

output:

**B : 00000c70bsdh346hdfh465hff79479g0**

Now, when we provide the function with the input A the function is required to produce an output B. For this the function takes the input and feeds it to the hash algorithm, which after hashing the input adds a zero at the beginning of the output.

So our output for the first iteration maybe :

**0c6235hf6297hkjfs36844y64nfh8920h23**

Now if we already know, that the difficulty of this problem is **5, **we have to hash and rehash for 5-times, adding a zero everytime its hashed. On obtaining 5 zeroes we can be sure that the hash generated is the required output-B, since we knew that the difficulty was 5, which meant we must have 5 leading zeroes in the output.

Every time we hash we get 1- zero, so we must hash and rehash for 5 times to get 5 zeroes. This is the

nonce(hence the name of this website).

So this hashcash technique was used in cryptocurrency consensus mechanismÂ also.

The Proof of Work or **PoW **algorithm asks the miner to solve such hashes, whose difficulties are given and whoever solves first gets the reward. Now, ofcourse this solving needs a lot of power so anyone with high GPU or ASIC cards would solve them first and earn the reward.

Today’s proof of work mechanism uses the SHA-256 algorithm, whereas the hashcash used SHA-1 hashing.

The difficulty of the network, i.e., the number of leading zeroes or the nonce is adjusted every 2016 blocks to maintain the continuous rate of block generation.

So, that’s it for today smart-asses.

Leave your comments, questions and anything you’d like me to post about, below