Introduction to Blockchain
This is an introduction to blockchain and related concepts. Why Bitcoins are very much in news and why is it in huge demand? This article covers the basics of Blockchain and how cryptocurrencies like Bitcoins and Ethereum are built on it. The details of how Bitcoins achieve decentralization and how a trust is established in such a decentralized system is discussed in detail here. Also, the mathematical aspects of the Blockchain have been discussed.
As per the wiki definition, "A Blockchain is the continuously growing list of records, called blocks, which are linked and secured using cryptography. Each block typically contains a hash pointer as a link to a previous block, a time-stamp and transaction data".
The concept of blockchain involves a decentralized consensus via a distributed, permissionless and trustless protocol.
The reason why the blockchain has gained so much admiration is that:
- It is not owned by a single entity, hence it is decentralized
- The data is cryptographically stored on the blockchain
- It is immutable, so no one can tamper with the data that is inside the blockchain
- The blockchain is transparent, so one can track the data if they want to
Blockchain is NOT Bitcoin
The first thing that clicks in our mind when we hear Blockchain is "Bitcoin"! Of course, they are related to each other but are not the same. Bitcoin is a cryptocurrency, a virtual currency that was the first successful blockchain product. On the contrary, blockchain is a distributed ledger technology which underlies cryptocurrencies like Bitcoin but does not restrict itself to the FinTech industry only.
Head over to this link to understand the fundamental differences between Bitcoin & Blockchain.
Conventional Bank vs Blockchains
Let's look how money is maintained in a bank and how does it change when a transaction is initiated. This is a sample of money ledger maintained by a bank.
Now, how will the picture change when A wants to send 25 INR to B? A request will be made to the Bank to initiate the transaction. The following steps will be taken in order to complete the above transaction:-
- Bank will check if A and B are valid users of the Bank. In case of inter bank transfer, a request will be made to another bank to verify the customer.
- Bank will verify if A has the required amount in their account.
- Bank will deduct 25 INR from A's account and will credit the amount to B.
This is how a centralized bank would work. Now let us see how decentralization is achieved by Blockchain. The following steps will be taken in a perfectly decentralized system:-
- Person A advertises that they wants to send 25 INR to B. This advertisement is heard by everyone on the blockchain network.
- Every node of the network has his/her own money ledger table which updates when certain transactions are received.
- The advertisement received at each node is verified and then the corresponding change is made in the node's ledger table.
This is how any transaction is incorporated in a Blockchain. There are a lot of trust issues and security concerns associated with it. Some of them are briefly touched upon in next sections.
Authenticity of a user and transaction
The Blockchain must ensure that any transaction announcement reaching a node must be correct and genuine. A few security checks used are:-
All the conventional banking transactions are verified for authenticity using your signature. Similarly, all your transactions in Blockchains are verified using a digital signature. A digital signature is nothing but the results of a Mathematical Function. The mathematical function consists of three important functions.
- A password generator, (sk, pk) = GeneratePassword(size). This password generator generates a secret key and public key when an input size is given. The 'sk' is the secret key and is supposed to be kept secret. The 'pk' is the public key which is made available to everyone in the network. Note that it is impossible to guess secret key if you have the public key.
- A signature on the document, sign = Signature(sk, msg). The next step involves formation of a signed transaction, which is again a mathematical function whose input is your transaction message and the secret key of the person initializing the transaction. Now, this sign can be safely transmitted and sent to other nodes.
- Finally, a function to verify the authenticity, valid_or_not = verify(pk, msg, sign). A function then verifies the authenticity by comparing the sign, the message and the public key of the person initializing the transaction. The function returns a true or a false depending upon whether the user is authentic or not.
This was how a Digital Signature works in the context of Blockchain. Here is an article that elucidates the concept of digital signatures in general, while this article talks about them more from the perspective of blockchains.
There are various other algorithms implemented for verifying the signatures of the user, but the idea remains the same. For a more mathematical treatment of the algorithm, refer to the wiki page on Elliptic Curve Digital Signature Algorithm Elliptic Curve Digital Signature Algorithm (ECDSA). A short summary of including the crucial steps of ECDSA can be found here.
Hash functions are particularly used to ensure that the blocks entering into the blockchain are genuine and not falsely fabricated by someone for wrong use. A new block will contain the hash of the previous block and thus would be easy to detect a false block if there's an inconsistency in the hash output.
- Introduction to hashing, hash functions & their applications
- Evolution of Hashing & Different Hashing Algorithms
- Use of Hashing in Blockchain - with Merkle Trees
What's a Block in a Blockchain: Dealing with the problem of Double Spending Attack
What's a Block in this Blockchain and what does it contain?
Consider a case where A initiates a transaction to B worth 2 BTC (Unit of Bitcoin) and at the same initiates a transaction of the same 2 BTC to his friend C. Both the announcements will travel through different series of nodes and it may happen that at a certain node X, the second announcement reaches first. Now, unaware of the existence of another announcement of the same coin, the node X will add the second announcement and will reject the initial transaction. This would cause an irregularity in the maintained blocks. Thus, time-stamps can not be used as a tool to decide which announcement started first. In other words, a transaction arriving first does not imply it was created first. Hence, a better solution of using Blocks of transactions at once was adopted. This ensures the problem of double spending attack. The blocks can only be added to the chain when the corresponding hash of the block is correctly found. This requires computers to guess the answer. This require huge computation power. Once a correct key is found, the answer is announced to all the nodes and the block is finally added to the chain. On an average, this process takes 10 minutes in Bitcoins. Hence, unlike conventional transaction, it requires more time to complete a transaction and to get added into the chain.
Can I make a chain of my own?
It requires huge computation power and also speed to be able to guess the correct value corresponding to a new block. It is highly unlikely that a single computer will be able to create multiple blocks at a time. It would require huge computation power in order to achieve this. To have a 50% chance of correctly guessing each block, it would require you to have 50% of total computing power of the world. However, in theory, if you are able to make a chain longer than the existing bitcoin chain, then whatever chain you created will be used everywhere and hence, IN THEORY, you can change the entire data of transactions. But this won't happen anytime soon.
How account statements are incorporated in a blockchain
The above money ledge table in case of conventional bank system does not exist in case of blockchain. Then how does the blockchain verifies if you actually have the required balance to initiate a transaction? Actually, the blocks in a blockchain contain the public key of the sender, the receiver and the amount in the transaction. Hence, when a new transaction is to be verified, the nodes iterates through all the previous existing blocks and add the credit amounts while deducting the debit amounts. In this way, a node gets to know the validity of a transaction.
Quick question: You want to know your balance, how would you know it? Answer: Iterate through all the previous blocks and add up what you got minus what you spent.
How good are Bitcoins?
Advantages of Bitcoins
- Security and Control : It is based on well established encryption techniques and mathematics of cryptography.
- The complete code of Bitcoin is easily available, hence making it very transparent.
- Less Risks for Merchants: Due to the fact that Bitcoin transactions cannot be reversed, and do not carry with them personal information, merchants are protected from potential losses that might occur from fraud.
Disadvantages of Bitcoins
- Lack of Awareness & Understanding
- Bitcoin is still at its infancy stage with incomplete features that are in development.
The Concept of Decentralization
The decentralized nature of blockchain technology means that it doesn't rely on a central point of control. Those who participate in the blockchain network have the option to contribute their computer storage and download a copy of the blockchain to secure the data that is recorded on it.
There are 2 types of decentralization:
- Architectural Decentralization: How many physical computers is a system made up of? How many of those computers can it tolerate breaking down at any single time?
- Political Decentralization: How many individuals or organizations ultimately control the computers that the system is made up of?
- Logical Decentralization: If you cut the system in half, including both providers and users, will both halves continue to fully operate as independent units?
Currently used blockchain technologies fall under the first 2 categories of decentralization. Techniques like sharding, to make blockchains logically decentralized are an interesting area of research.
Following are some interesting resources to understand more about decentralization:
- The Need for Decentralization
- Principles of Decentralization
- The Essence of Decentralization (by Vitalik Buterin - Co-founder of Ethereum)
A consensus is a dynamic way of reaching agreement in a group. While voting just settles for a majority rule without any thought for the feelings and well-being of the minority, a consensus, on the other hand, makes sure that an agreement is reached which could benefit the entire group as a whole.
What is the Byzantine Generals Problem?
Imagine that there is a group of Byzantine generals and they want to attack a city. They are facing two very distinct problems:
- The generals and their armies are very far apart so centralized authority is impossible, which makes coordinated attack very tough.
- The city has a huge army and the only way that they can win is if they all attack at once.
In order to make successful coordination the armies on either sides of the castle need to send messengers to relay information. Here comes the problem: The messenger could get captured, compromised, killed and replaced with another messenger by the city. This would lead to the armies getting tampered information which may result in an uncoordinated attack and defeat. What these generals need, is a consensus mechanism which can make sure that their army can actually attack as a unit despite all these setbacks.
Following are some of the major Consensus Mechanisms that could be implemented in blockchains:
Proof of Work (PoW)
To summarize how Proof Of Work Protocol works with the blockchain.
- The network has nodes called miners who verify transactions and include them in blocks, that get added to the chain
- The miners solve cryptographic puzzles to mine a block in order to add to the blockchain
- This process requires immense amount of energy and computational usage
- The puzzles have been designed in a way which makes it hard and taxing on the system
- When a miner solves the puzzle, they present their block to the network for verification
- Verifying whether the block belongs to the chain or not is an extremely simple process
- Miners are incentivized for their resources used in the form of a Block Reward associated with each block
Trivia: Bitcoin initially started with a block reward of 50 BTC. The block reward is halved after the discovery of every 210,000 blocks, which takes around four years to complete. As of February 2018, one block reward is worth 12.5 BTC.
This article helps answer several questions surrounding the concept of Proof of Work.
Proof of Stake (PoS)
PoW is highly resource intensive and causes scalability issues. A promising alternative is the Proof of Stake mechanism. PoS will make the entire mining process virtual and replace miners with validators.This is how the process will work:
- The validators will have to lock up some of their coins as stake.
- After that, they try to discover a block which they think can be added to the chain by validating it by placing a bet on it.
- If the block gets appended, then the validators will get a reward proportionate to their bets.
Head over to this article in order to understand the processes involved in Proof of Stake consensus.
In the context of blockchains, it means once data has been written to a blockchain no one can change it. This is implemented by including the hash pointer of a block header in the next block. Tampering with any data on an existing block will change the block hash of that block, resulting in a discrepancy in the next block, all the way to the end of the chain. Since the currently used PoW mechanism is extremely resource-intensive, mining all the blocks again from the tampered block right to the end of the chain is practically impossible for the attacker.
Ethereum is a decentralized platform created by Vitalik Buterin that runs smart contracts: applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference. In the Ethereum blockchain, instead of mining for bitcoin, miners work to earn Ether, a type of crypto token that fuels the network. The second type of token that is used to pay miners fees for including transactions in their block, it is called gas. Every smart contract execution requires a certain amount of gas to be sent along with it.
Ethereum’s core innovation, the Ethereum Virtual Machine (EVM) is a Turing complete software that runs on the Ethereum network. Instead of having to build an entirely original blockchain for each new application, Ethereum enables the development of potentially thousands of different applications all on one platform.
Several organizations are currently working to scale up Ethereum and fill the loopholes. Some technologies that are areas of active R&D include:
- Proof Of Stake (Casper)
- Plasma: It is a protocol that will allow the Ethereum blockchain to remove the need to process unnecessary data
- Sharding: Network will be divided into smaller parts (shards) and individual shard will hold different transaction history
- Raiden: The idea centers on taking payment transactions off-chain
Check out the following articles to widen your understanding about Ethereum:
Smart contracts are self-executing contracts with the terms of the agreement between parties being directly written into lines of code. The code and the agreements contained therein exist across a blockchain network. They can be used for all sort of situations, such as financial derivatives, insurance premiums, property law, and crowdfunding agreements.
A smart contract for a particular purpose is coded and placed on the blockchain. A triggering event (such as expiration date, etc.) results in the execution of the contract according to the terms agreed upon by involved parties. Since the contract is on the blockchain, anyone on the network can verify it. This removes the necessity of a centralized authority required to oversee the agreement such as a lawyer, etc.
- Beginner's Guide to Understanding Smart Contracts
- Our wiki has a Tutorial on getting started with Ethereum Smart Contracts development
Real World Applications of Blockchain
- Financial Services
- Asset Management: Trade Processing and Settlement
- Insurance: Claims processing
- Blockchain Internet-of-Things
- Supply Chain Sensors
- Smart Appliances
- Blockchain Healthcare
- Personal health records could be encoded and stored on the blockchain
- Ledger could be used for supervising drugs, regulation compliance, testing results, and managing healthcare supplies
- Social Networks
- Blockchain distributed nature eliminates the control of platforms by a single entity
- Users on decentralized social networks will own and control their data
- Transparent and trusted source of information for the farmers
- Establishing direct link between farmers and consumers/retailers
- Blockchain Government (Voting)
- Companies like “Follow My Vote” are using the blockchain technology
- Land Registry
- A hash is taken of the geo-coordinates along with a polygonial description of the land.
- This hash is tied to the owner’s ID and the result is hashed again and added to the blockchain.
- Since the hash is always a unique value, everyone will have a unique ID.
- Because of the blockchain’s immutability, no one can tamper with the records.
Blockchain is currently in a very nascent phase. It can be compared to the Internet of the 1990's. There is a long way to go in perfecting this technology, yet it has started impacting several areas of potential application. Organizations across the globe have started developing decentralized applications and have initiated a great amount of research in new consensus mechanisms, improving scalability, stability of token value, etc.