How does Proof of Work use cryptography?
Proof of Work is a consensus algorithm that uses a cryptographic hashing puzzle to make sure that a certain amount of work has been done before a block is created. Bitcoin's Proof of Work uses the SHA-256 hash function to create a hashing puzzle.
Blocks in a blockchain network are created by a special type of validator node called a miner. These miner nodes compete with each other to solve the hashing puzzle in order to produce a block to be appended to the ledger.
Blockchain miners will start to solve the hashing puzzle whenever they have data (often, a set of transactions) that needs to be included in a block. The following Figure 3.2 shows the basic structure of a block header used in a Proof of Work-based blockchain application. A puzzle solver will create a hash value of the header, generally using the SHA256 hash function. The puzzle here is to find a hash value for the header so that the hash begins with a known number of zero bits:
We have mentioned previously the characteristics of a hash function; that is, the hash value cannot be predicted because the creation of a hash value is a one-way process. As a result, it's difficult to predict the contents of the header, which would result in the hash value beginning with a certain number of zero bits. The only way to achieve this is by repeatedly trying out different header values and computing the hash value using the hash function. A different header is created by altering a variable field called nonce in the header. A random nonce is assigned to create a different header for the hash function. Once the miner finds a nonce that will produce a hash value with the required number of zero bits, the puzzle is solved, and the nonce is recorded in the block header.
Using a hash function to perform Proof of Work turns out to be a good approach because it is difficult to fraudulently compute a hash value due to its cryptographic characteristics. Hash functions make sure that a certain amount of CPU effort has been used to compute hash values, and that the hash rate of the computer is the Proof of Work during this process.