Overview of Blockchain Technology

Overview of Blockchain Technology

Blockchain:  The blockchain is an ordered data structure, which stores the blocks of transactions in back-linked list form.The blocks in the blockchain are linked back to their parent or previous block. Therefore, blockchain can be imagined as a vertical stack with the first block at the bottom and its child blocks forming layered structure one on top of the other with the youngest child at the top.The height of the stack will refer to the size of the blockchain.

Block Structure: A block is a container in the blockchain data structure that stores the transactions along with the status of the transaction. Generally, the size of the block is around 1mb.

Fig. 1. Simplified structure of the block

image

The block is made of block size field, followed by the header that contains the metadata, transaction counter keeping the record of the number of transactions and finally the list of the transactions which is variable in its size.

Block Header 

The block header consist of 3 blocks of metadata that are:

  1. Previous block hash: which refers to the previous block in the blockchain.
  2. Difficulty, Timestamp, and Nonce: used in making the system secure against any fraud transaction and mining process.
  3. Merkle Tree root: which is a data structure that is used for efficient summarization of all the transaction that takes place in the block.

Fig. 2. describes the structure of block header.

image

Block hash

  • The block hash value is used as the main identifier for identifying blocks in the blockchain.
  • The block hash is generated by using the SHA256 cryptographic hash algorithm on block header.
  • The 32-byte resulting hash value generated by the algorithm is known as block hash.
  • The block hash value is neither stored on the node’s storage nor included in the block’s data structure. Instead, the metadata of the block stores a database table which contains the block hash values for faster retrieval and indexing.
  • The hash value is computed by each node of the network as the block is received.

Merkel Tree

  • Merkel tree is a binary tree data structure which used to efficiently summarize all the transaction in the block. The tree is constructed by repeated hashing of the pair of nodes, till there is only one hash left which is the root node. Consider a case where there are n transaction to summarize than the time complexity to search any transaction in a Merkel a tree is given by O(2*log2(N)), which is very efficient.
  • The tree is built in a bottom-up manner. For example, A and B are two transactions which form the leaf node of the Merkel tree. Their data is hashed by the SHA256 cryptographic hash algorithm resulting in a 32-byte hash value each. Now, these pair of leaf node is summarized in the parent node by concatenating the two 32-byte hash value forming a 64-byte hash value. The 64-byte hash value is then double-hashed to generate a 32-byte hash value for the parent’s node.

Fig. 3. Merkel tree structure

image

The 32-byte hash value is stored in the block header. Since Merkel tree is a binary tree it needs even number of the transaction. Therefore, if they are the odd number of transaction to summarise, it copies the last transaction hash value for making the number of leaf node to be even.

Blockchain Linking: Each block in the blockchain has a hash value which is generated from the block’s header. The block’s header has a previous hash field which refers to the hash value of its parent. Therefore, this sequences of hashes connecting each block to its parent block, all the way back to the first block forms a chain of blocks called as the blockchain.

Fig. 4. Blockchain

image

Each node in the network maintains a local copy of the blockchain,starting from the first block or the genesis block.When a node receives a block from the network, it will first verify these blocks and then add to the existing blockchain. For verification, the node examines the previous hash field of the new block’s header. If the node is able to get the hash field of the first block or the genesis block from the previous hash field of the new block, then the new block is added to the blockchain as it is the child of the same genesis block.

Smart Contract:  The second generation of blockchain made the transactions without the need for a third party reliable by the help of user-defined script knows as smart contracts. The smart contract is a user-defined, partial or self-executing script which states and enforces the contractual agreement.The smart contract helps in verification and allow the transaction between the blocks to occur. They are stored in the blockchain itself, and hence are irreversible and traceable by every node in the blockchain network.The blockchain being decentralised technology, the smart contract cannot be tampered or be controlled by any node in that network and therefore provide credibility for the transaction to occur without any third party involvement.