Bitcoin Blockchain: Protocol for Micropayments
By Kapil Jain
()
About this ebook
This book offers a practical deep dive into every aspect of the Bitcoin protocol. It includes the math behind the Cryptography and a detailed overview of the application-level protocol, which works on top of the Bitcoin Blockchain network. It also focuses on the core principles and fundamental concepts of Bitcoin to explain the constructs of a Blockchain type system.
Related to Bitcoin Blockchain
Related ebooks
Cryptocurrency Chronicles: Unlocking The Secrets Of Blockchain Technology Rating: 0 out of 5 stars0 ratingsBlockChain for Beginners Rating: 0 out of 5 stars0 ratingsQuick Guide to Learning Solidity Rating: 0 out of 5 stars0 ratingsCryptocurrency Mining For Dummies Rating: 0 out of 5 stars0 ratingsBlockchain: Step By Step Guide To Understanding The Blockchain Revolution And The Technology Behind It Rating: 5 out of 5 stars5/5Enterprise Blockchain: Applications and Use Cases Rating: 0 out of 5 stars0 ratingsDecentralized Finance (DeFi) Rating: 0 out of 5 stars0 ratingsDecentralized Finance (DeFi): Unlocking The Future of Financial Freedom Rating: 0 out of 5 stars0 ratingsQuick Guide for Smart Contracts Creation and Deployment on Ethereum Blockchain Rating: 0 out of 5 stars0 ratingsBitcoin Trading Masterclass: The Complete Bitcoin Guide Rating: 0 out of 5 stars0 ratingsBitcoin: A Comprehensive Guide To Get Started With the Largest Cryptocurrency in the World Rating: 5 out of 5 stars5/5A Deep Dive Into The Top 50 Cryptocurrencies: A DYOR (Do Your Own Research) Guide Rating: 0 out of 5 stars0 ratingsCryptocurrency Investing Blockchain Revolution 2022 the Best Strategies to Become a Crypto Millionaire: WARREN MEYERS, #6 Rating: 0 out of 5 stars0 ratingsI Don't Trust You: But Blockchain and Bitcoin Will Help Rating: 0 out of 5 stars0 ratingsModern Full-Stack React Projects: Build, maintain, and deploy modern web apps using MongoDB, Express, React, and Node.js Rating: 0 out of 5 stars0 ratingsEarning Money through Crypto Currency Airdrops, Faucets, Cloud Mining, Online Trading and Online Advertisements Rating: 0 out of 5 stars0 ratingsThe Blockchain Technology: The Hidden Mystery Behind this Internet Tech Disruptor Rating: 0 out of 5 stars0 ratingsMetaversions: Many men, many minds Rating: 0 out of 5 stars0 ratingsCryptocurrency 101:: A Beginners Guide To Understanding Cryptocurrencies and Tow To Make Money From Trading Rating: 0 out of 5 stars0 ratingsThe Art of Tax Reduction Rating: 0 out of 5 stars0 ratingsBitcoin Gold Mining and Cryptocurrency Blockchain, Trading, and Investing Mastery Guide Rating: 0 out of 5 stars0 ratingsThe Secret of Bitcoin Rating: 0 out of 5 stars0 ratingsSimple electronics with GPIO Zero: Take control of the real world with your Raspberry Pi Rating: 5 out of 5 stars5/5
Computers For You
Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 4 out of 5 stars4/5Data Analytics for Beginners: Introduction to Data Analytics Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5UX/UI Design Playbook Rating: 4 out of 5 stars4/5The Self-Taught Computer Scientist: The Beginner's Guide to Data Structures & Algorithms Rating: 0 out of 5 stars0 ratingsStorytelling with Data: Let's Practice! Rating: 4 out of 5 stars4/5Elon Musk Rating: 4 out of 5 stars4/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 4 out of 5 stars4/5CompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsMindhacker: 60 Tips, Tricks, and Games to Take Your Mind to the Next Level Rating: 4 out of 5 stars4/5The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution Rating: 4 out of 5 stars4/52022 Adobe® Premiere Pro Guide For Filmmakers and YouTubers Rating: 5 out of 5 stars5/5CompTIA Security+ Get Certified Get Ahead: SY0-701 Study Guide Rating: 5 out of 5 stars5/5Get Into UX: A foolproof guide to getting your first user experience job Rating: 4 out of 5 stars4/5Procreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 5 out of 5 stars5/5Computer Science I Essentials Rating: 5 out of 5 stars5/5Fundamentals of Programming: Using Python Rating: 5 out of 5 stars5/5A Quickstart Guide To Becoming A ChatGPT Millionaire: The ChatGPT Book For Beginners (Lazy Money Series®) Rating: 4 out of 5 stars4/5Algorithms For Dummies Rating: 4 out of 5 stars4/5Becoming a Data Head: How to Think, Speak, and Understand Data Science, Statistics, and Machine Learning Rating: 5 out of 5 stars5/5Learning the Chess Openings Rating: 5 out of 5 stars5/5Quantum Computing For Dummies Rating: 3 out of 5 stars3/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for Bitcoin Blockchain
0 ratings0 reviews
Book preview
Bitcoin Blockchain - Kapil Jain
Section - I
CHAPTER 1
Bitcoin Protocol: Origins and Concept
On the road from the City of Skepticism, I had to pass through the Valley of Ambiguity.
- Adam Smith
Bitcoin is a new paradigm in terms of how a technology protocol can be built, implemented, and how it can change the world of internet-based applications and their architecture. This is very different from existing design patterns, architecture, and database structures that have been used by users and enterprises until now. This chapter will take you to the roots of the concept of Bitcoin protocol, a bird’s eye view of the overall structure, and some of the founding principles of the creation of Bitcoin Blockchain.
Structure
Skepticism to the solution, a Bitcoin road called the blockchain
History of electronic cash systems
Bitcoin as the protocol for value exchange network
What is blockchain and how Bitcoin works
Bitcoin is an economic system
Objective
After studying this chapter, you should be able to understand a bit of history and early attempts to create electronic cash systems. An overview of the Bitcoin blockchain and the transaction management system in Bitcoin. You will also learn about the ideas behind why Bitcoin is an economic system more than a cryptographic system and an immutable evidence trail. You will also learn more about a block and how the blocks are chained together forming a timestamped server storing transaction information.
Bitcoin: A Peer-to-Peer Electronic Cash System
There are few creations in the world that have brought about changes so large to human society, touching everyone’s life that it changes the way we think, we live and we interact with each other. These changes when they happen go through the phases of ignorance and rejection, contempt and resistance, notice and acknowledgment, and then wait and watch before they become accepted and adopted. Electricity is one such example, and so is the creation of the internet.
I believe we are at a place in time where we are going to witness another such invention happening right before our eyes which is going to take over the existing norms as the Internet did. This will enable a more transparent, independent, instant, and accountable medium of exchange of value, creating the perfect tool which the free market trade requires giving a real sense of financial sovereignty to an individual. It can help create organizations where decisions and power structure looks very different and not centralized, it can help make the governance of society much more transparent and efficient, it can help make an internet which is not based on advertising model but incentive model, and it can force-start a revolution in innovative hardware and software principles and architecture.
Yes, my build-up might bring the greatest skeptic thoughts to fore, but this is the journey I intend to take you in this book, going both into the technical and economic aspects of this once in a lifetime opportunity of creating a truly free market commodity and a completely new way of designing applications that don’t depend on monolithic silos. It comes with a public datastore (ledger) where no entry can be deleted to mask corruption or to have the possibility to associate every click of a button or a user action to be a microtransaction for things like content creation, gaming, and IoT but is having an almost guaranteed security model to beat the best possible implementation that currently exists but with a fraction of the cost. Let’s start this journey called Bitcoin which I feel is possible to be a ride filled with ambiguity to start with as it challenges many existing norms, but that is what every creation bringing fundamental change does.
Bit: A bit is the basic unit of information in information theory, computing, and digital communications. The name is a portmanteau of binary digit.
Coin: A coin is a small, flat, (usually, depending on the country, or value) round piece of metal or plastic used primarily as a medium of exchange or legal tender. They are most often issued by a government.
BitCoin: Bit of information and a coin which is money. Bitcoin with its transaction structure of Inputs and outputs is a carrier of both, Money and Information, at the same time. (Hence the emphasis on writing Bitcoin as Bit-Coin). The smallest unit is called satoshi and 1 Bitcoin represents 100000000 satoshis. Satoshi is a non-divisible integer value.
Bitcoin is like a smartphone, the phone/calling aspect is just one use case, but it can do a whole lot of things no one had imagined, similar to that, Bitcoin treated as money is only one use case but it can do a whole lot more things that no one has imagined. We will be exploring those features and use cases of Bitcoin in this book.
History
Since the advent of computers, there was always the thought that physical or paper money can at some time in the future be replaced by electronic money. This became more mainstream since the 1980s where a bunch of attempts was made to create this fabled electronic money. I will cover the few notable attempts in order to preview the thought process which made some impressions and these attempts, although not successful, did create an impact as an early effort to make electronic cash.
Ecash
Ecash was one of the earliest attempts towards creating electronic money. It was conceived by David Chum who is an American Cryptographer. He created Ecash as Anonymous electronic money based on a cryptographic electronic cash system in 1983. He did this work under the corporation named Digicash which later on went to collaborate with a few banks (Mark Twain Bank, Deutsche Bank) to provide them with a micropayment system in the USA, Australia, and Europe from 1995 to 1998. It met limited success with the best results coming from the US bank reaching up to about 5000 customers. The US bank was bought by another bank who was a large issuer of credit cards and eventually they stopped using Ecash. One of the main reasons it was shut down was due to the fact that it was anonymous and the credit card system was not, making the better solution win. Digicash went bankrupt in 1998 despite the flourishing e-commerce industry at the time where the credit card solution won the battle of currency of choice.
B Money
B Money was a hypothetical approach that got recognition for a few ideas which were good as they proposed another serious possible way to implement an electronic money system. It was conceived by Wei Dai, a computer engineer and a graduate of the University of Washington. He published a paper in the year 1998 introducing the idea of B-Money. He was trying to conceive of this system heavily inspired by Tim May’s idealistic crypto-anarchy world where governments are not just temporarily destroyed but permanently forbidden and permanently unnecessary. It hypothesized a community that uses its own, 1. The medium of exchange and 2. A way to enforce contracts. Both of these services traditionally provided by the government in effect replacing the government with this new system. It involved an assumption of the existence of an untraceable network in which senders and receivers are identified via public keys and every message is signed by its sender and encrypted to its receiver (pseudonyms).
Money in this proposed system could be created by anyone who can provide a solution to a previously unsolved computational problem, the money unit created proportionate to the amount of computing effort done. Transfer of money can happen by broadcasting the proposed transaction on the network by the sender and receiver. It required all users running a computer system connected to the network by default. It also involved a 3rd party who will do arbitration in case of a need for enforcing contracts. The problem of how to set up an Arbitrator (third-party) was solved by a proposal that a second protocol is used for keeping the accounts ledger by a subset of participants who needs to be trusted to a certain degree. The mechanism to keep a check on this subset, they were required to deposit a certain amount of money units to a special account which was to be later used as fines in case of misconduct.
This system was never implemented due to various challenges in terms of the right approach for money creation, the non-existence of the proposed network, and the overall complexity of usage.
Reference: http://www.weidai.com/bmoney.txt, W. Dai, b-money
, 1998.
Ripple Pay
Ryan Fugger created a community-driven open source project called Ripple Pay (2004), as defined by him, Ripple is a project to build a new kind of monetary system based on the trust present in our ordinary social and business relationships:
My IOU will only be accepted by my friends who trust me. I cannot pay strangers.
Each of my friends will only accept an IOU from me up to a certain amount, depending on how much each one trusts me (measured by how much credit each will offer me).
If my friends accept my IOU, they cannot use it as a currency outside the circle of my trusted friends.
Creating a social barter system application run by communities who trust each other rather than trusting an institution like the Bank. This became the basis for the future cryptocurrency implementation of Ripple and XRP.
Reference: http://ripple.ryanfugger.com/decentralizedcurrency.pdf Ryan Fugger. Money as IOUs in Social Trust Networks & A Proposal for a Decentralized Currency Network Protocol. April 18, 2004
There were few other attempts to create electronic cash/decentralized money such as Mojo Nation (m-net), Edonkey, and Liberty reserve but those also attained only little success in small groups. Both Ecash and Liberty reserve which achieved some success eventually were shut down by governments as they were trying to bypass regulations or creating a provision of anonymous money which poses a risk of facilitating criminal behavior or an alternate currency in competition to the government-issued legal tender. A lot of the above ideas have their roots in the Crypto-Anarchist movement or an inherent dissatisfaction with the existing government or the finance and banking system. It was described in a lot more details in the Ripple Pay system as the reason for it to exist is to not trust who (institutions) we are forced to trust but to trust who (friends and family or community) we already trust and create a barter system based currency.
These ideas, albeit quite idealistically attractive but were not as practical as the solution to the problem of the government or banking system not working as expected. They cannot solve it by being a system outside it, but only by a system working inside it. One can start to root for a world without government, and it could be argued that it is a possible or ideal way to go, not the less, in reality not possible.
And then came the Whitepaper. A message was posted and shared to a cryptography mailing list which goes something like this:
Figure 1.1: First ever post related to Bitcoin by pseudonym Satoshi Nakamoto published the Bitcoin whitepaper
Bitcoin whitepaper was circulated in November 2008 to a cryptography mailing list and communities for peer reviews and feedback before the final launch of the network that happened in January 2009.
Reference: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3440802 Wright, C. (Pseudonym: Nakamoto, S). Bitcoin: A Peer-to-Peer Electronic Cash System; Whitepaper: Sydney, Australia, October 2008.
The abstract documented in the whitepaper is probably the best description of bitcoin protocol which creates a unique network for value exchange, Peer to Peer electronic cash system. As I have described the earlier attempts where the proposed systems either did not pick up or failed and was found lacking something from the system architecture perspective incompleteness of functionality and security or lacking the business architecture view where it can become an enterprise-grade solution to be used. Bitcoin was something that addressed both. The simplicity of a system which breaks down the problem of transferring a message securely between two non-trusted parties, and also ensuring there are economic incentives for keeping the non-trusted parties engaged in the system. To understand Bitcoin, you need to look both from a technical perspective of things, and also from the economic perspective of things as the full proof aspect of the security model of Bitcoin is not technical, not cryptographic, but economic.
Introduction to Bitcoin
The internet has revolutionized trade. E-Commerce has been an exponentially growing industry and that is just one form of trade. Supply chain, banking services, and content creation for information (media, entertainment, news, education, FMCG) all industries are going through a phase where they have embraced the internet to expand their outreach and user experience of their services. Currently, the payments/monetization of services is heavily dependent on financial institutions serving as trusted third parties to process electronic payments. And to quote from the whitepaper:
While the system works well enough for most transactions, it still suffers from the inherent weaknesses of the trust-based model. Completely non-reversible transactions are not really possible since financial institutions cannot avoid mediating disputes. The cost of mediation increases transaction costs, limiting the minimum practical transaction size and cutting off the possibility for small casual transactions, and there is a broader cost in the loss of ability to make non-reversible payments for non-reversible services. With the possibility of reversal, the need for trust spreads. Merchants must be wary of their customers, hassling them for more information than they would otherwise need.
The core idea to challenge the system above is not to subvert the reporting of the information to the concerned legal entities or the government, but the system that exists right now was made to mirror the manual, paper-based systems that existed before the invention of the internet and computers and it was but the natural first step to migrate that manual business processes by automating them. After decades of having those systems now we are starting to see their limitations due to exponential increase in both the volume and usage of the exchange of information or even payments. In a country like India, we are also moving away from a cash-based system to a digital system where all of the payments that are of more than a certain amount are being mandated to be in digital form. The future holds even a larger volume of transaction requirements with things like IoT coming into day to day and household usage.
Let me pull up the overview of the current financial network and how they work to illustrate the number of hops and the number of parties that are involved in a simple payment done. I will take a typical example here. This is to give you an overview of how the two systems compare and stand when it comes to an individual. Due to the nature of the trusted system, the whole structure becomes quite complex with many trusted third parties getting involved who share part of the risk for the transaction and hence also receive a fee from the transaction. (Figure 1.2)
In Bitcoin, the transaction happens Peer to Peer (P2P) and the recording of transaction happens on a publically shared common record book called ledger or blockchain. But a bit differently from the existing systems, as the third-party is trustless.
Let’s have a look at the figures below for the existing and the new system that can be made with Bitcoin:
Figure 1.2: A typical Credit card transaction process flow
In a Bitcoin network the above system works in a bit different manner, as shown in Figure 1.3:
Figure 1.3: A typical and high-level transaction process flow using the Bitcoin blockchain
There are the following things that have changed from Figure 1.2 to Figure 1.3 but the same result of money being transferred from the customer to merchant has happened:
In place of multiple third parties (banking institutions, intermediary and settlement bank) we have only one third-party which is played by a number of competing miners reducing the number of hops a transaction has to take to reach the intended recipient.
There is always more than one miner (typically 3 to 10s) mining and hosting the blockchain’s public ledger at any point in time making it distributed public ledger, who works as the non-trusted validators for transactions and maintain the integrity of the underpaying public ledger.
The customer only has to send the transaction via his software to the public ledger. Once updated in the ledger, the merchant owns the money so this simplifies the overall business process and again removes the reversibility of the transaction.
In place of user accounts and the various sets of the payment transaction and network, all coins are associated with a private key and there are standardized transaction types used for the exchange of coins between two users using the public key for the intended recipient, making it completely secured.
Transactions that are computationally impractical to reverse would protect sellers from fraud, and routine escrow mechanisms could easily be implemented to protect buyers.
Then of course if there is a legal dispute due to which the transaction can become invalid, we can reverse the transaction but typically that will only happen for something that is ordered by a court of law and is significant in value due to the huge effort involved in it.
The ledger where the accounting entries are made (Bitcoin public ledger) is distributed across the globe making it resilient to any single point of failure scenarios.
Transactions
An electronic coin is defined as a chain of digital signatures and an owner transfers the coin to the new owner by a transaction. A transaction consists of an input record (owner digitally signing the hash of the previous transaction) and the public key for the next owner (recipient):
Figure 1.4: Transactions in Bitcoin, Source - Bitcoin Whitepaper
This diagram above shows how a transaction is in terms of its components and ownership of the coins that a transaction is made to transfer. The Cryptography used for generating the public and the private key is not the commonly used PKI but ECC which will be discussed in detail in a chapter later in the book.
Payee or recipient of a transaction can always verify the validity of the transaction by using his private key to validate the transfer of ownership via this transaction as shown above. Typically the trusted 3rd party like Financial institution acts as the verifier of the validity of a transaction to address (something that is commonly called the double-spending problem) to ensure that the owner of coins is not signing the same coins to more than one receiver. This is Bitcoin is achieved using a timestamp server which stores the log of all of these mentioned transactions, with time-stamped and digitally signed chain of ownership of all coins at any point in time, in time-stamped blocks which again are connected with each other in reference just as the transactions shown in the above picture. This server came to be known more commonly as a blockchain:
Figure 1.5: A representational view of the blockchain
A blockchain is a public book of record that can be verified by anyone if they are willing to put in the work for the infrastructure setup like downloading the complete blockchain and running a node but is typically done by a new type of entity which is referred to as miners. Mining is an analogy of physical miners who dig through mountains of pieces of gold and the better equipment and investment they have in mining, the better their chances are to be able to find gold. In Bitcoin, these mentioned transactions are grouped into a block. This will be discussed in detail in the chapter when we discuss mining, but it’s miners who work in competition with each other in a game of adding the next block every 10 mins and win a coinbase transaction which is similar to a reward winning them 6.25 bitcoin at the current times. Miners also are paid a small amount of fee (typically 1/100th of a cent of a USD per transaction) for the mining verification service they provide for users of the blockchain. Needless to say, the economic incentive for miners is coming via both, the mining reward and the transaction fees.
Transaction block
Let us look a bit more into the details of a block of transactions. A block is a collection of transactions that happened in the stipulated amount of time available from the previous block. The Transactions that made it to the block in that time period are put in the order they have been received (by the miner) and each transaction when created is always represented by a hash. A hash is part of many cryptographic tools that Bitcoin uses to achieve security as it has a unique property as described below.
A Hash is a cryptographic function with its unique property that it can transform a given input to a fixed number of alphanumeric strings. The input provided can be numeric, alphanumeric, media files, and binary files. The output hash can be chosen to be 64-bit, 128-bit, 128-bit, or 256-bit depending on the choice of the hash algorithm. Another unique property of this hash function is that it is a one-way function, which means there is no way to generate the data if someone has the hash with them. This effectively means that even a one-character change in the input data can completely change the value of the hash output. These two unique properties enable the use of this hash function as a digital fingerprint for the data processed through the function.
Each transaction once created, will have a hash generated for it using the SHA256 algorithm and this is how the content and a transaction looks like for transaction with Hash: 828ef3b079f9c23829c56fe86e85b4a69d9e06e5b54ea597 eef5fb3ffef509fe
(https://whatsonchain.com/)
Figure 1.6: A typical Bitcoin transaction
As you can see each transaction has some metadata for it (timestamp, confirmations, the fee paid, block number) and then there are details of input and output for the transaction. All the data that belongs to the transaction is put through the SHA256 hash function (twice!!) and a 32 byte and 64 character length hash for the transaction is created.
Any block contains a large number of transactions, and now with increasing block sizes of a possible supported block, this could go into a million and plan is to make the block size unlimited so that miners can benefit the most when the block rewards are not providing sufficient value for their work to earn more rewards by the fees present in the large transaction volume. The structure of a block looks like this:
Figure 1.7: Structure of a block
Each block consists of a few fields which are described in the below table with the properties for each of the fields present in the block:
Table 1.1: Block field details
Once a block is created, the miners go through the mining process to add it to the blockchain to win the block reward and the transaction fees for their effort for preparing this block. There is however one more important concept called Merkle root that should be discussed regarding the block header information mentioned in Figure 1.8.
The transactions that are stored in the block are made immutable to prevent any malicious attempt to change the entries made in the blockchain using the idea/concept of storing all of the transaction hash that is in the block in a Merkle tree structure. This acts as a checksum and even if a small character in a single transaction changes will break the integrity of this information and the change will render the block invalid and hence not accepted by the consensus/validation process of miners.
In cryptography and computer science, a hash tree or Merkle tree is a binary tree in which every leaf node is labeled with the hash of a data block. This is shown as the Hash (tx1), Hash (tx2), etc. in Figure 1.8. Every non-leaf node is labeled with the cryptographic hash of the labels of its child nodes. This is shown in Figure 1.8 as Hash 1-2 and Hash 3-4. Hash trees allow efficient and secure verification of the contents of large data structures. Demonstrating that a leaf node is a part of a given Merkle tree requires computing a number of hashes proportional to the logarithm of the number of leaf nodes of the tree.
Let us look at it with a diagram:
Figure 1.8: A Merkle root hash representation for a block with 4 transactions.
If there are an odd number of transactions, suppose there is no tx4, the hash 3-4 will just be the hash 3-3 by using tx3 hash twice and the same process applies. Now that we have a view on what is a block, let us go back to the idea of the timestamp server that we started this description with and define what a blockchain is.
Once the hash of the transactions is stored in a block with the timestamp, it becomes a publically stored record of truth which cannot be tampered with by any means. These blocks stored chained with each other act as a timestamped server for the information stored in them. It is not just published publicly but also implemented as a distributed timestamp server on a peer-to-peer basis using a proof of work system.
The proof-of-work is a system that is designed to make a set of competing miners use computational power to generate a hash for the next block that they are competing to add to the existing blockchain. This new hash to be generated is controlled in terms of how complex it is to generate by one of the fields mentioned in the block header called the nonce. Miners use this computational power, continuously scanning for a value that when hashed, such as with SHA-256, the hash begins with a number of zero bits. The nonce defines these leading numbers of zero bits to control the difficulty of this process and is done by incrementing it in a block until a value is found that gives the block’s hash the required zero bits. The average work required is exponential in the number of zero bits required and can be verified by executing a single hash.
This process of using a proof of work system to make a block ensures that the block cannot be changed once generated without redoing the same amount of computational work. You can also see that as there are more blocks chained after any block, the work to change said block will include changing all of these blocks that are chained as well and this way the work to alter the block increases exponentially as the depth of the block increases in the blockchain:
Figure 1.9: Blocks chained with each other and their chaining with past block
The last step in the selection of block involves a number of miners coming to an agreement that the winning miner block is what they all agree to add to the blockchain by a network consensus proved by the winning miner’s proof of work. This essentially is the system that replaces a trusted network to validate the correctness of a transaction which we discussed in Figure 1.2. All of the miners who are investing their CPUs vote in this network consensus to decide on the majority decision for the next block addition and block winner among them by a consensus method described as Nakamoto consensus which essentially is: Proof-of-work is essentially one-CPU-one-vote.
There is always a possibility that multiple miners solve the hash puzzle at the same time and the blockchain may have a fork happening from time to time. This automatically will resolve as the network will keep adding new blocks to one or the other fork and the majority of (miners) decisions will be represented by the longest chain demonstrating greatest proof of work:
Figure 1.10: A temporary fork or orphaning of a block in the Bitcoin blockchain network
The network splits are possible but eventually, the longest chain is the one that survives and these forks die off. These are meant to be uncommon but perfectly natural scenarios. The block is usually referred to as orphan block and usually block 3 and 4 will be added to something called an orphan pool and it’s only when the next block is added one of the orphan blocks becomes the confirmed block. In short, an orphan block has a parent block but no children blocks.
The obvious concern here in the case of chain death scenario is that what happens to the transactions that were included in block 4 but not in block 3, do those transactions also die along with that fork? The answer is quite simple. A number of miners receive the transactions from individual wallets or business nodes, not all at the same time. All of these transactions are collected in something called a mempool. This can be considered as a temporary storage area where miners pick up transactions to make the new block. If the miner who mined block 3 did not pick up some transactions that were included in block 4, a miner who has (during network consensus) agreed to the transactions included in the block 3, will consider those transactions not yet included in the blockchain and hence a valid transaction and will include them in the block 5.
The last bit about mining is the concept of the nonce. This is a parameter that is used to control the difficulty of the block hash that is to be generated. The value is relooked at every two weeks and is determined by a moving average targeting an average number of blocks per hour. If they’re generated too fast, the difficulty increases and vice versa to keep block generation to an average of one block every 10 mins.
Bitcoin block is approximated to be added every 10 mins. For Bitcoin to work correctly it needs to be somewhere between five minutes and 20. The exact ideal optimal time is not calculable because it varies by time of day, season, use, electricity price, and many other factors that are not standard. This 10 mins time period was set primarily for introducing a sufficient amount of difficulty so that a minimum CPU power is invested to ensure the security of the network. A miner has to perform a set of tasks (Validate for veracity so that only valid blocks are propagated) before a new block can be added.
In validating a block, the miner will perform the following functions:
Block’s data structure is in the correct format.
Hash of block’s header is less than or equal to the target difficulty set for the ongoing two-week period.
The size of the block is less than or equal to the maximum block size permitted (e.g., currently 2 GB).
The first transaction of the block is a coinbase transaction, which pays the winning miner and only one coinbase transaction is present.
Each transaction in the block is valid. Each transaction, as well as its hash, must be individually checked and validated for also being accurate in terms of input and output amount of coins it has.
The concept of block size mentioned above became one of the key discussions and contention points in the Bitcoin ecosystem in the recent few years causing multiple forks of the original Bitcoin chain creating a demerger sort of event in prevalent terminology. The block size defines the capacity of Bitcoin blockchain defining what is the maximum number of transactions that are being processed every second, in turn defining the solution of the issue of scaling. I will briefly mention below the 3 major forks of Bitcoin which are based on few attributes either limited scaling or another concept related to privacy and anonymity which will be discussed in detail towards the end of this chapter:
BTC: This fork is currently having a block size of 1 MB as maximum limiting it to process a maximum of 3-5 transactions per sec. This also caused the introduction of RBF (replaced by fee) concept to enable a higher fee to expedite the inclusion of a transaction to get priority in processing. This rendered BTC not suitable for