DIY Notes BlockChain
DIY Notes BlockChain
Unit 1
Ans
e)Cryptocurrency:
• one of the most popular applications of Blockchain is in Cryptocurrency. Who hasn’t heard about bitcoin
and it’s insane popularity.
• One of the many advantages of cryptocurrency using blockchain as it has no geographical limitations.
So crypto coins can be used for transactions all over the world.
• However, this option is much better than regional payment apps such as Paytm in India that are only
relevant in a particular country or geographical region and cannot be used to pay money to people in
other countries.
• There are many people in the world who don’t have a legitimate birth certificate especially in the poorer
countries of the world.
• According to UNICEF, one-third of all the children under the age of five don’t have a birth certificate.
And the problem is similar to death certificates as well.
• However, Blockchain can help in solving this problem by creating a secure repository of birth and death
certificates that are verified and can only be accessed by the authorized people.
Ans:
1. Blockchain is a database, or broadly distributed database, used mainly for concurrent transactions.
2. Blockchain has several blocks, also called nodes, and all the blocks are managed with the help of the
block header.
3. Constituents of Block Header are:
• Timestamp • Difficult target
• Version • Nonce.
• Merkle root • Previous hash.
Diagram:
1.Timestamp: Timestamp in the blockchain is used as proof that the particular block is used at what
instance of a time, also this timestamp is used as a parameter to verify the authenticity of any block.
2.Version: It states the version that the particular block is using, there are three types of Blockchain
version.
• Block-chain version 1.0(cryptocurrency) – use a public ledger to store the data, for example, Bitcoin.
• Block-chain version 2.0(smart Contract) – its is called smart contract which is self-executing
programs , for example Ethereum.
• Block-chain version 3.0(DAPPS) – used to create a decentralized structure, for example, tor Browser.
3.Merkle Root: A Merkle root uses mathematical formulas to check if the data is not corrupted, hacked,
or manipulated. For example, Suppose one block has 10 transactions, then to identify that block we need
10 transactions to combine and form one Hash Value, so it uses the concept of the binary tree to create
the hash of the block and that value is called the Merkle Root.
4.Difficult target: It specifies the complexity and the computation power required to mine the network,
if we are having a high difficulty target then it implies that we need more a computationally expensive
machine to mine it. For example, in order to increase the difficulty target algorithms such as SHA-2,
SHA-3. RIPEMD, MD5,BLAKE2 is used.
5.Nonce: It is abbreviated as ‘number only used once’ and it is a number which blockchain miners are
finding and on average, it takes almost 10 times to find out the correct nonce. A nonce is a 32-bit number,
having the maximum value as 2^(32) total possible value, so the job of the bitcoins miners is to find out
the correct integer value which is a random integer between 0 and 2^(32), so it becomes computationally
expensive.
6. Previous Hash : As Blockchain is a collection of several interconnected nodes also called a block, so
previous hash stores the hashed value of the previous node’s address, First block in the blockchain is
called the Genesis Block and has no previous block hash value.
7.Transaction: Blockchain technology is mostly about the transactions that we make digitally for
ourselves. Eventually, these transactions make their way to the various blocks that become part of the
Blockchain later on. So, it is important to understand the transaction life cycle in Blockchain technology.
Transaction in simple words is the process of sending money by the sender and the receiver receiving it.
The Blockchain transaction is also quite similar, but it is made digitally.
Q.3.Different between centralized and Decentralized.
Ans:
Centralized Decentralized
1). A centralized system has a centralized control 1). A decentralized system does not have a centralized
with all administrative authority. control and every node has equal authority.
2).This system are easy design, maintain, impose 2).This system are difficult to design , maintain, govern
Trust And govern. And impose trust.
3).This system are less stable because it have a 3).This system are more stable and fault tolerant because
Central point of failure. It does not have a central point of failure.
4).this system is less secured as compare to 4).this type of system are more secured as compare to
Decentralized. Centralized.
5).Centralization of power can lead to unethical 5). Symmetric system with equal authority to all, so less
operations. scope of unethical operations
6. Scalability is difficult most of the time. 6. Highly scalable.
Ans:
2.Private Block-chain:
• A private property of an individual or an organization, there is one in charge of important things such
as read/write or whom to selectively give access to read or vice versa.
• Private block chain are not decentralized like public blockchain . Only selected nodes can participate
in the process, make it more secure that other.
• These are not as open as a public blockchain.
• These blockchains are operated in a closed network.
• They are open to some authorized users only.
Advantage:
1.speed: rate of transaction is very high. 3.Privacy.
2.scalability. 4.balaced.
Disadvantage:
1.security is less bcoz number of nodes in this system is limited so there chances of manipulation.
2.since the system is centralized trust building is one of the main disadvantages.
3.since there is few nodes if nodes go offline the entire system of block chain can be endangered use
Cases:
3.hybrid block-chain:
• It is the mixed content of private and public , where some part is controlled by some organization
and other by public blockchain.
• It is a combination of both public and private blockchain.
• Permission-based and permissionless systems are used.
• User access information via smart contracts.
• Even a primary entity owns a hybrid blockchain it cannot alter the transaction
Advantage: 1.most advantage of this system is its hybrid nature. It cannot be hacked as 51% of users do
not have access to the network.
2.Cost: transaction cost are cheap as only a few nodes verify the transaction.
3.architecture: Highly customizable and still maintain integrity , security and transparency.
Disadvantage:
1.less efficient.
2.lack transparency.
3. Due to its closed ecosystem this blockchain lacks the incentives for network participation. Uses
Case:
Q.5. What are the differences between permissioned and permissionless blockchain?
Ans:
1.Permissioned Blockchain:
➢ There are closed network only a set of group are allowed validate transaction or data in a given
blockchain network.
➢ These are used in the network where high privacy and security are required.
Characteristics:
➢ A major feature is a transparency based on the objective of the organization.
➢ It does not have a central authority.
➢ Developer by private authority.
Advantage:
1.this blockchain tends to be faster.
2.they can offer customizability.
3.strong privacy.
4.as few nodes are involved performance and scalability are increased.
Disadvantage:
1.Not truly decentralized as it requires permission.
2.Risk of corruption.
3.anytime owner and operator can change the rules as per the need.
2.Permissionless Blockchain:
➢ It is also known as trust-less or public blockchains, are available to everyone to participate in the
blockchains process that use to validate transactions and data.
➢ These are used in the network where high transparency is required.
Characteristics:
➢ This blockchain has no central authority.
➢ The platform is completely open-source.
➢ Full transparency of the transaction.
➢ Heavy use of token.
Advantage:
1.Anyone can participate in the network.
2.trust among users or entities.
3.high level of transparency.
Disadvantage:
1.poor energy efficiency due to large network.
2.lower performance scalability.
3.Less privacy.
Q.6.Peer to Peer:
Ans:;
1. Peer-to-peer refers to the exchange or sharing of information, data, or assets between parties without the
involvement of a central authority.
2. Peer-to-peer (P2P) involves decentralized interactions among individuals and groups.
3. This approach has been used in computers and networking as well as with trading virtual currencies.
4. In a digital peer-to-peer network, each user is an equivalent owner of and contributor to the network.
5. This kind of network can be used for almost any kind of information or file-sharing.
6. With currencies, P2P refers to the exchange of cryptocurrencies, especially Bitcoin, which was created
with the goal of enabling anonymous P2P transactions that don't require processing by a financial
institution.
Types of peer to peer network:
1. P2P networks can be categorized according to their architectural differences. Three main categories are
described below.
(a). Unstructured P2P Networks.
(b). Structured P2P Networks. (c).
Hybrid P2P Network.
Advantages:
Disadvantage:
1.slower speed.
2.more difficult to manage. 3.less
computation power.
Unit 2
Ans:
1. Merkle tree is a fundamental part of blockchain technology. It is mathematical data structure composed
of hashes of different blocks of data, and which serves as a summary of all the transactions in a block.
2. It also allows for efficient and secure verification of content in a large body of data.
3. It also helps to verify the consistency and content of the data. Both Bitcoin and Ethereum use Merkle
Trees structure.
4. Merkle Tree is also known as Hash Tree.
5. The concept of Merkle Tree is named after Ralph Merkle, who patented the idea in 1979.
6. A Merkle tree stores all the transactions in a block by producing a digital fingerprint of the entire set of
transactions.
7. Merkle trees are created by repeatedly calculating hashing pairs of nodes until there is only one hash left.
This hash is called the Merkle Root, or the Root Hash.
8. The Merkle Trees are constructed in a bottom-up approach.
9. Every leaf node is a hash of transactional data, and the non-leaf node is a hash of its previous hashes.
10. Merkle trees are in a binary tree, so it requires an even number of leaf nodes.
11. If there is an odd number of transactions, the last hash will be duplicated once to create an even number
of leaf nodes. Diagram:
Advantage:
• It provides a means to maintain the integrity and validity of data.
• It helps in saving the memory or disk space as the proofs, computationally easy and fast.
Their proofs and management require tiny amounts of information to be transmitted across networks.
Disadvantage:
1.higher CPU usage and memory footprint compared to other type of tree.
2. With a Merkle tree, you have to compute and store a hash at each node, which can be
computationally expensive.
Merkle tree nodes are frequently updated, and thus the file also needs to be updated and constantly
overwritten.
Q.2.What are the different properties for cryptographic hash functions? Explain the three main properties
in detail.
Ans:
1. A cryptographic hash function is a mathematical function used in cryptography.
2.typical hash functions takes inputs of variable length to return outputs of a fixed length.
3.this functions combines the message—passing capabilities of hash function with security properties.
4.this functions are commonly used in data structures in computing system for tasks.
5. Cryptographic hash functions add security features to typical hash functions, making it more difficult to
detect the contents of a message or information about receiver and senders.
1.Colllision-Free:
➢ They are “collision-free.” This means that no two input hashes should map to the same output hash.
➢ A hash function H is said to be collision free if: It’s infeasible to find two values X1 and X2, such
that X1!=X2, yet H(X1)=H(X2) Or in other words, It’s infeasible to find two inputs which can
produce the same outputs.
➢ Since, hash function is compressing function with fixed hash length, it is impossible for a hash
function not to have collisions.
➢ This property makes it very difficult for an attacker to find two input values with the same hash.
➢ We can use this property of hash functions to create a digest for a given data.
2.Hidding:
➢ They can be hidden. It should be difficult guess the input value for a hash function form its output.
3.Puzzle-Friendly:
➢ They should be puzzle-friendly. It should be difficult to select an input that provide a pre-defined
output.
➢ Thus the input should be selected from a distributed that as wide as possible.
➢ Puzzle friendly property is used for bitcoin mining.
Q.3.Digital Signature:
Ans:
Q.1. What is double spending problem? Explain with suitable example. How it is handle in bitcoin?
Ans:
1. Although Blockchain is secured, still it has some loopholes. Hackers or malicious users take
advantage of these loopholes to perform their activities.
2. Double spending means the expenditure of the same digital currency twice or more to avail the
multiple services. It is a technical flaw that allows users to duplicate money.
3. Since digital currencies are nothing but files, a malicious user can create multiple copies of the same
currency file and can use it in multiple places.
4. There are also double spends that allow hackers to reverse transactions so that transaction happens
two times.
5. By doing this, the user loses money two times one for the fake block created by the hacker and for
the original block as well.
Diagram:
Example:
1. Suppose a user has 1 BTC.
2.he/she want to avail services from merchant A and Merchant B.
3.The User created multiple copies of the same BTC and stores it.
4.the user first sends the original BTC to Merchant A and gets the Services.
5.Simultaneously the user sends the copied version of 1 BTC to Merchant B.
6.Since the second transaction was not confirmed by other miner the merchant accepts the bitcoin and
sends the services.
7.But the cryptocurrency that was sent is invalid.
8.This is the case of Double spending.
Double spending handled by Bitcoins:
1. Bitcoin is one of the most popular blockchains. To combat Double spending it uses some security
measures.
2. To tackle these double-spending issues, some security measures are taken. They are:
➢ Validation: Validation of transaction by a maximum number of node in the network.
➢ Timestamp: the confirmed transaction are timestamped therefore they are irreversible.
➢ Block Confirmation: Merchant get block confirmations so that they are assured that there was
no case of double spending.
➢ Saving Copies: A copy of each transaction is kept at each node so in case of network failure the
whole network does not go down.
3.These security features have reduced double spending to a large exent.
4 Double Spending can be prevented using two approaches: Centralized and Decentralized.
1.P2PKH:
➢ This type of ScriptPubKey which locks bitcoin to the hash of private ey.
➢ A P2PKH transaction is one where the inputs were locked using the P2PKH ScriptPubKey.
➢ P2PKH is similar to P2PK transactions, except that the bitcoin is locked to the hash of the
public key rather than the public key itself.
Eg: If Alice wants to send 1 BTC to Bob in a P2PKH transaction, Bob provides Alice with
an address from his wallet. Bob’s address is included in the transaction. When Bob tries to
spend the bitcoin he received, he must sign the transaction with the private key
corresponding to the public key whose hash matches the hash provided in Alice’s
transaction.
2.P2SH:
• Pay-to-Script-Hash (P2SH) is a type of ScriptPubKey which allows for the spending of bitcoin based on
the satisfaction of the script whose hash is specified within the transaction.
• A P2SH transaction is a transaction whose inputs were locked using a P2SH ScriptPubKey.
Unit 4
Ans:
1. A Smart Contract is a computer program that directly and automatically controls the transfer of digital
assets between the parties under certain conditions.
2. Smart contracts are programs that execute exactly as they are set up by their creators. Just like a
traditional contract is enforceable by law, smart contracts are enforceable by code.
3. the bitcoin network was the first to use some sort of smart contract by using them to transfer value from
one person to another.
4. There are some common smart contract platforms like Ethereum, Solana, Polkadot, Hyperledger fabric,
etc.
5. The idea behind smart contracts is pretty simple. They are executed on a basis of simple logic, IF-THEN
for example
➢ IF you send object A, THEN the sum (of money, in cryptocurrency) will be transferred to you.
➢ IF you transfer a certain amount of digital assets, THEN the A object will be transferred to you.
➢ IF I finish the work, THEN the digital assets mentioned in the contract will be transferred to me.
Q.2.
Unit 5
1. Ethereum Virtual Machine (EVM) is designed as the runtime environment for smart contracts in
Ethereum.
2. It is sandboxed and isolated from the other parts of the system.
3. This means that any operation on EVM should not affect your data or programs in any way, no matter
how many times you call a particular function on it.
4. Ethereum contains its own Turing-complete scripting language, called Solidity, and with this comes a
need to execute this code.
Purpose of EVM:
1. The Ethereum Virtual Machine (EVM) is a Turing complete programmable machine, which can
execute scripts to produce arbitrary outcomes.
2. It has been built with the purpose of being a “world computer” and has immense power.
3. It is the computer that stores data on blockchain, like bitcoin, but it also executes code in smart
contracts on the Ethereum network.
4. The machine is made to be able to run any kind of Crypto-contract that can be built on Ethereum’s
blockchain.
Working of EVM:
EVM has two Parts:
1.EVM: The EVM is written in C++ and uses LLVM ass its compiler. It is a full-featured virtual machine
with all the features that you would want in a general purpose Smart Contract Virtual Machine. It also
allows you to write custom EVM bytecode .
2.Uncles: these are small pieces of smart contracts or data stored on the blockchain. This is a useful
feature because it allows for you to store metadata about your program.
Advantage:
1.Easy to write stateful contract.
2.Robust against failure.
3.Can run complex smart contracts.
4.Execute untrusted code without risking data.
Disadvantage:
1.High cost of storing data.
2.High gas cost.
3.high gas price during network congestion.
4.Technical expertise required.
1. Hyperledger Fabric is an open source, permissioned blockchain framework, started in 2015 by The
Linux Foundation.
2. It is a modular, general-purpose framework that offers unique identity management and access control
features, which make it suitable for a variety of industry applications such as track-and-trace of supply
chains, trade finance, loyalty and rewards, as well as clearing and settlement of financial assets.
Need Of Hyperledger:
1. Hyperledger was founded to advance the discovery as well as the adoption of cross-industry
blockchain systems. It is backed by major corporations such as IBM and many others across a wide
range of sectors, including finance, IoT, banking, industry, etc.
2. One thing to keep in mind is that Hyperledger was designed to assist and stimulate the advancement
of blockchain technology, not any particular cryptocurrency.
3. This Hyperledger neither has any nor will have its coin. It is a vital thing to keep in mind about
Hyperledger.
Disadvantages:
1.Requires high computational power.
2.Limited scalability.
3.complex setup process.
4.No native cryptocurrency support.
Q.3. What is Ethereum? Explain the architecture of Ethereum also explain the different components in
Ethereum network.
Ans:
1. Ethereum is an open-source public service that uses blockchain technology to facilitate smart contracts
and cryptocurrency trading securely without a third party.
2. There are two accounts available through Ethereum:
• externally owned accounts (controlled by private keys influenced by human users) and
• contract accounts.
3. Ethereum allows developers to deploy all kinds of decentralized apps.
4. Even though Bitcoin remains the most popular cryptocurrency, it’s Ethereum’s aggressive growth that
has many speculating it will soon overtake Bitcoin in usage.
Advantage of Ethereum:
➢ It allows individual and companies to do much more than just transfer money between entities.
➢ The hottest platforms in the world of cryptocurrency and blockchain and companies such Jp
morgan , intel and Microsoft invest in it.
Architecture of Ethereum:
➢ After bitcoin the second most used cryptocurrency is Ethereum. Unlike bitcoin, Ethereum is proposed
to be the more simple means of exchange or store of value.
➢ Ethereum refers as a decentralized computer network based on the blockchain technologies.
➢ Ethereum is build on top of blockchain network.
➢ Everyone on the Ethereum network has an exact copy of this ledger which allows them to view all
previous transactions.
➢ The Ethereum network allows users to build and run apps, smart contracts and other transaction these
features are not available in bitcoin.
➢ There is no boundary on how much Ether tokens can be produced while Bitcoin can only deliver 21
million coins.
2.Ether:
➢ Ether is a type of cryptocurrency used in the Ethereum network just like a bitcoin is used in a
blockchain network.
➢ It is a peer-to-peer currency, similar to Bitcoin. It tracks and promotes each transaction in the
network.
➢ It is the second-largest cryptocurrency in the world.
3.Gas:
➢ To complete every transaction on the Ethereum network, a consumer must first make a payment—
send out ethers—and the intermediate monetary value is known as gas.
➢ Gas is a unit of measurement on the Ethereum network for the computing power used to execute a
smart contract or a transaction.
➢ The price of gas is very low compared to Ether.
➢ The execution and resource utilization costs are predetermined in Ethereum in terms of Gas units,
called gwei.
4.Ethereum accounts: there are two types of Ethereum accounts, they are as follows:
a)Externally owned account- these are used to store transaction.
b)Contract accounts- these accounts store the details of smart contracts.
5.Nonce:
➢ For externally owned accounts, nonce means the number of transactions via this account.
➢ For a contract account, nonce means the number of contracts generated via this account.
6.Storage Root:
➢ It is the main root node of a Merkle tree.
➢ Hash of all details of the account is stored here.
➢ The root of the Merkle tree is the verification of all transactions.
Bitcoin Ethereum
1.Bitcoin trade in cryptocurrency. 1.Ethereum offers several method of exchange
including cryptocurrency, smart contracts and
EVM.
2.bitcoin use a “Proof Of Work” system. 2. Ethereum use a “Proof Of Stake” system.
3.Bitcoin allows only public 3.Ethereum allows both permissioned and
transaction(permissionless). permissionless transactions.
4.For Bitcoin the computer running he platform and 4.Ethereum does not offer block rewards and
verifying the transaction receive rewards. instead allows miners to take transaction fees.
5.the purpose of bitcoin was to replace national 5.the purpose of Ethereum was to utilize blockchain
currency during financial crisis. technology.
6.Bitcoin runs on the SHA-256 hash algorithm. 6.Ethereum runs on the Keccak-256 hash
algorithm.
7.the bitcoin blockchain has a block limit of 1mb. 7.the Ethereum blockchain does not have a block
limit.
8.the block time of bitcoin is 10 minutes. 8. The block time of Ethereum is 14 to 15 seconds.
9.Energy consumption is very high. 9. Energy consumption is very low.
10.structure oof bitcoin is simple and robust. 10. Structure of Ethereum is complex and feature
rich.
11. assets of Bitcoin is BTC. 11. Assets of Ethereum is Ether.