Proof of Work Explained
Consensus algorithms are an inherent part of all blockchain-based technologies as there is no authority unit supposed to validate the network's transactions. Consensus algorithms are here to provide the decentralized trouble proof functioning of the network. We can't underestimate the significance of the consensus algorithm applied for each particular blockchain-based project. Bitcoin is utilizing Proof of Work which is also an original consensus algorithm for the Ethereum blockchain. People debate if this consensus algorithm is worth using or is it better to use other options.
The Early History of Proof of Work
The first example of the algorithm close to Proof of Work was introduced in 1993 by Cynthia Dward and Moni Naor who came up with an anti-spam solution in the scientific paper called "On Memory-Bound Functions For Fighting Spam". The method described in this paper supposes that the unknown sender of the message is required to spend some time of his/her CPU power (e.g. 10 seconds) in order to prove that the sender is not a spammer.
According to Dward and Naor, spammers having to spend 10 seconds of CPU time would be able to send only up to 8 thousand spam messages a day instead of an unlimited number of spam messages they are capable of sending today. It's not a hard thing to check a function behind proof of work, but computing it is a real headache for spam-senders.
The term Proof of Work was coined in 1999. It emerged in the article called "Proofs of work and bread pudding protocols" (the authors Markus Jakobsson and Ari Juels). The very notion of Proof of Work supposes that the "prover" must provide the "verifier" with the evidence of the required computer work done at the appointed time lapse. The concept seemed to be quite interesting, however it wasn't brought to life until the creation of Bitcoin which strongly relies on Proof of Work in order to create a network governed by distributed consensus with no trust involved.
Bitcoin and Proof of Work
A proof of work is a consensus algorithm requiring an expensive and time-sapping process of production of a piece of data which correctness can be checked effortlessly. Hashcash proof of work system was created as salvation from spam bots but ended up being a staple of the Bitcoin network.
While people send coins to each other the ledger reflects this information in the form of blocks of transactions. The validation of these transactions requires the participation of some worker or workers performing mining.
People eager to validate transactions (known as "miners") have to execute the proof-of-work procedure in order to reach their goal. One worker is one node. The difficulty of this work (tasks) is flexible so the new block must be generated every 10 minutes. As the number of miners is incredibly huge and the time lapse of 10 minutes is relatively short, it is extremely hard to predict which worker (miner) will be the one who generates a new block (verifying all the transactions in the block).
The Mechanism of Proof of Work
In order to generate a new block miner should provide the correct hash for the block of transactions. To do so the miner should figure out nonce and hash function where a nonce is a random number that only used once (the Bitcoin network uses integer numbers between zero and 4,294,967,296 as nonce), and hash is a string of 64 symbols (a mix of digits and letters) containing the encrypted data.
Blocks in blockchain have individual hashes (such hash is called "id"). Every hash is created as a result of successful verification of the block. For verifying the next block the miner adds the latest hash to the current block creating a huge block of text. Then a nonce (a random number) gets added to the end of the block of text. This text consists of the previous block hash, the new transactions waiting for verification, and nonce. That's where the calculation starts. During the calculations, the worker changes the random number until the moment when the correct number of zeros in front of a string is defined.
The difficulty of this task shouldn't be underestimated. As it was mentioned before, the difficulty is set to the level that regardless of the number of miners and the power of their equipment each problem is solved only once every 10 minutes. To do this work computer has to generate millions of possible hashes every second.
To check if some node has executed the required work correctly the one will need a string that appeared as a result of validation and a nonce number. Applying the function on these two values will give the number of zeros in front of the string. In case if this number is correct, then the work was done well. If someone has bad intentions and try to add some invalid data to the chain, this will be stopped by the other participants of mining. Throughout the scale of 10 years, this scheme successfully guarded the Bitcoin blockchain. What makes the SHA-256 algorithm special is that no one can change even a single bit of information in the block secretly. That's why this ledger is called immutable.
Cons of Proof of Work
We can't agree that incredible consumption of electricity required by PoW is just a waste of resources (many opponents of PoW do such claims) as we have already explained that this consensus algorithm is highly effective when it comes to guarding the blockchain. Nevertheless, we cannot ignore that fact that Proof of Work spends gigantic amounts of energy in order to guess the number of zeros while validating transactions. Currently, the Bitcoin network consumes three times less energy than the traditional money system, but if we imagine that Bitcoin gets mass adoption, energy consumption will increase drastically. Anyway, Bitcoin is not replacing the traditional banks, so the consumption increases thanks to Bitcoin.
The other problem is that individuals using their CPU, GPU or ASIC devices for mining have too little chance for finding a new block and getting a reward as they have to compete with the mining pools utilizing dozens of thousands of devices to mine. Around half of the mining occurs in the relatively small group of mining pools. There's a risk that if the owners of these pools decide to unite and rule the Bitcoin blockchain using their hashing power they could do that. An authority having over 50% of hashing power actually can govern the blockchain. Such intrusions are known as 51% attack.
Another notable fact is that 70% of hashing power is coming from China because this country has cheap electricity. It gives this country an advantage in Bitcoin mining and decreases the level of decentralization.
Proof of Work actually manages to protect the network from bad actors although the cost of this consensus algorithm makes us think of the other possible ways to validate transactions and keep the network working correctly and smoothly. No wonder there are already several other consensus algorithms applied to different blockchain projects. The most highlighted competitor of PoW is Proof of Stake.