Unit - 1 BCT Fin
Unit - 1 BCT Fin
BLOCKCHAIN
1.)Block chain:
A blockchain is a distributed ledger with growing lists of records (blocks) that are
securely linked together via cryptographic hashes. Each block contains a
cryptographic hash of the previous block, a timestamp, and transaction data
(generally represented as a Merkle tree, where data nodes are represented by
leaves). Since each block contains information about the previous block, they
effectively form a chain (compare linked list data structure), with each additional
block linking to the ones before it. Consequently, blockchain transactions are
irreversible in that, once they are recorded, the data in any given block cannot be
altered retroactively without altering all subsequent blocks.
A blockchain was created by a person (or group of people) using the name (or
pseudonym) Satoshi Nakamoto in 2008 to serve as the public distributed ledger for
bitcoin cryptocurrency transactions, based on previous work by Stuart Haber, W.
Scott Stornetta, and Dave Bayer. The implementation of the blockchain within
bitcoin made it the first digital currency to solve the double-spending problem
without the need of a trusted authority or central server. The bitcoin design has
inspired other applications and blockchains that are readable by the public and are
widely used by cryptocurrencies. The blockchain may be considered a type of
payment rail.
Private blockchains have been proposed for business use. Computerworld called
the marketing of such privatized blockchains without a proper security model
"snake oil";[8] however, others have argued that permissioned blockchains, if
carefully designed, may be more decentralized and therefore more secure in
practice than permissionless ones.
2.)Block chain as Public Ledgers
Introduction
Most businesses keep a “ledger”, a book that describes the important events
(transactions) that took place. A public ledger is a common use of the blockchain
concept In fact, supporting public ledgers is the main original motivator for
blockchain technology in the first place. The idea of a public ledger is to make all
of the transactions in the system public, so that the operations on the application
(all the transactions) are transparent to all parties.
keep the identities of the parties in the transaction secure and anonymous, while
also confirming who they are. (If that seems contradictory, look again at the
section on public key cryptography.)
keep the state of all participants based on the transactions that have occurred
Consider the use case of debt between a groups of people. Instead of paying, debt
is recorded to resolve sometime in the future. The ledger would keep track of all
transactions. This allows the system to update the state (account balance) of those
involved by adding or subtracting from their money balance, and verify the
participants using public/private key pairs (which, by the way, keeps the real-life
identity of the participants secure). Because the ledger is made public, at all times,
all transactions are publicly known, verifiable, and immutable.
Account Balances
When a blockchain is used to maintain a public ledger, it is a big, long series of
transactions. Let’s repeat that: The blockchain is a Big, Long series of transactions.
Maybe millions of transactions, taking up hundreds of gigabytes of space for the
complete ledger. That is far too much information to process sequentially in order
to find all the additions and subtractions to a participant’s account, in order to
know their current account balance.
Fortunately, there is a fairly simple way to keep track of account balances even
within the paradigm of storing a series of transactions. This is the Unspent
Transaction Output (UTXO) model. Under this model, your total account balance
is reflected by the output of your transaction. For example, if you currently have a
total of 10 coins and you want to buy a product that is worth 2 coins, your
transaction must spend all your 10 coins. So, your transaction will actually send 2
coins to the seller address, and send the 8 remaining coins (back) to your account.
With the UTXO model, you don’t have to trace back through multiple transactions
in the history to find out the participant’s total balance, as their total balance is
stored at the latest transaction.
Distributed ledgers are public ledgers that do not have a central controller who is in
charge of adding blocks to the system. A distributed ledger has all of the goals of
any public ledger. However, across a network of nodes, there are multiple copies
of the ledger (the blockchain and its contents). In fact, anyone is welcome to keep
their own copy. The challenge is how to add new data to the blockchain when there
is no trusted party to do this. This is where the Consensus Algorithm comes in.
Those are complicated (aside from the cryptography primitive functionality, they
are the only part of blockchain technology that is in fact complicated). We will talk
about these in detail in later modules. For now, you can just accept that there is an
agreed upon way by which some members of the community can propose new
blocks to be added to the blockchain, along with a mechanism for the community
to collectively accept the update.
Bitcoin
Bitcoin (BTC) is a cryptocurrency, a virtual currency designed to act as money and
a form of payment outside the control of any one person, group, or entity, thus
removing the need for third-party involvement in financial transactions. It is
rewarded to blockchain miners for verifying transactions and can be purchased on
several exchanges.
It has since become the most well-known cryptocurrency in the world. Its
popularity has inspired the development of many other cryptocurrencies. These
competitors either attempt to replace it as a payment system or are used as utility or
security tokens in other blockchains and emerging financial technologies.
The most well-known cryptocurrency, Bitcoin, is the one for which blockchain
technology was created. Like the United States dollar, a cryptocurrency is a digital
means of exchange that uses encryption techniques to oversee the establishment of
monetary units and verify financial transfers.
The Bitcoin blockchain refers to the data stored in “blocks” of information that are
then linked together in a permanent “chain.” A block is a collection of Bitcoin
transactions from a specific period. Stacks of blocks are stockpiled on top of each
other, with each new block relying on the previous ones. As a result, a chain of
blocks is formed, giving rise to the word “blockchain.”
Every time a new block is added, it makes the previous blocks unmodifiable. This
ensures that each block is more secure over time, and it is an example of how
Bitcoin technology is changing how banking and financial transactions are being
made.
Bitcoin blockchain, however, is much more than cryptocurrency: It is the
technology that most cryptocurrencies are built on, including Bitcoin. The Bitcoin
blockchain is unique because it ensures that all transactions are accurate. Every
action in the blockchain is recorded and there is nothing that is left out of the
network. Once an action is recorded and stored in one of the information blocks, it
is time-stamped and secured, and the entire record is available to anyone in the
system.
The Bitcoin blockchain is also decentralized, meaning it is not stored in one master
computer or controlled by one company. It is distributed on many computers that
are in the network.
In the Bitcoin blockchain, there are codes called a hash. A hash is unique to each
block in the blockchain. Hashing allows every network user to identify each block
and directs them to move in the chain since every block has its own hash and a
previous block's hash.
With the latter in mind, the critical parts of the blockchain include records, block,
hash and chain. Block records and transactional records are the two types of
records in the blockchain. A block contains the most recent Bitcoin transactions
that have not yet been recorded in any previous block. Transaction records include
the asset, price and ownership data that are recorded, approved and settled across
all nodes in seconds.
The idea of blockchain technology was introduced in 1991 by Stuart Haber and W.
Scott Stornetta in their paper “How to Time-Stamp a Digital Document.” In this
paper, they explained the use of a continuous chain of timestamps to record
information securely.
The term peer-to-peer means that the computers that are part of the network are
equal to each other, that there are no “special” nodes and that all nodes share the
burden of providing network services. It is made up of thousands of Bitcoin nodes
that run the protocol. The protocol is responsible for establishing and safeguarding
the blockchain.
Every Bitcoin transaction happens in the Bitcoin blockchain network, which is the
digital space where Bitcoin mining and hash power generation occur. Hashing
power is the processing power used by your computer or hardware to perform and
solve various hashing algorithms. These algorithms are used to create new
cryptocurrencies and allow them to trade with one another. This process is called
mining.
The blockchain works as a ledger, tracking every Bitcoin transaction, and is self-
verifying, meaning that the entire network of nodes — different computers
participating in the network — will constantly check and secure every movement.
Here is where the “miners” come into the game: Their computers do the heavy
lifting of maintaining the chain and thus, receive Bitcoin as a reward. These rules,
collectively, are the Bitcoin protocol.
OR
Bitcoin
Satoshi Nakamoto introduced the bitcoin in the year 2008. Bitcoin is a
cryptocurrency(virtual currency), or a digital currency that uses rules of
cryptography for regulation and generation of units of currency. A Bitcoin fell
under the scope of cryptocurrency and became the first and most valuable among
them. It is commonly called decentralized digital currency.
A bitcoin is a type of digital assets which can be bought, sold, and transfer between
the two parties securely over the internet. Bitcoin can be used to store values much
like fine gold, silver, and some other type of investments. We can also use bitcoin
to buy products and services as well as make payments and exchange values
electronically.
When you send an email to another person, you just type an email address and can
communicate directly to that person. It is the same thing when you send an instant
message. This type of communication between two parties is commonly known as
Peer-to-Peer communication.
Whenever you want to transfer money to someone over the internet, you need to
use a service of third-party such as banks, a credit card, a PayPal, or some other
type of money transfer services. The reason for using third-party is to ensure that
you are transferring that money. In other words, you need to be able to verify that
both parties have done what they need to do in real exchange.
For example,
Suppose you click on a photo that you want to send it to another person, so you can
simply attach that photo to an email, type the receiver email address and send it.
The other person will receive the photo, and you think it would end, but it is not.
Now, we have two copies of photo, one is a simple email, and another is an
original file which is still on my computer. Here, we send the copy of the file of the
photo, not the original file. This issue is commonly known as the double-spend
problem.
Smart contracts are a type of Ethereum account. This means they have a balance
and can be the target of transactions. However they're not controlled by a user,
instead they are deployed to the network and run as programmed. User accounts
can then interact with a smart contract by submitting transactions that execute a
function defined on the smart contract. Smart contracts can define rules, like a
regular contract, and automatically enforce them via the code. Smart contracts
cannot be deleted by default, and interactions with them are irreversible.
Within a smart contract, there can be as many stipulations as needed to satisfy the
participants that the task will be completed satisfactorily. To establish the terms,
participants must determine how transactions and their data are represented on the
blockchain, agree on the “if/when...then…” rules that govern those transactions,
explore all possible exceptions, and define a framework for resolving disputes.
Security
Blockchain transaction records are encrypted, which makes them very hard to
hack. Moreover, because each record is connected to the previous and subsequent
records on a distributed ledger, hackers would have to alter the entire chain to
change a single record.
Savings
Smart contracts remove the need for intermediaries to handle transactions and, by
extension, their associated time delays and fees.
Applications of smart
contracts
1.Safeguarding the efficacy of medications
OR
What Is Smart Contract?
Smart contracts are self-executing contracts in which the contents of the buyer-
seller agreement are inscribed directly into lines of code.
Because smart contracts are digital and automated, there is no paperwork to deal
with, and
No time was spent correcting errors that can occur when filling out documentation
by hand.
There's no need to worry about information being tampered with for personal gain
because there's no third party engaged and
Security
Because blockchain transaction records are encrypted, they are extremely difficult
to hack.
Savings
A smart contract is a sort of program that encodes business logic and operates on a
dedicated virtual machine embedded in a blockchain or other distributed ledger.
Step 1: Business teams collaborate with developers to define their criteria for the
smart contract's desired behavior in response to certain events or circumstances.
Step 4: The developers then use a smart contract writing platform to create and test
the logic. After the application is written, it is sent to a separate team for security
testing.
Step 8: Once it obtains the necessary combination of events from one or more
oracles, the smart contract executes.
Let's consider a real-life scenario in which smart contracts are used. Rachel is at
the airport, and her flight is delayed. AXA, an insurance company, provides flight
delay insurance utilizing Ethereum smart contracts. This insurance compensates
Rachel in such a case. How? The smart contract is linked to the database recording
flight status. The smart contract is created based on terms and conditions.
The condition set for the insurance policy is a delay of two hours or more. Based
on the code, the smart contract holds AXA's money until that certain condition is
met. The smart contract is submitted to the nodes on EMV (a runtime compiler to
execute the smart contract code) for evaluation. All the nodes on the network
executing the code must come to the same result. That result is recorded on the
distributed ledger. If the flight is delayed in excess of two hours, the smart contract
self-executes, and Rachel is compensated. Smart contracts are immutable; no one
may alter the agreement.
Smart contracts allow you to create voting systems in which you can add and
remove members, change voting rules, change debating periods, or alter the
majority rule. For instance, you can create a vote for a decision within a
decentralized autonomous organization. Rather than a central authority making a
decision, a voting mechanism within the organization can determine whether the
proposal is accepted or rejected.
Suppose you want to start a business requiring funding. But who would lend
money to someone they don't know or trust? Smart contracts have a major role to
play. With Ethereum, you can build a smart contract to hold a contributor's funds
until a given date passes or a goal is met. Based on the result, the funds are
released to the contract owners or sent back to the contributors. The centralized
crowdfunding system has many issues with management systems. To combat this,
a DAO (Decentralized Autonomous Organization) is utilized for crowdfunding.
The terms and conditions are set in the contract, and every individual participating
in crowdfunding is given a token. Every contribution is recorded on the
Blockchain.
Because smart contracts can't send HTTP queries, they can't acquire information
about "real-world" events. This is by design.
Using external data could jeopardize consensus, which is critical for security and
decentralization.
The use cases for smart contracts range from simple to complex.
They can be used for simple economic transactions, such as moving money from
point A to point B, as well as for smart access management in the sharing
economy.
DISTRIBUTED CONSENSUS
Example –
OR
The longest chain is what individual nodes accept as the valid version of
the blockchain. The rule that nodes adopt the longest chain of blocks allows
every node on the network to agree on what the blockchain looks like, and
therefore agree on the same transaction history.
The longest chain is what individual nodes accept as the valid version of
the blockchain.
The rule that nodes adopt the longest chain of blocks allows every node on the
network to agree on what the blockchain looks like, and therefore agree on the
same transaction history.
In other words it means that computers acting independently over a network can
maintain a globally shared view of a file.
The target is what blocks must get under to be added on to the chain.
However, if the difficulty increases (because blocks were mined more quickly
than every 10 minutes on average), the blocks in the new difficulty period are
going to take more effort to mine on to the blockchain.
Now, seeing as nodes adopt the chain with the most work, they wouldn’t
actually adopt a chain with more blocks in it if it didn’t require as much work to
build. For example, if two versions of the blockchain span multiple difficulty
periods, nodes will adopt the one that has the most cumulative “chainwork”, and
not simply the one with the most blocks in it:
So in summary, the phrase “longest chain” refers to the blockchain that has
taken the most energy to build. For the most part this is usually the chain with
the most blocks in it, but to be more precise it’s the chain with the most amount
of work in it.
Note: In the first version of Bitcoin Satoshi actually used the number of blocks
as the metric for determining the longest chain, believing this to be the chain
that would have taken the most work to build. However this is vulnerable to
manipulation, so it was later changed to using chainwork as the metric for the
longest chain instead.1
[Chainwork] is the total number of hashes that are expected to have been
necessary to produce the current chain.
– Pieter Wuille
To work out chainwork, you just need to work out how many hashes you
would have needed to perform to mine each block in the chain, then add
them up.
The average expected number of hashes for each block depends on what the target was at the time.
Each nodes put the first block they receive at the top of their blockchain.
However, this situation can be resolved by having nodes adopt the longest chain
of blocks. This is because the next block to be mined will build upon one of
these two blocks, creating a new longest chain that all nodes on the network will
be happy to adopt.
Nodes are happy to abandon the shorter chain in favour of the new longer one.
This is known as a chain reorganisation.
So even though nodes can be in disagreement at any given time (due to the
unpredictability of mining and the speed of broadcasting data across a network),
adopting the longest available chain means that nodes will
always eventually agree on the same view of the blockchain.
In effect, the combined effort of miners coordinating to extend the same chain
protects existing blocks and transactions from being replaced by a single miner.
Furthermore, the bitcoins from this block reward can only be spent if the block
becomes 100 blocks deep in the longest chain. Therefore, this block reward
incentivises miners to always try and mine new blocks that will become part of the
longest chain (by always trying to build on to the current longest one).
A block
reward can only be spent if the block is part of the longest chain.
If you tried to spend the bitcoins from a transaction that is not in the longest chain,
nodes would not accept it nor try to mine it in to a block. This is because nodes
only consider the longest chain the valid history history of transactions, and
anything outside of that is not a valid transaction.
The bitcoins in a transaction that is not part of the longest chain are unspendable.
So only the transactions inside the longest chain are considered to be part of the
valid transaction history, and any transactions outside of it effectively never took
place.
Permissioned Blockchain:
A permissioned blockchain is a distributed ledger that is not publicly accessible. It
can only be accessed by users with permissions. The users can only perform
specific actions granted to them by the ledger administrators and are required to
identify themselves through certificates or other digital means.
It may also include maintaining the identity of each blockchain participant on the
network. Such blockchains are called permissioned blockchains.
In this article, we will be exploring permissioned blockchain. Also, to get the best
possible picture, we will also go through some of the best permissioned
blockchains out there, type of DLTs and other vital topics related to the
permissioned blockchains. Let’s start with the definition of Permissioned
blockchain.
What is Hashing?
Hashing is converting an original piece of data into a digest or hash. The process
uses cryptographic hash functions for the irreversible conversion of the message.
SHA-256 Algorithm
SHA-256 stands for Secure Hash Algorithm that generates a 256-bit digest of a
message. This is one of the most renowned hashing algorithms used by several
cryptocurrencies. Another popular application of this algorithm is Digital Signing
Verification.
Let’s dig into the steps to process a message using the SHA-256 Algorithm.
Step 1: Pad the message such that the length of the message
size is a multiple of 512.
Here, pad the message means adding some extra bits to the original message.
Therefore, the total length is exactly 64 bits less than a multiple of 512.
For instance, the length of message M is L. It means L+P+64 =n*512, where L is
the length of the message and P is padded bits.
Note: The bits padded to the message should start with ‘1’. And the rest bits must
be ‘0’ till we are exactly 64 bits less than the multiple of 512.
We padded bits to the original message in Step 1. Now, we can append the length
bits ie, expressed as 64 bits previously, to make it exactly equal to a multiple of
512.
To calculate the 64 bits, L(the original length of the message) mod 2³²
So, to get the entire message block, L+P+[L mod 2³²] = n*512
The entire message is broken into n blocks of 512 bits. Such as M1, M2,
M3……….Mn.
We need a few buffer values to use further. These 0-63 hexadecimal values are
called Keys and are denoted by ‘k’ afterwards.
A hash tree is also known as Merkle Tree. It is a tree in which each leaf node is
labeled with the hash value of a data block and each non-leaf node is labeled with
the hash value of its child nodes labels. This article focuses on discussing the
following topics in detail:
What is a Cryptographic Hash?
What is Hash Pointer?
Blockchain Structure
Block Structure
Merkle Tree Structure
How Do Merkle Trees Work?
Why Merkle Trees are Important For Blockchain?
Proof of Membership
Merkle Proofs
Simple Payment Verification(SPV)
Advantages of Merkle Tree
Let’s discuss each of these topics in detail.
What is a Cryptographic Hash?
A regular pointer stores the memory address of data. With this pointer, the data can
be accessed easily. On the other hand, a hash pointer is a pointer to where data is
stored and with the pointer, the cryptographic hash of the data is also stored. So a
hash pointer points to the data and also allows us to verify the data. A hash pointer
can be used to build all kinds of data structures such as blockchain and Merkle
tree.
Blockchain Structure
Block Structure
1. Block header: The header data contains metadata of the block, i.e
information about the block itself. The contents of the block header include-
Hash of the previous block header.
Hash of the current block.
Timestamp.
Cryptographic nonce.
Merkle root.
2. Merkle tree: A Merkle tree is a binary tree formed by hash pointers, and
named after its creator, Ralph Merkle.
As mentioned earlier, each block is supposed to hold a certain number of
transactions. Now the question arises, how to store these transactions within a
block? One approach can be to form a hash pointer-based linked list of transactions
and store this complete linked list in a block. However, when we put this approach
into perspective, it does not seem practical to store a huge list of hundreds of
transactions. What if there is a need to find whether a particular transaction belongs
to a block? Then we will have to traverse the blocks one by one and within each
block traverse the linked list of transactions.
This is a huge overhead and can reduce the efficiency of the blockchain. Now, this
is where the Merkle tree comes into the picture. Merkle tree is a per-block tree of
all the transactions that are included in the block. It allows us to have a hash/digest
of all transactions and provides proof of membership in a time-efficient manner.
So to recap, the blockchain is a hash-based linked list of blocks, where each block
consists of a header and transactions. The transactions are arranged in a tree-like
fashion, known as the Merkle tree.
Each block comprises of block header + Merkle tree
A Merkle tree is constructed from the leaf nodes level all the way up to the
Merkle root level by grouping nodes in pairs and calculating the hash of each
pair of nodes in that particular level. This hash value is propagated to the next
level. This is a bottom-to-up type of construction where the hash values are
flowing from down to up direction.
Hence, by comparing the Merkle tree structure to a regular binary tree data
structure, one can observe that Merkle trees are actually inverted down.
Binary tree direction vs Merkle tree direction
Example: Consider a block having 4 transactions- T1, T2, T3, T4. These four
transactions have to be stored in the Merkle tree and this is done by the
following steps-
Step 1: The hash of each transaction is computed.
H1 = Hash(T1).
Step 2: The hashes computed are stored in leaf nodes of the Merkle tree.
Step 3: Now non-leaf nodes will be formed. In order to form these nodes, leaf
nodes will be paired together from left to right, and the hash of these pairs will
be calculated. Firstly hash of H1 and H2 will be computed to form H12.
Similarly, H34 is computed. Values H12 and H34 are parent nodes of H1, H2,
and H3, H4 respectively. These are non-leaf nodes.
H12 = Hash(H1 + H2)
H34 = Hash(H3 + H4)
Step 4: Finally H1234 is computed by pairing H12 and H34. H1234 is the only
hash remaining. This means we have reached the root node and therefore H1234
is the Merkle root.
H1234 = Hash(H12 + H34)
Merkle tree works by hashing child nodes again and again till only one hash remains.
Key Points:
In order to check whether the transaction has tampered with the tree, there is
only a need to remember the root of the tree.
One can access the transactions by traversing through the hash pointers and if
any content has been changed in the transaction, this will reflect on the hash
stored in the parent node, which in turn would affect the hash in the upper-level
node and so on until the root is reached.
Hence the root of the Merkle tree has also changed. So Merkle root which is
stored in the block header makes transactions tamper-proof and validates the
integrity of data.
With the help of the Merkle root, the Merkle tree helps in eliminating duplicate
or false transactions in a block.
It generates a digital fingerprint of all transactions in a block and the Merkle root
in the header is further protected by the hash of the block header stored in the
next block.
Why Merkle Trees are Important For Blockchain?
In a centralized network, data can be accessed from one single copy. This means
that nodes do not have to take the responsibility of storing their own copies of
data and data can be retrieved quickly.
However, the situation is not so simple in a distributed system.
Let us consider a scenario where blockchain does not have Merkle trees. In this
case, every node in the network will have to keep a record of every single
transaction that has occurred because there is no central copy of the information.
This means that a huge amount of information will have to be stored on every
node and every node will have its own copy of the ledger. If a node wants to
validate a past transaction, requests will have to be sent to all nodes, requesting
their copy of the ledger. Then the user will have to compare its own copy with
the copies obtained from several nodes.
Any mismatch could compromise the security of the blockchain. Further on,
such verification requests will require huge amounts of data to be sent over the
network, and the computer performing this verification will need a lot of
processing power for comparing different versions of ledgers.
Without the Merkle tree, the data itself has to be transferred all over the
network for verification.
Merkle trees allow comparison and verification of transactions with viable
computational power and bandwidth. Only a small amount of information
needs to be sent, hence compensating for the huge volumes of ledger data that
had to be exchanged previously.
Merkle trees use a one-way hash function extensively and this hashing separates
the proof of data from data itself
Proof of Membership
If there are n nodes in the tree then only log(n) nodes need to be examined.
Hence even if there are a large number of nodes in the Merkle tree, proof of
membership can be computed in a relatively short time.
Merkle Proofs
A Merkle proof is used to decide:
If data belongs to a particular Merkle tree.
To prove data belongs to a set without the need to store the whole set.
To prove a certain data is included in a larger data set without revealing the
larger data set or its subsets.
Merkle proofs are established by hashing a hash’s corresponding hash together
and climbing up the tree until you obtain the root hash which is or can be
publicly known.
Consider the Merkle tree given below:
Let us say we need to prove that transaction ‘a’ is part of this Merkle tree.
Everyone in the network will be aware of the hash function used by all Merkle
trees.
H(a) = Ha as per the diagram.
The hash of Ha and Hb will be Hab, which will be stored in an upper-level node.
Finally hash of Hab and Hcd will give Habcd. This is the Merkle root obtained
by us.
By comparing the obtained Merkle root and the Merkle root already available
within the block header, we can verify the presence of transaction ‘a’ in this
block.
From the above example, it is clear that in order to verify the presence of ‘a’, ‘a’
does not have to be revealed nor do ‘b’, ‘c’, ‘d’ have to be revealed, only their
hashes are sufficient. Therefore Merkle proof provides an efficient and simple
method of verifying inclusivity, and is synonymous with “proof of inclusion”.
A sorted Merkle tree is a tree where all the data blocks are ordered using an
ordering function. This ordering can be alphabetical, lexicographical, numerical,
etc.
Proof of Non-Membership:
It is also possible to test non-membership in logarithmic time and space using a
sorted Merkle tree. That is, it is possible to show that a given transaction does
not belong in the Merkle tree.
This can be done by displaying a path to the transaction that is immediately
before the transaction in question, as well as a path to the item that is
immediately following it.
If these two elements in the tree are sequential, this proves that the item in issue
is not included or else it would have to go between the two things shown if it
was included, but there is no room between them because they are sequential.
Coinbase Transaction:
A coinbase transaction is a unique Bitcoin transaction that is included in the
Merkle tree of every block in the blockchain. It is responsible for creating new
coins and also consists of a coinbase parameter that can be used by miners to
insert arbitrary data into the blockchain.
Simple Payment Verification(SPV)
SPV makes it extremely easy for a client to verify whether a particular
transaction exists in a block and is valid without having to download the
entire blockchain. The users will only require a copy of the block headers of
the longest chain.
This copy of headers is stored in the SPV wallet and this wallet uses the SPV
client to link a transaction to a Merkle branch in a block. SPV client
requests proof of inclusion(Merkle proof), in the form of a Merkle branch. The
fact that the transaction can be linked to a Merkle branch is proof that the
transaction exists.
Now by assessing the blocks which are being mined on top of the transaction’s
block, the client can also conclude that majority of the nodes have built more
blocks on top of this chain by using consensus mechanisms like Proof of Work,
and hence this is the longest, valid blockchain.
Advantages of Merkle Tree
1. Efficient verification: Merkle trees offer efficient verification of integrity and
validity of data and significantly reduce the amount of memory required for
verification. The proof of verification does not require a huge amount of data to
be transmitted across the blockchain network. Enable trustless transfer of
cryptocurrency in the peer-to-peer, distributed system by the quick verification of
transactions.
2. No delay: There is no delay in the transfer of data across the network. Merkle
trees are extensively used in computations that maintain the functioning of
cryptocurrencies.
3. Less disk space: Merkle trees occupy less disk space when compared to other
data structures.
4. Unaltered transfer of data: Merkle root helps in making sure that the blocks
sent across the network are whole and unaltered.
5. Tampering Detection: Merkle tree gives an amazing advantage to miners to
check whether any transactions have been tampered with.
Since the transactions are stored in a Merkle tree which stores the hash of
each node in the upper parent node, any changes in the details of the
transaction such as the amount to be debited or the address to whom the
payment must be made, then the change will propagate to the hashes in upper
levels and finally to the Merkle root.
The miner can compare the Merkle root in the header with the Merkle root
stored in the data part of a block and can easily detect this tampering.
6. Time Complexity: Merkle tree is the best solution if a comparison is done
between the time complexity of searching a transaction in a block as a Merkle
tree and another block that has transactions arranged in a linked list, then-
Merkle Tree search: O(logn), where n is the number of transactions in a
block.
Linked List search: O(n), where n is the number of transactions in a block.