Introduction
- Proof of Work (PoW) is a mechanism to prevent double spending. Most cryptocurrencies use it as a consensus algorithm, which serves as a way to secure the ledger.
Introduction
In short, Proof of Work (PoW) is a mechanism designed to prevent double spending in digital payment systems. Bitcoin and many other cryptocurrencies use PoW to protect their blockchain networks and data. Such elements are called consensus mechanisms—or algorithms—because they allow multiple parties to reach consensus without having to trust each other.
Proof of Work was the first consensus algorithm and is still one of the most important along with Proof of Stake (PoS). PoW was introduced by Satoshi Nakamoto in the Bitcoin whitepaper in 2008, but the technology itself was proposed long before that.
An early example of the use of the Proof of Work algorithm is the HashCash system from Adam Back, which appeared even before cryptocurrencies. Requiring a small number of calculations before sending email has reduced the amount of spam. Such calculations cost virtually nothing for the average sender, but significantly complicate the bulk mailing process.
What is double spending?
Double spending occurs when the same funds are spent more than once. This term is almost always used in relation to digital currency, since in real life it is difficult to imagine a situation in which the same money is spent twice.
For example, when you buy coffee, you hand over money to the cashier, who puts it in the cash register. You won’t be able to go to another cafe and pay for a second coffee with the same bill. However, in digital money systems this is possible.
You've probably already copied files on your computer. The same file can be easily sent to dozens of people. And since digital money is just data, it is necessary to eliminate the possibility of double spending, that is, copying and sending the same units in different places. If a digital payment system cannot prevent double spending, it will quickly collapse.
To learn more about double spending, check out the article What is Double Spending.
Why is Proof of Work needed?
If you've already read our guide to blockchain, then you know that cryptocurrency users broadcast transactions to the network. But transactions do not become valid immediately, but only after verification and addition to the blockchain.
For example, the Bitcoin blockchain operates as a public transaction database (registry) that can be viewed by any user. Let's say you and three of your friends have a notepad in which you write down your Bitcoin transactions. If one of you wants to transfer funds, he will make a note in his notebook:
Alice pays Bob 5 BTC. Bob pays Carol 2 BTC and so on.
When making each transfer, you must refer to the previous transaction from which the funds were received. That is, when Bob transfers 2 BTC to Carol, the entry looks like this:
Bob transfers 2 BTC from a previous transaction with Alice to Carol.
This way we can track all BTC transfers. If Bob tries to make another transaction using the same 2 BTC that he just sent to Carol, everyone will immediately know about it. The group will not allow him to record such a transaction in the notebook, since he has already spent those 2 BTC.
Such a system can work well in a small group of people where all participants know each other well, because it will be easier for them to agree on which of them will be responsible for adding transactions to the general list. But what if we want to gather a group of 10,000 members? The idea of using a notepad doesn't scale well because no one would trust a stranger to manage such a financial ledger.
This is why the Proof of Work algorithm is needed. It ensures that users don't spend money they can't spend. Using game theory along with cryptography, the algorithm allows any user to update the blockchain according to the rules of the system.
How does PoW work?
Think of the notepad in the example above as a blockchain. However, transactions are not added to the system one by one, but are combined into blocks. Users who create a block include transactions in the candidate block. Transactions will be considered valid only after the candidate block is confirmed and added to the blockchain database.
The process of confirming transactions and adding new blocks is called mining. It is quite complex and requires costs, but can generate profit in the form of block rewards. It consists of transaction fees and new bitcoins created by the protocol.
The Proof of Work mechanism requires the miner (the user creating the block) to invest resources (electricity and computing power) into hashing the data of a candidate block until a solution is found.
Hashing a block involves passing it through a hash function to generate a hash. The block hash acts as a “fingerprint” and serves as an identifier for the input data that is unique to each block.
In other words, the miner must verify and collect pending transactions, then combine them into a candidate block and run the block data through a hash function to obtain the correct hash. If the miner manages to find the correct hash for his candidate block, he will submit it to the network, add the block to the blockchain and receive a mining reward.
Once the miner submits the candidate block and hash to the network, other network participants will repeat the hashing process to ensure the validity of the result.
Finding the correct hash takes a huge number of attempts, but checking the correctness of the finished hash is quite easy. To do this, you simply need to pass the same input data (block data) through a hash function and check if the result matches.
In Proof of Work, you must provide data whose hash follows certain rules set out in the protocol, provided you don't know how to retrieve it directly. The only option is to run the data through a hash function and check if it matches the conditions. If there is no match, you will have to change the data to get a different hash. Changing even one character in your data will lead to a completely different result, for this reason it is impossible to simply predict what the output might be.
So, to create a block, you need to calculate the hash. To do this, the user hashes together information about all transactions that need to be added to blocks and some other data. But since the data set does not change, the user adds a piece of information that will become a variable. Otherwise, the output will always be the same hash. This variable data is called a nonce. They are changed on each attempt to obtain a new hash.
So mining is the process of collecting blockchain data and hashing it along with a one-time code until you find a suitable hash. If you find a hash that satisfies the conditions set by the protocol, you get the right to broadcast a new block to the network. At this point, other participants in the network need to update their blockchains to include the new block.
The conditions set by major cryptocurrencies are incredibly difficult to meet. The higher the network hashrate, the more difficult it is to find a valid hash. This is done to prevent blocks from being generated too quickly.
Regular attempts to guess a huge number of hashes are expensive, because it wastes a huge amount of computing resources and electrical energy. However, if miners manage to find a valid hash, the protocol rewards them for their work.
Let's review what we covered:
Mining is a complex and expensive process that ensures the security of the network.
Miners who create a valid block are rewarded in the form of new cryptocurrencies and transaction fees.
Generating the correct hash takes some time, but its accuracy can be easily and quickly verified by repeating the hashing process.
But what if you try to cheat the system? What's stopping you from putting a bunch of fraudulent transactions into a block and creating a valid hash?
Public key cryptography was developed for this purpose. To learn more about this topic, check out our article What is Public Key Cryptography. In short, the algorithm uses certain cryptographic techniques that allow any user to verify the right of an individual network participant to move funds to another address.
When you create a transaction, you sign it. Any network participant can then compare your signature with your public key to see if it matches. This lets you know if you can spend your funds and if your expenses do not exceed the allowable amount.
Any block containing an invalid transaction will be automatically rejected. Trying to fool the network will cost you a lot because you will end up wasting your computing resources without getting any reward for it.
This is the idea of Proof of Work: it is more profitable for users to act honestly than to try to deceive the system. Miners are trying to recoup their investment, so most will follow the rules to make a profit.
Proof of Work (PoW) или Proof of Stake (PoS)
There are many other consensus algorithms besides PoW, but one of the most popular is Proof of Stake (PoS). Its concept dates back to 2011 and has been implemented in Ethereum and several other protocols.
In networks with Proof of Stake consensus, the role of miners is played by validators, since the protocol is not associated with the mining process and guessing hashes. Instead, users are selected at random, and the selected participant must propose a new block. If a block is found to be valid, the validator will receive a reward consisting of transaction fees for that block.
The protocol selects a new validator based on several factors. To have a chance to be selected, you need to lock some of the tokens by adding them to staking. This amount acts as a kind of collateral: validators block a certain number of coins in the system, which will be lost if the validator tries to deceive the system. Staking coins will be forfeited if a validator attempts to validate an invalid block.
Proof of Stake has some advantages over Proof of Work. One of them is a smaller carbon footprint. This is due to the fact that Proof of Stake does not require the maintenance of powerful mining farms, and therefore consumes much less electricity than Proof of Work.
However, PoS does not have as great a track record as PoW. While PoW may be perceived as wasteful, mining is currently the only consensus algorithm that has worked well for over a decade. During this time, Bitcoin's PoW mechanism has securely processed trillions of dollars worth of transactions. The PoS protocol has yet to prove its effectiveness and competitiveness in the long term.
In conclusion
Proof of Work is a reliable and secure solution to the problem of double spending. Bitcoin has proven that it does not require centralized organizations. With proper use of cryptography, hash functions and game theory, participants in a decentralized environment can themselves monitor the correct operation of the entire financial database.
Recommended reading
What is cryptocurrency mining and how does it work?
What is public key cryptography?
What is the blockchain consensus algorithm?
Disclaimer: The following materials are provided “as is” without warranty of any kind for general reference and educational purposes only. This information should not be considered financial advice, legal advice, or a recommendation to purchase any specific product or service. You should seek your own advice from appropriate professional advisers. Since this article was written by a third party author, please note that the opinions expressed are those of the third party author and do not necessarily reflect the views of Binance Academy. For more detailed information please follow the link. The value of digital assets can be volatile. The value of the funds invested may go up and down. You may not get your invested funds back. You are solely responsible for your investment decisions. Binance Academy is not responsible for your possible losses. This information does not constitute financial, legal or professional advice. To learn more, please read our Terms of Use and Risk Disclosure.