Content

  • Introduce

  • What is double spending?

  • Why is Proof of Work necessary?

  • How does PoW work?

  • Proof of Work vs. Proof of Stake

  • Conclude


Introduce

Proof of Work, often abbreviated as PoW, is a mechanism to prevent double spending. Most cryptocurrencies use it as their consensus algorithm, which is used as a method to secure the cryptocurrency's ledger.

Proof of Work was the first consensus algorithm to emerge and is still the dominant algorithm today. It was introduced by Satoshi Nakamoto in the 2008 Bitcoin white paper, but the technology itself was established long before that.

Adam Back's HashCash was an early example of a Proof of Work algorithm before the advent of cryptocurrency. By requiring the sender to do a little math before sending the email, the recipient can reduce spam. This calculation will cost almost nothing for a legitimate sender, but will add up to a large number for someone sending large numbers of emails.


What is double spending?

Double spending occurs when the same amount of money is spent more than once. The term is used almost exclusively in the context of digital currencies - after all, you'd be stuck spending the same money twice. For example, today, when you pay for a cup of coffee, you pay cash to a cashier who can lock it in the register. You can't go to the coffee shop across the street and pay for another coffee with the same bill.

In digital currency mechanisms, enforcement is possible. You just need to duplicate a previous computer file - by copying and pasting. You can email the same file to ten, twenty, fifty people.

Since digital currency is just data, you need to prevent others from copying and spending the same currency in different places. Otherwise, your currency will quickly collapse.

To learn more about double spending, read The Beginner's Guide to Double Spending.


Why is Proof of Work necessary?

If you've read our Beginner's guide to blockchain technology, you'll know that users broadcast transactions to the network. However, those transactions will not be considered valid immediately. That only happens when they are added to the blockchain.

Blockchain is a large database that every user can see, so they can check if the money has been spent before. Illustrate through an example like this: you and three friends have a notebook. Any time one of the three wants to make a transfer of whatever unit the group is using, he or she writes it down – Alice pays Bob five units, Bob pays Carol two units, and so on.

There's a problem here - every time you make a trade, you're only dealing with the source of the funds. So if Bob pays Carol two units, the actual entry would be as follows: Bob pays Carol two units from the previous transaction with Alice.

Now we have a way to track 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 transactions to be added to the books.

This can work well in a small group. Everyone knows each other, so they will likely agree on which friend should add the transaction to the book. But what if we want a group of 10,000 participants? The notebook idea is not practical, because no one wants to trust a stranger to manage it.

This is the reason for the birth of Proof of Work. It ensures that users will not spend money that they do not have the right to spend. Using a combination of game theory and cryptography, the PoW algorithm allows people to update the blockchain according to the system's rules.


How does PoW work?

Our ledger in the example above is the blockchain. But we don't add transactions one by one - instead, we bundle them into blocks. We announce transactions to the network, then users who create a block include them as a candidate block. Transactions will only be considered valid when the candidate block becomes a confirmed block, meaning it has been added to the blockchain.

However, adding a block is not cheap. Proof of Work requires a miner (user who creates a block) to use some of their own resources to enjoy the privilege. That resource is computational power, which is used to hash block data until a solution to the puzzle is found.

Hashing block data means you pass it through a hash function to create a block hash. A block hash works like a “fingerprint” – it is an identifier for your input data and is unique to each block.

It is almost impossible to reverse a block hash to get input data. However, once an input is known, it is easy to confirm that the hash is correct. You just need to send input through the function and check if the output is the same.

In Proof of Work, you must provide data whose hash matches certain conditions. But you don't know how to do it. Your only option is to put your data through a hash function and check if it matches the conditions. Otherwise you will have to change your data a bit to get a different hash. Changing even one character in your data will result in a completely different result, so there's no way to predict what the output might be.

As a result, if you want to create a block, you are playing a guessing game. You get information about all the transactions you want to add and some other important data, then hash them all together. But since your dataset won't change, you need to add a piece of variability information. Otherwise, you will always get the same hash as output. This variable data is named a nonce. It's a number that you'll change every time you try, so you'll get a different hash each time. And this is what we call digging.

In short, mining is the process of collecting blockchain data and hashing it along with a nonce until you find a specific hash. If you find a hash that satisfies the conditions set by the protocol, you have the right to broadcast the new block to the network. At this point, other participants of the network will update their blockchain to include the new block.

For today's major cryptocurrencies, the conditions are difficult to satisfy. The higher the hash rate on the network, the harder it is to find a valid hash. This is done to ensure that new blocks are not discovered too quickly.

As you can imagine, trying to guess large numbers of hashes can be expensive on your computer's resources. You're wasting compute cycles and power. But the protocol will reward you with cryptocurrency if you find a valid hash.

Let's recap what we know so far:

  • Digging is expensive.

  • You will be rewarded if you create a valid block.

  • Knowing an input, users can easily check their hash - users who are not involved in mining can verify that a block is valid without consuming a lot of computing power.

Everything is still going well. But what if you try to cheat? What would stop you from injecting a bunch of fraudulent transactions into the block and generating a valid hash?

That was the case that led to the birth of public key cryptography. We won't go into detail in this article, but you can learn through the article What is public key cryptography? to have a comprehensive view of it. In short, we use some neat cryptographic tricks that allow any user to verify whether someone has the authority to transfer the money they are trying to spend.

When you create a transaction, you sign it. Anyone online can compare your signature with your public key and check if they match. They will also check whether you can actually spend your money and whether your total input is higher than your total output (i.e. you are not spending more than money you have).

Any block that includes an invalid transaction will be automatically rejected by the network. Trying to cheat will be very costly for you. You will waste your resources without any reward.

In this regard, Proof of Work presents an advantage: It makes cheating costly, but profitable to act honestly. Any rational miner will be looking for ROI, so they can be expected to behave in a way that ensures revenue.



Looking to get started with cryptocurrency? Buy Bitcoin on Binance!



Proof of Work vs. Proof of Stake

There are many consensus algorithms, but one of the most anticipated is Proof of Stake (PoS). This concept dates back to 2011 and has been implemented in several smaller protocols. But it has yet to see adoption in any major blockchain.

In Proof of Stake systems, miners are replaced by validators. There is no mining involved and no race to guess the hash. Instead, users are selected at random - if selected, they must propose (or “forge”) a block. If the block is valid, they will receive a reward made up of fees from the block's transactions.

However, not just any user can be selected - the protocol chooses them based on several factors. To qualify, participants must lock up a stake, which is a predetermined amount of the blockchain's native currency. Staking works like a guarantee: just as defendants must deposit large sums of money to discourage them from skipping trial, validators lock up a stake to discourage fraud. If they act dishonestly, their shares (or part of them) will be taken away.

Proof of Stake has several benefits over Proof of Work. What is most notable is the smaller carbon footprint - since PoS does not require high-power mining farms, the electricity consumed is a fraction of that of PoW.

That said, there is nothing that comes close to PoW. While PoW can be considered wasteful, mining is the only consensus algorithm proven at scale. In just over a decade, it has secured trillions of dollars worth of transactions. To say for sure whether PoS can compete with PoW in ensuring security, PoS needs to be adequately tested in practice.


Conclude

Proof of Work is the original solution to the double spending problem and has proven to be reliable and secure. Bitcoin has proven that we don't need centralized entities to prevent the same money from being spent twice. With the use of cryptography, hash functions, and game theory, participants in a decentralized environment can reach consensus on the state of a financial database.