How to achieve Proof of Work?

Mining involves the process of producing a hash whose value is less than the target value. When this hash has been found, it is called a valid hash and hence proof of work is achieved.

The mining algorithm uses a counter known as the nonce to generate the hash using the SHA256 cryptographic function. A hash algorithm always produces the same arbitrary length data given the same inputs. It is impossible to compute the same hash with two different inputs. It is also impossible to predict the output of any given data in advance.

The value of nonce is initialised to 0. Mining is finding the nonce, the only input that changes every time we run the hash function. The goal is to find a value for the nonce that will result in hash lower than the target. So, the mining node might need to try billions or trillions of nonce values before it gets a valid hash. As you can see, mining is like playing the slot machine, there is no way to predict when can you strike a jackpot.

It is very easy to prove that the nonce found indeed produces a valid hash. All the information are available, everyone in the network can run the hash function and confirm if the hash is valid or not. Because it is also impossible to predict what the nonce will be, it also acts as a proof that the miner has indeed achieved Proof-of-Work.

Calculation of the Valid Hash

(The numbers are based on block #540909)

The formula to calculate the current target of the block is

Current target= maximum target / difficulty

Maximum target is set to

0x00000000FFFF0000000000000000000000000000000000000000000000000000

This is a hexadecimal number. After conversion to a decimal number

Maximum target= 26959946667150639794667015087019630673637144422540572481103610249215

Difficulty is (as given in the block)

7019199231177.17

Therefore,

Current target=(26959946667150639794667015087019630673637144422540572481103610249215)/7019199231177.17

= 3.84089×10^54

The hash of the block is