Blockchain
UNIT-4 : Blockchain Technology Stack
Data Structure of Blockchain
• What Is a Merkle Root?
• A Merkle root is the hash of all the hashes of all the transactions that are part
of a block in a blockchain network.
• A Merkle root is a simple mathematical method for confirming the facts on a
Merkle tree.
• They're used in cryptocurrency to ensure that data blocks sent through a
peer-to-peer network are whole, undamaged, and unaltered.
• They play a very crucial role in the computation required to keep
cryptocurrencies like bitcoin and ether running.
Working of Merkle Trees
• A Merkle tree totals all transactions in a block and generates a digital
fingerprint of the entire set of operations, allowing the user to verify
whether it includes a transaction in the block.
• Merkle trees are made by hashing pairs of nodes repeatedly until only
one hash remains; this hash is known as the Merkle Root or the Root
Hash.
• They're built from the bottom, using Transaction IDs, which are
hashes of individual transactions.
• Each non-leaf node is a hash of its previous hash, and every leaf node
is a hash of transactional data.
Benefits of Merkle Tree in Blockchain
• Merkle trees provide four significant advantages -
• Validate the data's integrity: It can be used to validate the data's integrity
effectively.
• Takes little disk space: Compared to other data structures, the Merkle tree
takes up very little disk space.
• Tiny information across networks: Merkle trees can be broken down into
small pieces of data for verification.
• Efficient Verification: The data format is efficient, and verifying the data's
integrity takes only a few moments.
Blockchain Technology Stack
• Application Layer:
• This is the top layer of the stack, where decentralized applications (DApps) are built. DApps are software
applications that run on top of blockchain networks and interact with smart contracts and other blockchain
features. Developers use programming languages and frameworks to create DApps that provide various
functionalities such as financial services, supply chain management, gaming, and more.
• Smart Contracts Layer:
• Smart contracts are self-executing contracts with the terms of the agreement directly written into code. This
layer is responsible for executing smart contract code, which can be triggered by predefined conditions or
transactions. Ethereum's Solidity is a popular programming language used for writing smart contracts, while
other blockchain platforms offer their own smart contract languages.
• Protocol Layer:
• The protocol layer defines the rules and consensus mechanisms that govern the blockchain network. It
includes components like the consensus algorithm, network protocol, and validation rules. Common
consensus algorithms include Proof of Work (PoW), Proof of Stake (PoS), and Delegated Proof of Stake (DPoS).
• Consensus Mechanism:
• The consensus mechanism is a critical part of the protocol layer. It determines how nodes
in the network agree on the state of the blockchain. Different mechanisms ensure
agreement, security, and data consistency among participants. Apart from PoW, PoS, and
DPoS, there are other mechanisms like Practical Byzantine Fault Tolerance (PBFT), Raft,
and more.
• Network Layer:
• The network layer handles communication between nodes in the blockchain network. It
establishes peer-to-peer connections, propagates transactions and blocks, and ensures
data synchronization. The network layer is responsible for maintaining the connectivity
and integrity of the blockchain network.
• Blockchain Layer:
• This layer stores the actual blockchain, which consists of a chain of blocks containing
transactions and other relevant data. Each block is linked to the previous one through
cryptographic hashes, creating an immutable and tamper-resistant ledger. The blockchain
layer provides data persistence and ensures the security and integrity of recorded
transactions.
• Cryptography and Security Layer:
• Cryptography is used throughout the blockchain stack to secure data, ensure privacy, and create
cryptographic proofs. This layer includes cryptographic algorithms for key generation, digital
signatures, encryption, and hashing. Security protocols and mechanisms protect against attacks
and ensure the confidentiality of sensitive information.
• Data Storage Layer:
• The data storage layer comprises various data structures and databases that store
blockchain-related information. Depending on the blockchain's design, data may be stored in
different ways, such as on-chain (inside the blockchain) or off-chain (external databases or storage
systems).
• APIs and Middleware:
• APIs (Application Programming Interfaces) and middleware provide interfaces for external
applications and services to interact with the blockchain. They abstract the complexity of
blockchain operations, making it easier for developers to integrate blockchain functionality into
their applications.
• User Interface (UI) Layer:
• This layer encompasses the user interfaces that users interact with to access and manage their
blockchain-related activities. It includes interfaces for creating transactions, interacting with
What is a Blockchain Protocol?
• Protocols are rules which govern the functioning of a blockchain.
Since Blockchains are a network of computers which operate on a
peer-to-peer basis, protocols define how information is transferred
between computers on the network.
• Blockchains which note all the transactions of a specific crypto token
need to be governed by a set of rules. These rules are essentially the
heart of the blockchain. It gives an idea to the miners, stakers and the
investing community about how exactly the blockchain functions. The
rules also help investors identify if the crypto is worth investing in or
not.
Hyperledger
• An open-source blockchain protocol, Hyperledger was developed by
the Linux Foundation. As a permissioned blockchain, only authorized
parties are able to participate in the network. The protocol is scalable,
flexible, and modular, so it is suitable for enterprise apps. Hyperledger
targets organizations in different industries and aims to enable
business transactions and other financial services.
• The protocol’s smart contract engine enables companies to more
easily develop and deploy smart contracts. Hyperledger also offers
individuals a secure channel where they can share private data.
Multichain
• It is a blockchain protocol built for communication within
organisations or between organisations. Multichain provides solutions
for private blockchains. Multi-chain provides an API which can be
utilised for the development of blockchain solutions. It cuts down the
development time by almost 80% according to the multi-chain
website. Unlike public blockchains, blockchains built using Multichain
offer complete control over the blockchain and hence it is most suited
for organisations to deal with high-privacy financial transactions like
banking.
Ethereum
• The Ethereum protocol is designed around smart contracts, where
contracts are automatically performed without the need for third
parties when certain conditions on the network are met. The designs
of the Ethereum network are scalable, which means it can handle
numerous transactions per second, making it perfect for
decentralized apps (dApps) that need to handle huge amounts of
data.
Quorum
• Quorum, which is enterprise-focused, aims to help organizations in
the finance industry and has major backing from those financial
institutions. An open-source project developed by J.P. Morgan Chase,
Quorum can be used by anyone. Built on Ethereum, it is compatible
with smart contracts and Ethereum tools.
Corda
• It is an open-source project which enables interoperability, which is
the power of exchanging information between various blockchains.
Transactions performed using Corda are transparent and highly
anonymised at the same time. While its solutions are tailored towards
banking, several integrations of Corda can make it a dependable
solution for any application. It is accredited by the R3 banking
consortium making it a marquee name for blockchain solutions for
banking.
Ledger Conflicts and Resolution
• What are conflicts?
It is possible, that the two different miners solve the Proof-of-Work at the same
time and thus add their blocks to the last known block in the chain.
Now, we have two branches after Block 103. Both the branches are valid. So the
next mined block may be added in either of the branches. Suppose, the miner
adds the newly mined block to Block 104-A, the branch containing Block 104-A
will be longer than the branch containing Block 104-B.
.
• In Bitcoin architecture, the longest branch always wins and the
shorter ones are purged. So the Block 104-B has to be purged. Before
purging this block, all transactions in this block will be returned to the
transaction pool so that they are mined and added to some future
block. This is how the conflicts are resolved and only one single chain
of blocks is maintained by the system
Forking
•Forking is a term that refers to a situation where a cryptocurrency or token project
needs to make technical updates to its own code.
•These updates will either be applied to the backend of a project with no major
changes in service, or they will fundamentally change the scope of the original
project.
•Forking implies any divergence(divison) in Blockchain- temporary or permanent.
Very simply,forking is said to happen when a Blockchain splits into two branches.
•It can happen as a result of a change in consensus algorithm or other software
changes.
•Depending on the nature of change, the fork can be categorized into Hard Fork
and Soft Fork
Hard Fork
• A hard fork is a permanent divergence from the previous version of the Blockchain, and
nodes running previous versions will no longer be accepted by the newest version.
• A hard fork is a radical change to the protocol that makes previously valid blocks or
transactions invalid.
• Any transaction on the forked (newer) chain will not be valid on the older chain.
• All nodes and miners will have to upgrade to the latest version of the protocol software
if they wish to be on the new forked chain.
• This essentially creates a fork in the Blockchain, one path which follows the new,
upgraded Blockchain, and one path which continues along the old path.
• Hard Fork is usually done only when there is enough support from the mining
community. Only when the majority of miners give positive signal towards the upgrade
or fork, the developers of the chain starts work on the upgraded code.
Hard Fork
• A good example of a Hard Fork was when Bitcoin Cash came into existence. Previously
Bitcoin was the dominant player in the cryptocurrency game. But as transaction times
slowed and fees started to rise, the future of Bitcoin came into question.
• Generally, there are two different ways which a hard fork can occur. It can either be:
Contentious or planned
• A planned hard fork means that the creators/developers were all in agreement as to
how the coin would be forked. When this occurs, there is no split in the chain. This is
because all of the nodes have agreed to upgrade to the latest version of the coin’s
client that possesses the rule change.
Hard Fork - Contentious hard fork
•If there was disagreement in the community about the path of a coin, like Bitcoin, for example, then
a contentious hard fork would occur. The most notable example of this is the creation of Bitcoin Cash.
• Another Example : A well-known example of a hard fork is from Ethereum. In 2016, a smart
contract was constructed on Ethereum called the Decentralized Autonomous Organization
(DAO). Due to flaws in how the smart contract was constructed, an attacker extracted Ether,
the cryptocurrency used by Ethereum, resulting in the theft of $50 million [15]. A hard fork
proposal was voted on by Ether holders, and the clear majority of users agreed to hard fork
and create a new version of the blockchain, without the flaw, and that also returned the
stolen funds.
Soft Fork
•A soft fork is said to happen when a change to the software protocol
keeps it backward compatible.
•What this means is that the new forked chain will follow the new rules
and will also honor the old rules.
•The original chain will continue to follow the old rules.
•This kind of fork requires only a majority of the miners upgrading to
enforce the new rules, as opposed to a hard fork which requires
(almost) all nodes to upgrade and agree on the new version.
Soft Fork
•New transaction types can often be added as soft forks, requiring only
that the participants for e.g. sender and receiver and miners
understand the new transaction type.
•This is done by having the new transaction appear to older clients as a
“pay-to-anybody” transaction (of a special form) and getting the miners
to agree to reject blocks including this transaction unless the
transaction validates under the new rules.
•A soft fork can also occur at times due to a temporary divergence in
the Blockchain when miners using non-upgraded nodes violate a new
consensus rule their nodes don’t know about.
Smart Contracts
•They are logic or code that operate on block chain
•They are part of the block chain in Ethereum
•They are immutable, it should be carefully coded
•Solidity is popular to code smart contract, EVM (Ethereum virtual machine) is the
computer that runs the code.
•EVM is the engine of ethereum.
•Smart contracts are lines of code that are stored on a blockchain and automatically
execute when predetermined terms and conditions are met.
•At the most basic level, they are programs that run as they’ve been set up to run by the
people who developed them.
•The benefits of smart contracts are most apparent in business
collaborations, in which
they are typically used to enforce some type of agreement so that all
participants can be
certain of the outcome without an intermediary’s involvement.
Difference between Traditional and Smart
Contracts
What are the benefits of smart contracts?
• Speed and accuracy: Smart contracts are digital and automated, so you won’t have to
spend time processing paperwork or reconciling and correcting the errors that are
often written into documents that have been filled manually. Computer code is also
more exact than the legalese that traditional contracts are written in.
• Trust: Smart contracts automatically execute transactions following predetermined
rules, and the encrypted records of those transactions are shared across participants.
Thus, nobody has to question whether information has been altered for personal
benefit.
• Security: Blockchain transaction records are encrypted, and that makes them very hard
to hack.Because each individual record is connected to previous and subsequent
records on a distributed ledger, the whole chain would need to be altered to change a
single record.