Content
Introduction
What is double spend?
Why is Proof of Work necessary?
How does PoW work?
Proof of Work vs. Proof of Stake
Final considerations
Introduction
Proof of Work (commonly abbreviated as PoW) is a mechanism for preventing double-spends. Major cryptocurrencies use PoW as a consensus algorithm, which is a method of securing cryptocurrencies from a distributed ledger.
Proof of Work was the first consensus algorithm created and, to this day, it remains the main one. It was introduced by Satoshi Nakamoto in the Bitcoin white paper in 2008, but the technology itself was conceived long before that.
HashCash by Adam Back is an early example of a Proof of Work algorithm that predated cryptocurrencies. By requiring senders to do a small computational check before sending an email, receivers could reduce spam. This check was quick and simple for the user sending the email, but it would be a problem for someone sending mass emails, such as spam emails.
What is double spend?
A double-spend occurs when the same funds are spent more than once. The term is used almost exclusively in the context of digital money – after all, it would be difficult to spend the same money twice when it is physical. When you buy a coffee, you hand the money to the cashier who probably blocks it in some way. You will not be able to cross to the other side of the street and pay for another coffee with the same bill.
In digital money schemes, there is such a possibility. You've probably duplicated a computer file before – just copy and paste. You can send the same email file to ten, twenty, fifty people.
Since digital money is simply a set of data, people need to be prevented from copying and spending the same units in different places. Otherwise, the respective currency system will collapse.
For more details on double-spending, check out the article Guide to Double-Spending.
Why is Proof of Work necessary?
If you've read our guide on blockchain technology, you already know that users broadcast transactions to the network. However, these transactions are not considered valid immediately. This only happens when they are added to the blockchain.
The blockchain is a large database that all users can see, making it possible to check whether funds have been previously spent. Imagine this: you and three friends have a notebook. Whenever one of you makes a transfer of any unit, you record it in the block – Alice paid five units to Bob, Bob paid two units to Carol, etc.
There is one more detail – whenever you make a transaction, you make a reference to the transaction from which the funds came. Therefore, if Bob was paying Carol with two units, the entry would be as follows: Bob pays Carol two units from this previous transaction with Alice.
Now we have a way to track the units. If Bob tries to make another transaction using the same units he just sent to Carol, everyone will know immediately. The group will not allow the transaction to be added to the notebook.
This can work well in a small group. Since everyone knows each other, they will likely come to an agreement about which friends can add transactions to the notebook. But what if we want a group of 10,000 participants? The notepad idea would not be suitable as no one wants to trust a stranger to manage transaction records.
This is where Proof of Work comes in. It ensures that users do not spend money that they have no right to spend. Using a combination of game theory and cryptography, a PoW algorithm allows anyone to update the blockchain according to the rules of the system.
How does PoW work?
Our notebook in the example above is the blockchain. But we don't add transactions one by one – instead, we group them into blocks. Transactions are announced to the network, so when creating a block, users will include the transactions in a candidate block. Transactions will be considered valid only when the candidate block becomes a confirmed block, which means it has been effectively added to the blockchain.
However, attaching a block is not a cheap process. Proof of Work requires a miner (the user who creates the block) to use their own resources to have this privilege. This resource is computational power, used to hash the block data until a solution to the puzzle is found.
To generate a block hash, the Hashing process submits the block data to a hashing function. The block hash works like a “fingerprint” – it is an identity of the input data and is unique to each block.
It is practically impossible to reverse a block hash to obtain the input data. Knowing an input, however, it is easy to confirm that the hash is correct. You just need to submit the input to the function and check if the output is the same.
In Proof of Work, you must provide data whose hash meets certain conditions. But you don't know how to get there. Your only option is to submit your data through a hash function and check if it meets the conditions. Otherwise, you will have to change your data a little to get a different hash. Changing a single character in your data will result in a completely different output, so there is no way to predict the output.
So if you want to create a block, you are playing a guessing game. Typically, you get information about all the transactions you want to add and some other important data, then group it all together into a hash. However, as your data set is fixed, you will need to add variable information. Otherwise you would always get the same hash as output. This variable data is what we call a nonce. It's a number that you change to get a different hash each time you try. This is the process we call mining.
In short, mining is the process of collecting data from the blockchain and hashing it, using a nonce, until a specific hash is found as a result. If you find a hash that meets the conditions set by the protocol, you have the right to broadcast the new block to the network. Once this is done, the other participants in the network will update their blockchains to include the new block created.
For today's top cryptocurrencies, the conditions are incredibly difficult to satisfy. The higher the hash rate on the network, the harder it is to find a valid hash. The hash rate is adjusted to ensure that valid blocks are not found too quickly.
As you can imagine, trying to guess large amounts of hashes using a computer can be a very expensive process. You would be wasting computational cycles and electricity. But if you find a valid hash, the protocol will reward you with cryptocurrencies.
Let's recap what we've seen so far:
Mining is a very expensive process.
You are rewarded for producing a valid block.
Knowing an input, a user can easily verify its hash – users who are not miners can check whether a block is valid, without the need for large computational power.
So far, so good. But what if someone tries to cheat? What stops a user from inserting fraudulent transactions into the block and producing a valid hash?
That's where public key cryptography comes in. We won't go into depth here, but check out the article What is Public Key Cryptography? for a more comprehensive view on this subject. In short, we use some cryptographic tricks that allow any user to check if someone has the right to move the funds they are trying to spend.
When you create a transaction, you sign it. Anyone on the network can compare your signature to your public key and see if it matches. They will also check that you can actually spend the funds and that the sum of your inputs is greater than the sum of your outputs - that is, that you are not spending more than you actually have.
Any block that includes an invalid transaction will be automatically rejected by the network. Trying to cheat is expensive. You will waste your resources without getting any reward.
That's the magic of Proof of Work: it's expensive to cheat, but it's profitable to act honestly. Any rational miner seeks return on investment, ROI. In other words, the expectation is that they behave in a way that guarantees their profits.
Thinking about investing in cryptocurrencies? Buy Bitcoin on Binance!
Proof of Work vs. Proof of Stake
There are many consensus algorithms, but Proof of Stake (PoS) is one that has generated the most expectation. It's a 2011 concept and has already been implemented in some smaller protocols. However, it has not yet been adopted on any of the major blockchains.
In Proof of Stake systems, miners are replaced by validators. There is no mining involved nor is there a competition to guess hashes. Instead, users are selected randomly – if selected, they must propose (or “forge”) a block. If the block is valid, they will receive a reward made up of the block's transaction fees.
Not just any user can be selected – the protocol chooses them considering several factors. To be eligible, participants must maintain a locked stake value, which is a predetermined amount of the blockchain's native currency. Staking works like a guarantee: just as defendants must spend a large amount of money to discourage them from skipping their trial, validators maintain a stake amount to discourage cheating. If they act dishonestly, the stake value (or part of it) will be lost.
Proof of Stake has some advantages over Proof of Work. The most notable is the lower energy consumption – since in PoS, there is no need for mining farms that consume so much energy. The electricity consumed is only a fraction of that used in PoW.
PoS doesn't even come close to the usage history of PoW. While this may be considered wasteful, mining is the only consensus algorithm that has proven effective on a large scale. In just over a decade, it has ensured the transfer of trillions of dollars in transactions. To be sure that PoS can compete with the security of PoW, Staking must be properly tested on a large scale.
Final considerations
Proof of Work was the original solution to the double-spending problem and has proven to be a reliable and safe method. Bitcoin has proven that we don’t need centralized entities to stop the same funds from being spent twice. With the clever use of cryptography, hash functions, and game theory, participants in a decentralized environment can reach consensus regarding the state of a financial database.