Everything You Should Know About Blockchain.
And how it's changing the modern world
A lot has changed since blockchain first arrived in the 1990s and since then it's changing our world in a way no one has predicted. If you have been active on the internet you must have heard people throwing words like NFT, Ethereum or you must have heard about some famous crypto coin like Dogecoin or Bitcoin.
Here is a tweet of Elon musk about Dogecoin.
Here is a tweet about Jack Dorsey which was sold for NFT for over $2.9 million
All the famous cryptocurrencies like BTC, Ethereum, or any other coin like Ethereum classic or Bitcoin cash run on Blockchain and something to know NFT which works on Ethereum which runs on Blockchain.
So the question arises what is this BLOCKCHAIN everything is running on.
Genesis of The Blockchain
Well, the blockchain is originated way before any cryptocurrencies emerged or hypothetically saying, even theorized. A cryptographer named David Chaum first tossed the idea of the blockchain-like protocol in his 1982 dissertation " Computer Systems Established, Maintained, and Trusted by Mutually Suspicious Groups ".
Further work on a cryptographically secured chain of blocks was described in 1991 by Stuart Haber and W. Scott Stornetta. They wanted to implement a system wherein document timestamps could not be tampered with.
It wasn't till 2008 when the first blockchain was conceptualized by a group/people know as Satoshi Nakamoto. Nakamoto improved the design in an important way using a Hashcash-like method to timestamp blocks without requiring them to be signed by a trusted party and introducing a difficulty parameter to stabilize the rate with which blocks are added to the chain. The design was implemented the following year by Nakamoto as a core component of the cryptocurrency bitcoin, where it serves as the public ledger for all transactions on the network.
How Blockchain works
As the name suggests blockchains are nothing but a big chain of interconnected blocks. Where every block contains their previous block's hash value and that is how they are linked as well as their own unique hash.
Now that we have a gist of what blockchain is let's dive deeper into the technicality of Blockchains.
Blockchains are decentralized and transparent which means anyone can add their own block on the blockchain given that they have to do certain work to add it. This process is called mining and it is well rewarded. We will talk more about mining later in this article.
It is well secured by powerful cryptography which makes it impossible to tamper with. Also, blockchain is publicly broadcasted and are decentralized which makes it immutable and impossible to temper.
But what is Decentralization?
To understand this concept of decentralization let's first understand how banks and transactions work right now.
Suppose you want to share money with your friend Bob who is miles away from you. So what will you do is open your Application on your mobile and transfer the money to Bob's account.
So what is happening behind the scene is you are not sending money to Bob instead you are sending a message to the bank.
A message you kidding me? Well, if you think a little more money is nothing but some number in this digital world.
So our message might look something like this.
"To" : "BOB",
"From" : "Alice",
"Ammount" : "500 $"
So in this message, we are saying send 500$ to Bob. After the bank receives this message from your device it will check so certain tasks to complete the transaction.
It will open the ledger ( A ledger balance is computed by a bank at the end of each business day and includes all withdrawals and deposits to calculate the total amount of money in a bank account.) and check if Alice has enough money to transfer i.e if Alice has 500$ or more.
If the above condition is met then the ledger is updated where the new balance of Alice will be the old balance - 500 $ and a new balance of the Bob will be the old balance + 500$.
After this both receive a message that their transaction is successful.
So this was how the transaction works with banks. But the problem with it is you can never verify the transaction yourself or you can never see what is happening inside the book of the bank you trust they can manage your money and all the power is centralized around the bank. They have the power to create new money (as I already said it's just a number) or transfer if they want.
This centralization of power is something from which the community is not happy with and blockchain solves the problem using a decentralized method of adding a transaction.
Now let's understand how Blockchain handles this kind of transaction between Alice and Bob.
Now Alice wants to send some money to Bob through Blockchain. This transaction will happen without the interference of any central power.
So what's really happening is shown in the below image.
When a transaction is made it creates a block that block is then sent to every node where miners compete with one another to add that block to the main block. On successfully doing that each miner is paid in cryptocurrencies, but that is the miner's logic which can be discussed in the next article.
For now, we understood how decentralization happens in the blockchain.
So now you might though if no one is governing the transactions then how is it getting validating and adding to blockchain who is doing all that work? Here come's the miners who validate the transaction and add it to the block.
Who are Miners and how Mining Logic Works
Well, till now it's clear that the blockchain is made of a number of blocks. So what are these blocks and which kind of data do they contain.
Well if we see an overview block looks something like below.
In this, we can see that a single block contain
- Previous Hash
- Merkel Root.
But in exact a block look something like this with a lot of data
You can see all the transactions and blocks of the public Blockchain. Here I used Etherscan to get the block data but there are a lot of services out there.
So what happens is every time transactions are made they came to miners where miners validate the transactions and then try to add that block to the public Blockchain.
Why I used "try to add"? Instead of add, well every miner is trying to add a new block to the Blockchain continuously all the time and it's like a race between every miner.
The way blockchain validates a block is valid or not is called Consensus Mechanism. There are different ways the Consensus Mechanism works one which is very popular is Proof of Work others are Proof of stake, Proof of Capacity, Proof of Activity* .
In this article, we will only talk about the Proof of Work.
In Proof of Work, every miner has to compute a hash value for the block in some given condition.
Let say you are a miner and you have to calculate a hash value that should start with 4 0's
for example : 0000x147a9393258780beef7d
to calculate something like this take a lot of trial and error and a lot of computational power. And also there is only one thing you can change in the block which is the value of Nonce.
So for every time you want a new hash value, you keep incrementing the value of Nonce and by finding a valid hash you can add that hash to the block.
Well if any miner can add to the Blockchain isn't that make the Blockchain untrustable and unsafe.
Well here comes the power of Decentralization to save you. Every time a miner adds a block to the Blockchain other miners do a validation check on that block. If the block is valid and matches with their own version of Blockchain if everything is valid they add that Blockchain to their own version of Blockchain and start mining the new block.
Say, if some malicious group tries to add an invalid block to the Blockchain for their own profile. After successfully mining the Blockchain their block will be rejected by other miners which can cost them a lot of money and computation power.
If another miner successfully mines a valid block the whole Blockchain will move to that version of the block and malicious manner have to sync up to mine the next block.
Well, for every success full mining each miner is given some reward. For mining on BTC Blockchain, it's BTC coin and on mining on ethereum Blockchain, it's ethereum.
fun fact: It's the only time a new coin is created. (It's just an analogy)
well till now we learned about what is Blockchain and now a new block is created and added.
But, we have no clue about how transactions take place in the blockchain.
How the transaction works in Blockchain.
Let's again take Alice and Bob's example and understand the transaction in-depth and how every transaction is protected.
But before that let us look at the concept of asymmetric encryption.
Asymmetric encryption and how it works in Blockchain.
Now, to understand this let's first understand how symmetric encryption works. Suppose Bob wants to send some data to Alice but the data is sensitive and Bob wants to send this in a way that only Alice can read it. Alice will send her on the box so that Bob can put the data in a box and close it. Once the box is closed only Alice can open the Box with her key, let's call this key Alice's Private key.
Now in cryptography same concept is happen, to send a message to Alice Bob encrypts the data using the Hash function such that only Alice's private key can Hash it back to the original data.
The problem with the above method was for every time Alice wants to receive a message Alice have to create numerous keys and boxes to receive messages from numerous people. This can be really problematic and hence the concept of the Asymmetric key was introduced.
Now in the Asymmetric Encryption key, Alice has two keys one is called Alice's private key and the other is called Alice's Public key. Now the public key is shareable and the private key must not be disclosed.
Now, every time someone wants to send a message to Alice they can use Alice's public key and send it to Alice now that message can only be decrypted by Alice's private key.
The math behind is quite long so we will discuss it in later articles, but for now, we understood the private and public key concept. Let's see how it is implied in Blockchain
In Blockchain when Alice wants to send money to BOB that data will be sent to the miner where they verify some conditions like the following.
- Does Alice have enough money?
- Does Alice is the one who sent the money to Bob or is it someone else.
For checking the available balance in the wallet BTC uses something called UTXO. An overview on UTXO will be that it is a set of all the previous transaction is done by Alice and after adding and subtracting everything if the balance matches then miner approve the transaction.
And to verify if the transaction Is came from Alice something called a Digital signature is used where Alice signs with her private key and sends it to the miner with other data. Well, you have to understand that those logics are automatically implemented in the wallet and Alice doesn't actually sign anything. Moving on what kind of data is sent to the miner?
Well, the data might look something like this with other data of course
Once it is received the miner will validate the transaction and add it to the Blockchain. Once added to Blockchain the data becomes immutable.
Today we learned about how Blockchain works and how data/transactions are added to the Blockchain. Once the transaction came to the miner, the miner validates the data and calculates a valid nonce value to add his version of the block to the Blockchain. Once added the miner get a reward but if the miner tries to add malicious data then it gets declined by rest of the miner and once more than 50% miners agree to some nonce then that will become the main branch and malicious data will not be added to the main branch of the blockchain.
So, this was an overview of Blockchain technology I hope you liked the article. I will be posting more in-depth knowledge about this topic from time to time. To get notified please subscribe to my newsletter.
Did you find this article valuable?
Support Ashish maurya by becoming a sponsor. Any amount is appreciated!