Table of Contents
Introduction
Blockchain which is the underlying technology for the cryptocurrency Bitcoin, has evolved and become a technology which has the power to disrupt the way sectors like finance, healthcare, energy, voting and other industries are working.
This guide will deep dive into explaining the Blockchain Architecture starting with what is a blockchain, Blockchain Architecture’s difference with the Client Server Model, Blockchain components-blocks, transactions, nodes, miners and wallets and how does the Blockchain work. We will also discuss briefly the security of a Blockchain Architecture and its possible use cases.
Let us begin.
What is a Blockchain?
Blockchain in Simple Terms
As the name suggests, a Blockchain is a chain of blocks. A block in this chain or series is a database containing digital data or information, while the chain represent the binding of these blocks using cryptographic functions. This chain of blocks or data is shared in a Distributed network of multiple nodes (computers or servers).
Blockchain is the new revolutionary and more secure way of record keeping in which the records are distributed (shared among all the members of the network),immutable (cannot be changed), transparent (visible to all in the network) and added in a chronological order.
Blockchain Architecture vs the Client Server Architecture
The Blockchain architecture is contrary to the traditional/normal web structure we witness. In the normal web structure-client server model, a central server stores and has authority over all the data. We as the clients request data that we need from these Central servers. For instance take the example of Google. Google stores and has the authority of all the data. We request the data that we need from Google.
Risks posed by Client Server Model |
Data compromise and manipulation: First, since the data is stored and controlled centrally it can be compromised and manipulated. |
Single Point of Failure: If the Central Server fails the entire network fails. |
An analogy to explain Blockchain will be a peer to peer network of computers. Each of these computers called nodes have a copy of the ledger or file containing digital records. Now the algorithm of the network is such that, as soon as a new item or data is added to one of the copies of the ledger, it gets automatically updated in all the copies with all other nodes of the network. This ledger is the Blockchain and the whole network of computers represent the Blockchain network. |
Now let us understand what do we mean by a Block in a Blockchain.
A Block in a Blockchain
Let us understand this with an example. Suppose, Flipkart (that we use frequently for online purchases), is made up on Blockchain. Then for each of your purchase transactions through the Flipkart, the data will be stored in a Block of the Blockchain. In fact one Block of the Blockchain will have multiple purchase data of other buyers using the portal.
A Block in a Blockchain normally contains up to 1 MB of digital data. Now the Block will normally contain your transaction data (purchased items, cost, time, date, etc.) and your identity (a Digital Signature assigned to you).
All these data in a block is stored in the form of a cryptographic code by applying Hash function.
Hash is a Cryptographic function which when applied on any data of any length or form (text, image, audio, etc.) produces a unique output (called Digest) which is of a definite length. Also this output value is unique for each and every input value.
Each block contains the hash of the data stored in the block and the hash of the data stored in the previous block.
Genesis Block and Uncle or Ommer Blocks
The first Block in a Blockchain is known as the Genesis Block. Ommer or Uncle Blocks are the detached Blocks which are not chosen for inclusion in the Blockchain ledger. Please see the figure below.
Blockchain: Formal definition
Now that we have a layman perspective, we can now formally define a Blockchain as a method of storing records of digital data among multiple parties which is immutable (cannot be changed), distributed and can be shared directly peer to peer without the use of a Centralized authority.
Blockchain is disrupting the way data was stored or kept. It is a more secured way of record-keeping in which we do not need to trust any Central Authority like Google, Facebook for keeping the data secured.
For example, Amazon is a central authority or a centralized database which has tera bytes of data of your shopping, your transactions, your card details, etc. We trust the Amazon server for keeping our data safe, which is of course ensured by certain legal obligations that Amazon has to obey. But again that is our trust on the legal system or the Government. Forget any bad practices, suppose the Amazon server is hacked or gets down, then it will surely impact us with our confidential data stored. Here comes the Blockchain technology which does not have any central point for record keeping. Data is transparent and immutable.
The three pillars of the Blockchain technology are:
1. Immutable data, because cryptographic principles are used to store data
2. Peer-to-peer connection: Data can be shared directly peer to peer between any two nodes (computer or servers) of the system
3. Data is Distributed, i.e. a copy of the data lies with every node of the system.
Blockchain Architecture: How does a Blockchain work?
Blockchain technology is all about devising a more secured and efficient way of data storage or record keeping. Data in a blockchain is immutable, decentralized (not controlled by any Central Authority) and transparent.
In fact, the Blockchain Technology is not an entirely new one. In fact it is an amalgamation of conventional high performing technologies to produce the most efficient, secure and transparent way one can store records and perform transactions. In order to understand what is going inside, let us understand the technological components which make it the behemoth DISRUPTIVE TECHNOLOGY.
These technologies or rather the Blockchain components are:
- Cryptographic Hash Function
- Asymmetric Cryptography for Identity Management
- Transaction using Cryptography
- Wallets
- Blocks
- Consensus Mechanism
- Addition of Blocks in the Blockchain
Cryptographic Hash Function
A Cryptographic Hash function is an algorithm which can convert any input (of any length like file, text, image, etc.) into a unique output called ‘digest’ of alphanumeric string of the same length. For example let us see an example Hashing by using the popular Hashing algorithm called SHA-256.
Input Text | SHA-256 Digest Value |
Hello, World! | 0xdffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f |
Cryptography has the below unique traits.
- Unique output. Hence no two different inputs can have the same digest or output value. This property is known as being Collision Resistant.
Hence, given two input values ‘x’ and ‘y’ it is computationally not practical to have Hash (x)=Hash (y). - Fixed length string of alphanumeric characters. For any two input values, come whatever be, a Hash function will always produce the same length Output or Digest. For example the cryptographic hash function SHA-256 produces 64 character of alphanumeric digest for any input given to it.
- Preimage Resistant. This means that it is computationally impractical to find out the input value of a given Output or Digest.
Examples of Cryptographic Hash Functions are Secure Hash Algorithm (SHA-256) and Keccak.
Let us check where the cryptographic Hash function is employed in a Blockchain.
Cryptographic Hash function in Blockchain
Cryptographic Hash function is employed to attain Ultra-Security in the Blockchain Network. The different applications of the Cryptographic Hash function in the Blockchain network (not limited to) are:
- Creating unique addresses of the Nodes/Users in the Blockchain network. Private Keys and Public Keys are derived using the Hash function, which we will see later in the guide.
- Hashing (and hence securing) of the data in a Block (Blocks contain a number of Candidate Transactions in a Blockchain. Blocks are described below in the article).
- Hashing (and hence securing) of the Block Header.
- Hashing of the data in the previous block.
Identity Management: Asymmetric Key or Public Key Cryptography
Blockchain uses Asymmetric Key Cryptography, in which each user has a pair of keys- Public Key and a Private Key. The Public Key is derived by applying cryptographic function on the Private Key. Even though there is a relationship between the two keys, the private key cannot be found from the public key.
The Public key is shared with other users in the network, though the Private key is kept confidential for accessing and owning the digital assets (like cryptocurrency).
It can be understood by the analogy of the email that we use. We have an email id for sending and receiving data with another person, and in order to login to his/her email he/she should have a password. Similarly one has the Public Key to send and receive digital assets (like cryptocurrency) with other users in the Blockchain, but in order to access and own the data one needs to have a Private Key.
One can encrypt with a private key and then decrypt with the public key. Alternatively, one can encrypt with a public key and then decrypt with a private key.
Below we have shown a generic model of the Cryptography phenomena.
As you can see the Sender uses a Key (Key 1) to encrypt the plain text into the Ciphered text or coded text. The receiver uses Key (Key 2) in order to reconvert the ciphered text to plain text which is readable to the human being.
Symmetric Cryptography: For the above example, if both the keys (Key 1 and Key 2) are same (pre-decided between the sender and the receiver), then such a cryptographic arrangement is known as Symmetric Cryptography.
Asymmetric Cryptography: When both the sender and receiver use different keys (Key 1 and Key 2 in the above example) then it is called a Asymmetric Cryptography.
Asymmetric Cryptography (Public and Private Keys) in a Blockchain
As said, the Blockchain Technology uses Asymmetric Key Cryptography.
The Public key is the identity which is shared with other users in the Blockchain network. Whereas the Private Key is kept confidential and must not be shared or known to other users of the network in order to maintain the data assets confidential.
Let us now understand in detail the application of Asymmetric Cryptography or Public Key Cryptography in blockchain.
One can encrypt with a private key and then decrypt with the public key. Alternatively, one can encrypt with a public key and then decrypt with a private key.
Let us suppose Nitin has to send a data packet (like one having cryptocurrency) to Harleen. If Nitin does not employ any cryptography the data can be opened by anyone in between and can be tampered.
Hence Nitin needs to employ cryptography to the data packet to be sent to Harleen.
In blockchain Asymmetric Cryptography is used to:
- Ensure that only the intended receiver can open the data packet and
- Ensure the integrity of the data, i.e. the data packet is received from the intended sender.
Let us see how Nitin can apply Asymmetric or Public Key cryptography and send data packet to Harleen.
- First, Nitin locks or encrypts the data packet using the Public Key of Harleen. Now only Harleen with the corresponding Private Key can open or decrypt the data packet. This ensures that only the intended receiver gets to open the file.
- Second, Nitin applies another lock or encryption using his Private Key. This can be decrypted by Harleen using the corresponding Public Key of Nitin. This ensures data integrity, i.e. the data has arrived from the intended source-Nitin in this case. If the data packet does not open with the Public Key of Nitin it implies the data was sent from an unknown sender.
If you encrypt (“lock”) something with your private key, anyone can decrypt it (“unlock”), but this serves as a proof you encrypted it: it’s “digitally signed” by you.?
Panayotis Vryonis
Note: One cannot afford to loose the Private Key as it can be used to access all your Digital Assets in the Blockchain Network.
Digital Signature
The Public Key and the Private Key combine to generate the Digital Signature. Digital Signature is used for verifying and signing transactions
Transaction
A transaction or a Candidate Transaction in a Blockchain Network is any data or digital asset (cryptocurrency in the case of a crypto Blockchain) which a user or a node in a Blockchain Network sends to another user in the network.
A Transaction data will be made up of:
- Input data which is the data or digital asset to be transferred.
- Output data: The outputs are usually the accounts that will be the recipients of the digital assets along with how much digital asset they will receive. Each output specifies the number of digital assets to be transferred to the new owner(s), the identifier of the new owner(s), and a set of conditions the new owners must meet to spend that value. If the digital assets provided are more than required, the extra funds must be explicitly sent back to the sender (this is a mechanism to “make change”).
Please note that a Transaction in a Blockchain Network must be (a) Authenticated and (b) Validated. The Validity of the Transaction ensures that the transaction meets the pre-formalized data formats or smart contract requirements specific to a Blockchain Network. The Authenticity of the transaction ensures that the sender of the digital assets owned and had access to those digital assets. The sender typically digitally sign the transaction using his Private Key, which can be verified at any time using the associated Public Key. This phenomena is called Asymmetric Key Cryptography (as we saw in the previous section). |
Wallets
Simply put, a wallet is an electronic device or a software application which connects a computer to the blockchain. It holds your Public and Private keys. The wallet initiates transactions to send or receive cryptocurrencies. For example, a Bitcoin wallet will connect to the Bitcoin blockchain and will initiate transactions to send and receive Bitcoin.
Examples of wallets you will find are Coinbase, Trezor, Electrum, Robinhood, Exodus, Ledger Nano.
Broadly there are two categories of wallets.
- Hardware Wallets
- Software Wallets of Hot Wallets
Hardware wallets are more secure than Hot Wallets. But depending on the usage and the amount of investments, you can choose between the two categories. For instance, for the novice investor having a few dollars of investment, Hot or Software wallets are advisable.
While if large sums of money are involved always store your Private Keys in a Hardware Wallet like Trezor or Ledger Nano.
For a broader understanding of wallets please check this guide.
Blocks
We already explored Blocks earlier in this guide.
A Block in a Blockchain normally contains up to 1 MB of digital data. A Block will normally contain your transaction data (example-purchased items, cost, time, date, etc.) and your identity (a Digital Signature assigned to you).
Normally in most of the Blockchains a Block will have a Block Header and Block Data. Please check the figure below which gives a detailed description about a Block in a Blockchain.
Consensus Mechanism
By now we know that Blockchain is a decentralized Database. This means that every member of a Blockchain network has a copy of the blockchain database.
But how does a new Block of data is added to the Blockchain? Who verifies the data in the block before adding it to the Blockchain?
In a Centralized system this is no issue as the Central Authority takes care of validating and adding the data to the Central repository. For example in the conventional banking system (centralized) all your transactions are validated and added to the centralized database by the Bank itself.
In a Blockchain, a Consensus mechanism is followed to verify and add a new block of data to the Blockchain. There are different types of Consensus mechanisms developed which are employed in different blockchain networks. For instance, Bitcoin blockchain employs the Proof of Work consensus, while Cardano employs Proof of Stake. Ethereum at the time of writing this article employs Proof of Work too.
In a Blockchain, Miners (who are the members of the Blockchain network) compete among themselves to verify and add Blocks (containing digital data) to the Blockchain. Miners adhere to the Consensus Mechanisms developed for the specific blockchain, in order to validate Blocks to be added to the Blockchain ledger.
There are different mechanisms developed for the miners to compete. Example, in Proof of Stake, miners compete to solve a computational problem. The miner who solves the problem first gets to verify and add block to the Blockchain.
The two most popular Consensus Mechanisms are discussed below.
Proof of Work (PoW)
- The PoW is the first Consensus mechanism developed for Blockchains. It was devised to reach consensus in the Bitcoin Blockchain.
- Miners compete with each other to solve a mathematical puzzle using their CPU power. The Miner who solves the puzzle first is the winner.
- The winning Miner propagates the Block to be added to the Blockchain. Other Miners start validating the transactions in the Block till it reaches an agreed-on-percentage (51 percent or 90 percent as per the configuration).
- Then the winning Miner gets the chance to add Block to the Blockchain and is rewarded (with cryptocurrencies).
Used in: Bitcoin, Ethereum
Advantages: Time tested; Safe
Disadvantages: Too slow and massive Power consumption
Proof of Stake (PoS)
- The PoS is based on the economic stake of a validating member in the Blockchain. By stake we mean the money which the validator has deposited in the network.
- In order to become a validating member to validate transactions to be added to the network one must deposit some economic stake in the network.
- In PoS each validating member gets his/her turn to vote and propose a Block in the Blockchain network. The weight of his/her vote depends on the size of his/her economic stake.
Used by: Ethereum’s upcoming Casper model of consensus
Advantages: Security, reduced risk of centralization, and energy efficiency
Disadvantages: more prone to attack as there is no computational factor like with POW to keep the network safe
Minting: In PoS the entire process of validating and adding a new Block to the Blockchain network and getting rewarded, is called Minting (not Mining)
Addition of Blocks in the Blockchain Network
Let us check the steps involved in the addition of a new block in the Blockchain.
Addition of a new Block in the Blockchain
Step 1: Transaction is initiated
A Node or User in the Blockchain Network initiates a transaction to send digital assets (data or cryptocurrencies) to another User or Node.
For example in a Bitcoin Blockchain the data can be Bitcoin which one person sends to another person (peer-to-peer) in the Bitcoin Blockchain Network.
Note: A Node or User can send this data using a mobile or desktop application or by using a Digital Wallet.
Step 2: Transaction is Validated and Authenticated
The algorithm of the Blockchain checks for the validity and authenticity of the data. Validity is confirmed by checking whether the data is in the specified format of the network. Authenticity is confirmed by checking whether the data has been digitally signed by the sender using his Private Key.
Note: Validation and Authentication of the data by the Blockchain algorithm does not ensure its addition to the Blockchain ledger(the distributed ledger).
Step 3: Authenticated and Validated Transaction waits is a queue with other similar transactions
The validated and authenticated data waits in a Queue with other transaction data, until a Publishing Node creates a Block with all these individual transaction data.
Note: In a Blockchain, we need Publishing Nodes to add a Block (which stores individual candidate transactions) to the network. The question arises why will a User or a Node like you and me will take this responsibility to publish or add Blocks in the Blockchain. The answer is because of financial benefits. For example, in the case of Bitcoin, a Publishing Node which is also called a Miner gets Bitcoins in return for publishing a Block in the Blockchain. But this is not an easy task. Multiple users compete with each other in order to add a Block in the Blockchain.
Step 4: A Publishing Node adds the transaction to a Block with other similar transactions
A Publishing Node adds all the validated and authenticated transactions waiting in the queue to a Block. As mentioned, there is a monetary reward associated with addition of a new block to the Blockchain.
Step 5: Publishing Nodes compete with each other
As said multiple publishing nodes compete with each other at the same time to add a Block in the Blockchain. But the question is who decides for which among the competing nodes will add his/her Block. Is there a Central Authority which decides this? The answer is NO!
Blockchain uses Consensus Models (discussed earlier) in order to resolve the dispute among Users for the addition of the next Block in the Blockchain. There are different Consensus Models such as the Proof of Work, Proof of Stake, Round Robin, Proof of Authority or Identity, etc. Each Blockchain uses one of these Consensus models to decide who adds the next Block in the Blockchain.
The Bitcoin uses the Proof of Work Consensus Model in which each publishing node tries to solve a computationally intensive puzzle which requires much resources (Electricity and CPU power). The Node which solves the puzzle first is accepted as the Winner and adds the next Block in the Blockchain.
Step 6: Winner Node adds his/her respective block to the Blockchain
The winner node adds his/her respective block of transactions in the Blockchain.
The figures below show how a Block is added to a Blockchain.
Blockchain Architecture Security
Blockchain is safer and is a transparent and decentralized method used for record keeping. The data stored cannot be changed (immutable) and transparent (visible to all the members of the Blockchain network). This is contrary to a Centralized mode of data keeping, where data is controlled by a Central Authority. Risks of data manipulation and even hacking of the Central Server are there in a Centralized mode of record keeping.
Let us see why it is practically impossible to tamper the data in a Blockchain.
The blockchain uses Hash function to cryptographically store data in its blocks.
A hash is a cryptographic function created for a Block by the Blockchain algorithm. The Hash of a Block is based on the digital data which is stored in the Block. This means that if the digital data is tampered then the Hash function also changes.
A Block in the Blockchain stores its Hash as well as the Hash of its previous Block.
Now when a Hacker tampers the data of a Block then it will automatically change the Hash of the Block (as the Hash is derived from the data in the Block). Since this Hash is also stored in the next Block of the Blockchain a mismatch is created. Hence now the Hacker will need to change the Hash of the next block also. Again the mismatch will happen with the Hash stored in the next Block and so on.
Hence in order to change the data in one of the blocks a Hacker will have to change the Hash of each of the Blocks in the Blockchain after the Block he wants to tamper. This will require enormous computational Power and Energy (money) which is practically impossible.
Blockchain Architecture: Possible Use Cases of Blockchain
By now we have learnt that a Blockchain has two vital traits, the combination of which makes it unique and employable in so many facets of our lives. These two vital traits are:
- Immutable: Data stored in a blockchain is immutable or cannot be changed. As we saw this is mainly due to the cryptography, its decentralized nature and the basic algorithm which govern a blockchain.
- No third party or Central authority is needed. In the real world scenario whenever a third party is involved in any data transaction, for example a money transaction, then a cut or percentage of the payment gets to this third party. For example, when you are transferring money to your friend, the bank (third party) generally earns a commission. Similarly when you buy something using your credit card, then the credit card charges are applied. Add to it the trust we need to have on these third parties for keeping our confidential data (card numbers, money, etc.) safe.
Hence we can use the Blockchain technology in cases where we are looking to eliminate the third party (for avoiding any transaction fees) or whenever data security is of utmost importance. Though data security is also promised by the conventional Internet, this is not as promising as it is in the Blockchain network. We studied the reasons (distributed, cryptography, algorithm) above. Some of the Industries where Blockchain technology is being employed for greater security and peer to peer transaction are shown in the figure below.
Conclusion
By now we have understood the Blockchain architecture starting with what Blockchain is, its components-blocks, transactions, nodes, miners and wallets and how does the Blockchain work. We also discussed Blockchain architecture versus the client server model of data storage.
We will be dedicating a separate guide to discuss different types of Blockchain Architectures, its security including the risks posed, and the possible use cases.