Hello there 👋 ! We are now at 1800+ subscribers 💪 💪. Thank you for your love and support ❤️ ❤️. I am enjoying it; I hope you are enjoying it too! I would love to hear from you at ravitandon2@gmail.com if you love the content and want to read about specific topics.
A quick recap. In the previous newsletter, we looked at Bitcoin Fundamentals. I hope you enjoy reading this one. Given the enormous interest in Web3 technologies, I wanted to take a deep dive into understanding the applications of blockchain, how they are built, and what system design principles underpin them. Therefore, for this blog post, I decided to focus on understanding Proof-Of-Work — the consensus algorithm used by the Bitcoin network.
Before I began, I loved this YouTube video to understand the Consensus Mechanism used by the Blockchain network.
What is Consensus?
In general terms, a consensus is a form of agreement between a group of independent entities in a network. So, for example, within a democracy, we could say that the elections run a majority vote, and we arrive at a consensus on who should be the nation's leader. Distributed systems that consist of thousands of independent nodes over a network usually employ an algorithm to arrive at a consensus. A distributed consensus algorithm aims to allow a set of computers to all agree on a single value that one of the nodes in the system proposed (as opposed to making up a random value). The challenge in a distributed system is that messages can be lost or machines can fail. Paxos guarantees that a set of machines will choose a single proposed value as long as most systems that participate in the algorithm are available. (Source: Rutgers University)
Why is a consensus model needed?
In a generic database application, say a medical report. Usually, a single user (administrator) or a program has access privileges to the database. That means that a single user can read, write or modify any database record. In the case of a medical database, it will be information about different patients. Typically, no one else has access to the account. So, a malicious user or program masquerading as a program (say a virus — trojan or spyware) can delete your account or add an entry that says you owe $10,000 to the institution. Proof of work was the very first consensus model used. We will be doing a deep dive on the proof-of-work consensus model in this blog post.
Consensus Model on blockchain
As discussed in the previous blog post, a blockchain is a distributed ledger and a self-governing system. This means that there isn’t a central system that maintains the truth value for the system. Contributions come from hundreds of thousands of users (part of the distributed network) that make it function properly. So, for the example of the malicious user on the medical records application who says that you owe $10,000 to the institution, the other hundreds of thousands of users will mark the claim as a fraud. This is the first significant advantage of using a consensus algorithm on a distributed ledger.
Essential characteristics of a Consensus Algorithm
In a real-world, distributed ledger, we need the following properties to hold on a network:
Reliability
Fairness
Real-Time Guarantee
Efficiency
Transparency
Before we understand the consensus algorithm used by the Bitcoin network, let us first discuss and understand the problem that the consensus algorithm on bitcoin is designed to solve — double spending.
What is Double-Spending?
We have a blockchain network that consists of Blob, Alice, John, and Kara. Assume that Bob has only $10. He can go ahead and send $10 to Alice. If Bob is malicious and the network is slow to settle transactions, he can send $10 to John within a short period. This can cause issues in the network since the network lost $10 that Bob never had. Traditionally, this is called double-spending and is solved using a centralized network. Money networks such as Visa, Mastercard, and UPI solve this problem using a central server that runs a database to validate the transactions.
Proof Of Work
Proof-of-work is a consensus mechanism on the Bitcoin network. It is an algorithm that uses considerable computational effort to deter, detect and remove malicious users from fraudulently manipulating the Bitcoin blockchain. Launched on the Bitcoin network in 2009, proof-of-work was designed to solve the problem of double-spending (as discussed above).
To revise, a blockchain is a list of blocks. On the Bitcoin blockchain, each block holds information related to transactions made by different users. So, a list of transactions that a blockchain holds can look as follows:
On Jan 1, 2022, Bob paid Alice $10.
On Jan 10, 2022, Alice paid John $5.
On Feb 1, 2022, Alice paid Kara $5.
In reality, a blockchain can contain 100 transactions.
A bit of the history of Proof-Of-Work
Per Satoshi Nakamoto's original paper on Bitcoin, the proof-of-work algorithm used on the Bitcoin blockchain was derived from Adam Back’s Hashcash (Paper, Wiki). As per Satoshi’s paper - “the proof-of-work involves scanning for a value that when hashed, such as with SHA-256, the hash begins with several zero bits. The average work required is exponential in the number of zero bits required and can be verified by executing a single hash.” The system places a constraint that the hash of a block to be generated should begin with a predetermined number of zeros. The higher the number of zeros, the higher the requirement for the computation power. The idea "...to require a user to compute a moderately hard, but not intractable function..." was proposed by Cynthia Dwork and Moni Naor in their 1992 paper "Pricing via Processing or Combatting Junk Mail."
Usage in Emails
Hashcash is a cryptographic hash-based proof-of-work algorithm that requires a selectable amount of work to compute, but the proof can be verified efficiently. It was initially used for identifying spam in emails. For email uses, a textual encoding of a hashcash stamp is added to the header of an email to prove the sender has expended a modest amount of CPU time calculating the stamp before sending the email. In other words, as the sender has taken a certain amount of time to generate the stamp and send the email, it is unlikely that they are a spammer. The receiver can verify that the stamp is valid at a negligible computational cost. However, the only known way to find a header with the necessary properties is brute force, trying random values until the answer is found; though testing an individual string is easy, satisfactory answers are rare enough to require a substantial number of tries to find the answer. The hypothesis is that spammers, whose business model relies on their ability to send large numbers of emails with minimal cost per message, will cease to be profitable if there is even a small cost for each spam they send. Receivers can verify whether a sender made such an investment and use the results to help filter email.
How is a new block generated?
Users who participate in the blockchain and provide compute power to create new blocks are called miners. It takes roughly around 10 minutes for miners to find a new block that can be used to extend the blockchain and hold new transactions. One can then ask why it takes almost 10 minutes to create a new block? What do the miners end up doing? To answer these questions, let us go back to looking at a block's design. Each block in a blockchain holds a cryptographic hash (digital signature or the password) which makes the block valid. It is also noteworthy that each block in a blockchain is linked together to the previous blocks. The miners in a blockchain end up creating a new password for the block. However, by design, the cryptographic hash can only be guessed. The process of guessing is followed by a validation so that the hash is consistent with the data that the block holds. This process of guessing can take around 10 minutes (on average). Once the block’s hash is validated, the miners who participated in the guesswork get paid for the work they ended up doing.
Features Of Proof-Of-Work
Secure
The proof-of-work consensus algorithm is secure. The following two rationales will help argue the case.
Reason #1: Misbehavior from a miner on a proof-of-work mechanism results in the miner being kicked out.
Reason #2: To control the consensus mechanism, a malicious user will need to control 51% of the users on the network. This would amount to hundreds of billions of dollars on the Bitcoin network. Given the amount of computing power and money involved in making a fake transaction, we can assume that the consensus protocol is safe and secure.
Consensus
Miners broadcast the details of a transaction when a new block is added to the network; All the other miners then validate the new details of the new block. If a majority of the miners agree, they leave their computation and use the broadcast block as the truth. To understand this, a set of miners try and solve a puzzle (that gives the password to the new block), and the miners that find the solution the fastest are rewarded with bitcoins, and the other miners have to agree on the solution. This ensures that every miner in the system has the exact block details in the network. This leads to consensus (or widespread agreement).
Problems with Proof-Of-Work
While the proof-of-work consensus algorithm is mighty and has served the blockchain well, it does not go without its problems. This section discusses some of the problems that have plagued networks that use proof-of-work.
Environment Impact
According to this report by BBC in 2021, Bitcoin consumed a similar amount of energy as the power of the Netherlands in January 2021 due to its heavy-duty proof-of-work consensus mechanism.
It was also reported that about two-thirds of the energy usage is derived from fossil fuels.
Inability To Scale
Before we begin, let us try and answer the question — why is scalability an issue for blockchain? Take the example of Bitcoin for finding the ideal answer. It processes almost seven transactions every second, while Visa processes almost 1700 transactions every day. (Reference). This makes the Bitcoin blockchain severely inferior to the Visa blockchain. The on-chain transaction processing capacity of the bitcoin network is limited by the average block creation time of 10 minutes and the original block size limit of 1 megabyte. These jointly constrain the network's throughput. (Wikipedia). The figure below shows the number of transactions on the Bitcoin blockchain per month. Note: It is a logarithmic scale. The number of transactions in 2012 was 100 thousand and has increased 1000x to 100 Million in 2022.
As the number of transactions increases in the blockchain, the cost of transactions increases to apply back pressure on the incoming transactions. This could mean that if a user wants to do a small transaction (say $10 transfer), the overall gas fee (the amount to be paid to the blockchain for the transfer) could be significantly larger (say $20). This makes the blockchain infeasible during peak lead.
Several solutions have been proposed to overcome the limitations, such as different hash calculation schemes (e.g., Schnorr Signatures), offloading transaction verification to a layer-2 system (e.g., Lightning System), and increasing the block size.
The Bitcoin network scalability is a moving target and will improve as new advancements are made in Web3 technologies.
Key Takeaways
To conclude, the key takeaways from the blog post are as follows:
Consensus mechanisms have been such as proof-of-work quite helpful.
Proof-of-work is secure and guarantees consensus under attacks by malicious users.
The Proof-Of-Work consensus algorithm has some drawbacks, its detrimental impact on the environment, and its inability to scale.
Have a great weekend, and Take Care!
If you loved this post, do share it with your network. It will keep me motivated :)
nit:Visa processes almost 1700 transactions every second
nit: Visa processes almost 1700 transactions every second