The five layers of blockchain: Application layer, Consensus layer, Network layer, Data layer, and Execution layer.
Core Concepts:
- Execution Layer: Manages code execution, including smart contracts, utilizing virtual machines or compilers to interpret and execute code.
- Data Layer: Stores and manages blockchain data, including blocks, Merkle trees, hash functions, transactions, distributed storage mechanisms, timestamps, and digital signatures.
- Network Layer: Establishes peer-to-peer connections between nodes, enabling block propagation, synchronization, and scalability enhancements like sharding and Directed Acyclic Graph (DAG) structures.
- Consensus Layer: Employs consensus algorithms to validate transactions and maintain network integrity and efficiency.
- Application Layer: Facilitates user interaction with blockchain through user interfaces (UI), smart contracts, chaincode, and decentralized applications (DApps), enabling diverse functionalities and interactions within the blockchain ecosystem.
Blockchain technology operates through various components, which are categorized into five layers. These layers form the architecture of blockchain, as illustrated in Figure below. Let’s explore each layer in detail and provide associated examples.
Execution layer
The execution layer manages the execution of all code and instructions carried out on the application layer. An example of this is when a smart contract gets executed. This layer typically consists of a virtual machine, docker or any compiler to interpret and execute the code.
Data layer
Responsible for storing and managing data within the system, this layer includes essential components like the chain structure, blocks, Merkle tree, hash functions, transactions, distributed storage mechanism, timestamps, and digital signatures. We’ll delve deeper into each of these components below.
Block
At the core of a blockchain lies the block. Each block comprises two main parts: the block header and the transaction records. Check out the structure of a block in the figure below.
The block header contains four fields:
- Previous Hash: This field stores the hash value of the previous block in the blockchain. By including the hash of the previous block, each block is linked to its predecessor, forming a chain. This linking ensures the immutability and integrity of the blockchain.
- Data: The data field contains a batch of transactions that have been validated and added to the block. These transactions could involve the transfer of digital assets, the execution of smart contracts, or any other operation supported by the blockchain network.
- Nonce: The nonce is a crucial parameter used in the process of mining, which is integral to the consensus mechanism of proof of work (PoW) blockchains like Bitcoin. Miners compete to find a nonce value that, when combined with the block’s data, produces a hash value that meets certain difficulty criteria.
- Hash: The hash value of the block is generated using a cryptographic hashing algorithm, such as SHA-256 (Secure Hash Algorithm 256-bit). This algorithm takes into account the data, nonce, and previous block’s hash to produce a unique and fixed-length hash value for the current block. The hash serves as the digital fingerprint of the block, uniquely identifying it within the blockchain network. Any change to the block’s data or structure would result in a completely different hash value, making it tamper-evident and preserving the integrity of the blockchain.
The transaction records section of the block contains the actual transactions that have been included in the block. These transactions represent various activities performed on the blockchain network, such as transferring digital assets between users, executing smart contracts, or recording data onto the blockchain ledger.
Merkle tree
The Merkle tree is a cryptographic data structure used in blockchain to verify the consistency and summarise the content securely and efficiently. The Merkle tree creates a digital footprint of all transactions, enabling users to verify whether a transaction is included in a block. The Merkle tree root is modified when a transaction gets altered. This root is contained in the data field from the block header.
The Merkle tree root, or root hash, is created through the iterative process of hashing pairs of nodes until only a single hash remains. Every leaf node stores the hash of transaction data, while every non-leaf node stores the hash of its previous hashes. An example of what the Merkle root looks like is shown in the Figure below.
Hash Function
Blockchain employs SHA-256 to secure blocks and ensure data immutability, thus preventing unauthorized access. SHA256 (or Secure Hash Algorithm 256) is utilised as a hashing algorithm to transform any text of variable length into a standardized 256-bit (32-byte) string.
In a Bitcoin system, miners solve complex mathematical puzzles, known as proof of work (PoW), to validate transactions. The goal is to determine the nonce value. This value is the puzzle required to solve to be able to generate a hash (Arora, 2022).
Transactions
A transaction in blockchain is any type of user activity that occurs within the network. In Bitcoin, for example, it occurs when a user sends bitcoins to another user. The transaction life cycle in a PoW based blockchain can be found here xxx.
Distributed storage
Blockchain revolves around three fundamental concepts, a public distributed ledger, SHA-256, and the consensus algorithm. A distributed ledger contains all the information regarding transactions in the blockchain network. Once a block gets approved by the consensus algorithm, it is appended to the existing chain. Here, a decentralized ledger is formed and each node contains a copy of that ledger. Furthermore, each block has a cryptographic signature along with a timestamp to ensure that the ledger remains auditable and immutable.
Digital signature
Digital signatures are based on public key cryptography (PKC). PKC contains the public key paired with the private key, where the public key is accessible to authorized users and the private key only belongs to the owner. Either of the keys can be used to encrypt a message, while the one not used for this, is utilised to decrypt the message.
A user’s address is used as their public key. Their private key is then used to access their digital money. Say a user sends a message to a receiver. The digital signature of the message is generated using the hash value of the message along with the sender’s private key. The hash function transforms the original message into a fixed-size hash value, which then gets encrypted with the sender’s private key. The receiver can verify the message by firstly generating the hash value of the message. The digital signature can then be decrypted using the sender’s public key. The verification process only works if the hash values are the same.
There are different types of digital signatures. Bitcoin uses the Elliptic Curve Digital Signature Algorithm (ECDSA). When a transaction is created, it includes a signature that serves as a proof of authenticity. The transaction is only added to the blockchain if the signature gets verified by the other nodes. Bitcoin utilises the ECDSA to leverage the principles of public key cryptography to uphold against tampering and to verify that the transaction was initiated by the rightful holder of the private key associated with the public address (public key) used in the transaction.
Network Layer
The network layer establishes connections between nodes over a peer-to-peer network, allowing block propagation and network synchronization. Additionally, it guarantees that each node contains a copy of the ledger, enabling them to compare it with other nodes to verify the accuracy of the data.
To enhance scalability, some blockchain systems implement sharding. This approach works by partitioning the network into smaller committees, known as shards, to minimize the resource requirements of consensus protocols. Unlike traditional blockchain systems, each node is only responsible for handling information related to its shard. Each shard has its own set of nodes that apply the consensus algorithm.
Alternatively, the Directed Acyclic Graph (DAG) presents a different structure from traditional blockchain models. In DAG-based blockchains, the transactions are organised in a directed graph, unlike the linear chains. The idea behind DAG is that a new transaction is only recorded if at least two earlier transactions are validated. Each transaction is validated by at least two parent transactions and there is no need for miners to authenticate the transactions, thereby increasing the development time.
Consensus layer
The consensus algorithm is responsible for achieving agreement amongst the nodes in the network to validate transactions and the order in which they are added to the chain. Blockchain relies on a consensus mechanism to uphold its trustworthiness, security, and operational efficiency. There are different types of consensus algorithms which is discussed xxx.
Application layer
The application layer includes programs that allow users to utilize blockchain. This layer has two sub-layers: the presentation layer (layer 1) and the execution layer (layer 2). Layer 1 includes user interfaces (UI), scripts, and APIs (application programming interface). This layer allows users to interact with the functionalities of blockchain and it encompasses design, layout, and other user interface components. Layer 2 includes smart contracts, underlying rules, chaincode, and DApps.
Decentralized applications operate in a decentralized network such as blockchain. A DApp can interact with blockchain using smart contracts or chaincode. A smart contract is “a computerized transaction protocol that executes the terms of a contract”. Chaincode is a specific type of smart contract used in Hyperledger Fabric to implement and execute predefined business rules on the blockchain network.
Summary:
Blockchain technology is structured through a complex and multi-layered architecture, each playing a critical role in maintaining the system’s functionality, security, and integrity. From the execution layer, which handles code execution, to the data layer where data is securely stored and managed via mechanisms such as the Merkle tree and cryptographic hashing; each layer contributes uniquely to the blockchain’s operation. The network layer ensures robust peer-to-peer communication and synchronization, while the consensus layer is vital for validating transactions and achieving participant agreement, using various algorithms to maintain system reliability and trustworthiness. Finally, the application layer offers the interface and operational protocols that allow users to interact with and utilize blockchain functionalities, facilitated by components like smart contracts and decentralized applications (DApps). Collectively, these layers form a formidable structure that underpins blockchain systems, making them not only revolutionary in terms of technology but also foundational for future innovations in digital transactions and decentralized data management. Understanding each of these layers and their interconnections is essential for anyone looking to engage deeply with blockchain technology, whether from a development, investment, or research perspective.