Proof of Work

Published by Mario Oettler on

Remember, the challenge is to randomly choose a node that is allowed to add a block to the blockchain. This process is accomplished by a puzzle the nodes need to solve. Nodes that participate in this puzzle are often called miners.

The task goes as follows.

  1. Take the data of the block candidate and hash them. This gives us the block hash from the topic about blocks.
  2. Check if the hash is below a certain target. If the hash is below it and you are the first one who published the solution you win.

This sounds easy at the first glance. But if the target is low enough (remember that you need a hash lower than the target) it takes many tries to find a correct input combination.

But if we need many attempts, we need to change the input every time at least a little bit (remember the property of our hash function? It said that if you change the input a tiny bit the hash changes completely).

In order to achieve this small change, there is a variable called nonce in the block header of each block. And this nonce is our value which is incremented with each attempt. And now we have a race between all miners. The one who succeeds in finding the correct nonce and its corresponding block hash first wins the race and is allowed to append a new block to the blockchain.

The starting input values are for every miner a bit different. First, because each miner can choose different sets of transactions, and second in the miner’s address goes into the hash input too. What we need this for we will explain in the incentives section.

The miner with the fastest computer can try more nonces then it’s competitors. That’s why he has the best chance to win this race. But since the hash output is unpredictable a miner with lower computing power can be lucky too. It is a bit like an easter egg hunt. If you run fast through the garden searching for easter eggs you can check many spots, and it is very likely that you find an easter egg before your siblings. But if you happen to look at the wrong spots, your younger and slower siblings can be lucky too by looking at different spots that might happen to be the right ones.

If the correct block hash was found, the miner submits its block to the network as quickly as he can. Other miners check if the block is technically correct and if the puzzle solution is correct. If this is the case, they append this block to the blockchain and the race starts over with new values (new transactions and a new previous block hash) for the next block.