Blockchain End Sem - Important Question and Solution
Blockchain End Sem - Important Question and Solution
Blockchain End Sem - Important Question and Solution
Motivation - smallify.live/real-motivation
Niru Gang
Chapter 1
Define Blockchain
● Blockchain is a list of records called blocks that store data publicly and in chronological
order.
● This information is encrypted using cryptography to ensure that the privacy of the user is
not compromised and data cannot be altered.
● Blockchain is a peer-to-peer (P2P) distributed network that connects nodes.
● Blockchain is decentralized. It means there’s no central point of authority in the network.
● Each node carries the same copy of network records.
● Every network update (such as adding a new block) requires consensus or global
network agreement.
● Use in blockchain:
○ It is used to validate the data's integrity effectively.
○ Compared to other data structures, the Merkle tree takes up very little disk space,
hence the size of records on each node is minimized.
○ Merkle trees can be broken down into small pieces of data for verification, hence
making verification less computationally intensive.As the data format is efficient,
verifying the data's integrity takes only a few moments.
Niru Gang
Explain in detail the components of Blockchain.
Node
● Full Node: It maintains a full copy of all the transactions. It has the capacity to validate,
accept and reject the transactions.
● Partial Node: It is also called a Lightweight Node because it doesn’t maintain the whole
copy of the blockchain ledger. It maintains only the hash value of the transaction. These
nodes have low storage and low computational power.
Ledger
It is a digital database of information.
There are three types of ledger. They are:
● Public Ledger – It is open and transparent to all. Anyone in the blockchain network can
read or write something.
● Distributed Ledger – In this ledger, all nodes have a local copy of the database. Here, a
group of nodes collectively execute the job i.e verify transactions, add blocks in the
blockchain.
● Decentralized Ledger – In this ledger, no one node or group of nodes has a central
control. Every node participates in the execution of the job.
Wallet
It is a digital wallet that allows users to store their cryptocurrency.
Every node in the blockchain network has a Wallet.
Privacy of a wallet in a blockchain network is maintained using public and private key pairs.
Cryptocurrency wallets are mainly of two types –
● Hot Wallet – These wallets are used for online day-to-day transactions connected to the
internet. Hackers can attack this wallet as it is connected to the internet. Hot wallets are
further classified into two types –
○ Online/ Web wallets – These wallets run on the cloud platform. Examples –
MyEtherWallet, MetaMask Wallet.
○ Software wallets – It consists of desktop wallets and mobile wallets. Desktop
wallets can be downloaded on a desktop and the user has full control of the
wallet. An example of a desktop wallet is Electrum.
○ Mobile wallets: designed to run on mobile devices: eg. mycelium.
● Cold Wallet – These wallets are not connected to the internet. It is very safe and hackers
cannot attack it. These wallets are purchased by the user. Example – Paper wallet,
hardware wallet.
○ Paper wallet – They are offline wallets in which a piece of paper is used that
contains the crypto address. The private key is printed in QR code format. QR
code is scanned for cryptocurrency transactions.
○ Hardware wallet – It is a physical electronic device that uses a random number
generator that is associated with the wallet.
The focus of wallets is on these three things –
● Privacy
● Transactions should be secure
Niru Gang
● Easy to use
Nonce
● A nonce is an abbreviation for “number only used once,” which is a number added to a
hashed or encrypted block in a blockchain.
● It is the 32-bit number generated randomly only one time that assists to create a new
block or validate a transaction.
● It is used to make the transaction more secure.
● It is hard to select the number which can be used as the nonce.
● It requires a vital amount of trial-and-error.
● First, a miner guesses a nonce. Then, it appends the guessed nonce to the hash of the
current header.
● After that, it rehashes the value and compares this to the target hash.
● Now it checks whether the resulting hash value meets the requirements or not. If all the
conditions are met, it means that the miner has created an answer and is granted the
block.
Hash
The data is mapped to a fixed size using hashing. It plays a very important role in cryptography.
In a blockchain network hash value of one transaction is the input of another transaction.
Properties of the hash function are as follows –
● Collision resistant
● Hiding
● Puzzle friendliness
Advantages:
● Trustable: Public Blockchain nodes do not need to know or trust each other because the
proof-of-work procedure ensures no fraudulent transactions.
● Secure: A public network can have as many participants or nodes as it wants, making it
a secure network. The higher the network's size, the more records are distributed, and
the more difficult it is for hackers to hack the entire network.
● Open and Transparent: The data on a public blockchain is transparent to all member
nodes. Every authorized node has a copy of the blockchain records or digital ledger.
Niru Gang
Disadvantages:
● Lower TPS: The number of transactions per second in a public blockchain is extremely
low. This is because it is a large network with many nodes which take time to verify a
transaction and do proof-of-work.
● Scalability Issues: Its transactions are processed and completed slowly. This harms
scalability. Because the more we try to expand the network's size, the slower it will
become.
● High Energy Consumption: The proof-of-work device is expensive and requires lots of
energy.
Use Cases:
● Voting: Governments can use a public blockchain to vote, ensuring openness and trust.
● Public Blockchain is secured with proof of work or proof of stake; they can be used to
displace traditional financial systems.
Private Blockchain
● This blockchain operates in a private context, such as a restricted network, or is
controlled by a single identity.
● While it has a similar peer-to-peer connection and decentralization to a public blockchain
network, this Blockchain is far smaller.
● Only selected nodes can participate in the process, making it more secure than the
others.
● These blockchains are operated in a closed network.
Advantages:
● Speed: Private Blockchain transactions are faster. This is because a private network has
a smaller number of nodes, which shortens the time it takes to verify a transaction.
● Scalability: You can tailor the size of your private Blockchain to meet your specific
requirements. This makes private blockchains particularly scalable since they allow
companies to easily raise or decrease their network size.
● Privacy: It has increased the level of privacy for confidentiality reasons as the
businesses required.
Disadvantages:
● Trust Building: In a private network, there are fewer participants than in a public network.
● Lower Security: A private blockchain network has fewer nodes or members, so it is more
vulnerable to a security compromise.
● Centralization: Private blockchains are limited in that they require a central Identity and
Access Management (IAM) system to function.
Use Cases:
Niru Gang
● Supply Chain Management: A private blockchain can be used to manage a company's
supply chain.
● Asset Ownership: A private blockchain can be used to track and verify assets.
● Internal Voting: Internal voting is also possible with a private blockchain.
Hybrid Blockchain
● Organizations who expect the best of both worlds use a hybrid blockchain, which
combines the features of both private and public blockchains.
● It enables enterprises to construct a private, permission-based system alongside a
public, permissionless system, allowing them to choose who has access to certain
Blockchain data and what data is made public.
● In a hybrid blockchain, transactions and records are typically not made public, but they
can be validated if necessary by granting access via a smart contract.
Consortium Blockchain
● In the same way that a hybrid blockchain has both private and public blockchain
features, a Consortium blockchain, also known as a federated blockchain, does.
● However, it differs because it involves various organizational members working together
on a decentralized network.
● Predetermined nodes control the consensus methods in a consortium blockchain.
Niru Gang
● It has a validator node responsible for initiating, receiving, and validating transactions.
Transactions can be initiated or received by member nodes.
Niru Gang
● However, these miners use very powerful computers that are specifically designed to
mine crypto transactions.
● They do this by actually solving math problems and resolving cryptographic issues
because every transaction needs to be cryptographically encoded and secured.
● These mathematical problems ensure that nobody is tampering with that data.
● The cryptocurrency is created by rewarding these miners for their work in solving the
mathematical and cryptographical problems.
Niru Gang
● Deterministic: A hash function must be deterministic, which means that for any given
input a hash function must always give the same result.
● Avalanche Effect: This means for a small change in the input, the output will change
significantly.
● Puzzle Friendliness: This means even if one gets to know the first 200 bytes, one cannot
guess or determine the next 56 bytes.
● Fixed-length Mapping: For any input of fixed length, the hash function will always
generate the output of the same length.
Niru Gang
○ It is a one-way function.
Anyone can publish a transaction and The network is accessible only to those who
participate in the network by adhering to a set have permission and transactions can be
of published rules. edited by administrators.
Public open: Public and open blockchains are Public closed: Public and closed blockchains
available for everybody and written data is are open to everyone to write, but only
accessible and readable by everybody as restricted people can read the data.
well.
Public and open blockchains support use A use case for this kind of blockchain for
Niru Gang
cases such as public/transparent ledgers example is voting or polling.
where everybody can read and verify data. Everybody can write his/her vote or opinion to
the blockchain, but only the creators of the
ballot box are allowed to read the voting
results.
Public open blockchain example is bitcoin Public and closed blockchains are often used
for medical, legal or financial use cases
where customers or prospects can store
confidential and / or personal information for
restricted access by the corresponding
entities.
Private and Open: This type of private Private and Closed: Private and closed
blockchain is commonly used in supply blockchains enable use cases where only
chains, where only suppliers are able to write trusted and known members are able to write
the supply status to the chain, but every and read the data in the blockchain (e.g. an
private blockchain’s participant can track the interbank blockchain where banks exchange
status and see the information. assets).
Niru Gang
Basis of comparison Public blockchain Private blockchain
Niru Gang
Differentiate between permissionless and permissioned blockchain
Image link
Define following
● Miners: Miners validate new blockchain transactions and record them on the blockchain.
Miners compete to solve a difficult mathematical problem based on a cryptographic hash
algorithm.
● Mining: Mining is the process that Bitcoin and several other cryptocurrencies use to
generate new coins and verify new transactions. It involves vast, decentralized networks
of computers around the world that verify and secure blockchains.
● Nonce: It is a four-bit (32 byte) number added to a hashed—or encrypted—block in a
blockchain that, when rehashed, meets the difficulty level restrictions. The nonce is the
number that blockchain miners are solving for.
● Hash tree: A hash tree encodes the blockchain data in an efficient and secure manner.
It enables the quick verification of blockchain data, as well as quick movement of large
amounts of data from one computer node to the other on the peer-to-peer blockchain
network.
Niru Gang
Chapter 2
Niru Gang
○ Consensus mechanisms form the backbone of all cryptocurrency blockchains,
and are what make them secure.
○ In order to guarantee that all participants (‘nodes’) in a blockchain network agree
on a single version of history, blockchain networks like Bitcoin and Ethereum
implement what’s known as consensus mechanisms (also known as consensus
protocols or consensus algorithms). These mechanisms aim to make the system
fault-tolerant.
Created two blockchains at the end Soft fork combines the split into one at the
end
Hard fork can valid previously entered invalid Soft fork can only invalidate previously
transactions and vice-versa. entered valid transactions.
Niru Gang
More secure and private Less secure and private
Requires all miners to validate new rules Soft fork can work well with the majority of
miners
Changes the entire rules of a blockchain Used to add new functions and properties to
a blockchain
Does not require a soft fork for reversible Requires hard fork for reversible process
process
What is a Wallet? Explain types of Wallet. Differentiate between hot and cold
wallets.
The letter ‘E’ in e-wallet stands for electronic; thus, e-wallet refers to an electronic wallet. An
e-wallet, also known as a digital wallet, enables users to conduct transactions with ease. These
wallets can be used for simple transactions both online and in stores.
Types of wallet are as follows:
● Closed wallet
○ A closed wallet enables users to make payments via an app or website.
○ They are typically created by businesses that sell products or services to their
customers.
○ Users of a closed wallet can only use the stored funds to complete a transaction
with the wallet’s issuer.
○ If a transaction is canceled or a refund is issued, the entire amount is stored in
the wallet.
● Semi-closed wallet
○ A semi-closed wallet allows users to easily make transactions at merchants and
locations that are listed.
○ Semi-closed wallets have a limited coverage area.
○ To accept payment from the wallet, merchants must accept the contract or
agreement with the issuer.
● Open wallet
○ Banks provide open wallets.
○ Users with open wallets can use them for any type of transaction.
○ Open wallets allow you to easily transfer funds.
○ Payments can be made both online and in-store at any time.
○ The open e-wallets service provider allows users to conduct transactions from
anywhere in the world; however, both the sender and the receiver must have
accounts on the same application.
● Crypto wallet
○ Users’ public and private keys are stored in cryptocurrency wallets.
○ The keys could be cryptocurrency ownership certificates.
Niru Gang
○ Hardware wallets, also known as cold wallets, add an extra layer of security and
safety.
○ A USB stick can be used to operate wallets offline.
○ These wallets can be used to make cryptocurrency payments.
● IoT wallet
● IoT is an abbreviation for the Internet of Things.
● These are installed in watches, jackets, wristbands or other wallet enabled devices such
as smart car computers, smart refrigerators, and others.
● IoT wallets work with e-money and virtual currencies.
Bitcoin
● Bitcoin is the original blockchain cryptocurrency.
Niru Gang
● Most popular
● Widely used
● Derived from bitcoin[fork]: Namecoin, Peercoin, litecoin
Tokens
● Crypto tokens are a type of cryptocurrency that represents an asset or specific use and
reside on their own blockchain.
● Tokens can be used for investment purposes, to store value, or to make purchases.
● Cryptocurrencies are digital currencies used to facilitate transactions (making and
receiving payments) along the blockchain.
Explain UTXO
In bitcoin, the transaction lives until it has been executed till the time another transaction is done
out of that UTXO. UTXO stands for Unspent Transaction Output.
● It is the amount of digital currency someone has left remaining after executing a
transaction.
● When a transaction is completed, the unspent output is deposited back into the
database as input which can be used later for another transaction.
● UTXOs are created through the consumption of existing UTXOs. Every Bitcoin
transaction is composed of inputs and outputs. Inputs consume an existing UTXO,
while outputs create a new UTXO.
● The UTXO model does not incorporate wallets at the protocol level. It is based on
individual transactions that are grouped in blocks. The UTXO model is a design
common to many cryptocurrencies, most notably Bitcoin.
● Cryptocurrencies that use the UTXO model do not use accounts or balances.
Instead, UTXOs are transferred between users much like physical cash.
● Each transaction in the UTXO model can transition the system to a new state, but
transitioning to a new state with each transaction is infeasible.
● The network participants must stay in sync with the current state.
Niru Gang
● Language Agnostic Smart Contracts: The UTXO based smart contracts are
independent of language and allow UTXOs to develop unique consensus
mechanisms.
● Support for Decentralized Exchanges and Atomic Swap: The UTXO model could
support atomic swaps, hence enabling peer-to-peer crypto trades without the
involvement of a third party. The atomic swap feature of UTXOs offers a better facility
for direct cryptocurrency trades between user wallets.
● Scalability Benefits: Facility or parallel transaction processing reduces computation
load on the blockchain networks.
● Privacy and Security: With new addresses used for every UTXO transaction, it is
impossible to track the transactions.
● Prevents Double Spending: A UTXO can only be used once, this is fundamental
within the operation of the blockchain technology that guarantees that the currencies
are not used more than once.
● More Flexibility: It provides more flexibility than fiat currency.
● Simple parallelization: It allows for the simpler parallelization of transactions in the
smart contracts.
Refer for example
Niru Gang
Chapter 3
Solidity programming
Solidity in 2 mins (for beginners)
or Solidity in 100 Seconds
Solidity is an object-oriented programming language for implementing smart contracts on
various blockchain platforms, most notably, Ethereum.
File Extension is .sol
Example:
pragma solidity >=0.4.0 <0.6.0;
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}
Pragma:
The first line of any solidity program is a pragma directive which tells the source code’s intended
Solidity version.
Solidity Contract:
A Solidity contract is a collection of functions and states that resides at a specific address on the
Ethereum blockchain.
Function:
Function in Solidity is defined by using the ‘function’ keyword, followed by a unique function
name, a list of parameters, scope, data type of returned value and a statement block
surrounded by curly braces.
// function definition
function function-name(parameter-list) scope returns() {
//statements
}
// function call
function-name()
Niru Gang
Value Types
● Boolean: This data type accepts only two values True or False.
● Integer: This data type is used to store integer values, int and uint are used to declare
signed and unsigned integers respectively.
● Fixed Point Numbers: They can be declared as fixed and unfixed for signed and
unsigned fixed-point numbers of varying sizes respectively.
● Address: Address holds a 20-byte value which represents the size of an Ethereum
address. It can be used to get balance or to transfer a balance by balance and transfer
method respectively.
● Bytes and Strings: Bytes are used to store a fixed-sized character set while the string is
used to store the character set equal to or more than a byte. Byte has an advantage that
it uses less gas, so better to use when we know the length of data.
● Enums: It is used to create user-defined data types, used to assign a name to an integral
constant which makes the contract more readable, maintainable, and less prone to
errors. Options of enums can be represented by unsigned integer values starting from 0.
● Arrays: An array is a collection of values of the same data type where each value has a
particular location known as an index. By using the index location, the desired value can
be accessed or modified. The array size can be fixed or dynamic.
● Struct: Solidity allows users to create and define their own type in the form of structures.
The structure is a group of different types which can contain both value type and
reference type.
● Mapping: Mapping is a reference type that stores the data in a key-value pair where a
key can be any value type. It is like a hashtable or dictionary as in any other
programming language, where values can be retrieved using corresponding key.
Inheritance:
Solidity supports inheritance between smart contracts, where multiple contracts can be inherited
into a single contract. The contract from which other contracts inherit features is known as a
base contract, while the contract which inherits the features is called a derived contract. Simply,
they are referred to as parent-child contracts.
Error Handling
Errors can occur at compile time or runtime. Solidity is compiled to byte code and there a syntax
error check happens at compile-time, while runtime errors are difficult to catch and occurs
mainly while executing the contracts. Solidity has many functions for error handling. Some of the
runtime errors are out-of-gas error, data type overflow error, divide by zero error,
array-out-of-index error, etc.
Niru Gang
After version 4.10 new error handling construct assert, require, and revert statements were
introduced.
● Smart Legal Contracts: These contracts are legally enforceable and require the parties
to fulfill their contractual obligations. Failure to do so may result in strict legal actions
against them.
● Decentralized Autonomous Organizations: These are blockchain communities that
are bound to specific rules coded into blockchain contracts combined with governance
mechanisms. Hence, any action taken by the community members gets replaced by a
self-enforcing code.
● Application Logic Contracts: These contracts contain an application-based code that
remains in sync with other blockchain contracts. It enables communication across
different devices, such as the merger of the Internet of Things with blockchain
technology.
Niru Gang
Benefits of smart contract
● Autonomy and savings: Smart contracts do not need brokers or other intermediaries to
confirm the agreement; thus, they eliminate the risk of manipulation by third parties.
Moreover, the absence of intermediaries in smart contracts results in cost savings.
● Backup: All the documents stored on the blockchain are duplicated multiple times; thus,
originals can be restored in the event of any data loss.
● Safety: Smart contracts are encrypted, and cryptography keeps all the documents safe
from infiltration.
● Speed: Smart contracts automate tasks by using computer protocols, saving hours for
various business processes.
● Accuracy: Using smart contracts eliminates errors that occur due to the manual filling of
numerous forms.
Niru Gang
● For example, let’s assume Alice and Bob want to bet on the outcome of a sports match.
● Alice bets $20 on team A and Bob bets $20 on team B, with the $40 total held in escrow
by a smart contract.
● When the game ends, how does the smart contract know whether to release the funds to
Alice or Bob?
● The answer is it requires an oracle mechanism to fetch accurate match outcomes
off-chain and deliver it to the blockchain in a secure and reliable manner.
● Solving the oracle problem is of the utmost importance because the vast majority of
smart contract use cases like DeFi require knowledge of real-world data and events
happening off-chain.
Disadvantages:
● Difficult to change: Changing smart contract processes is almost impossible, any error
in the code can be time-consuming and expensive to correct.
● Possibility of loopholes: According to the concept of good faith, parties will deal fairly
and not get benefits unethically from a contract. However, using smart contracts makes it
difficult to ensure that the terms are met according to what was agreed upon.
● Third party: Although smart contracts seek to eliminate third-party involvement, it is not
possible to eliminate them. Third parties assume different roles from the ones they take
in traditional contracts. For example, lawyers will not be needed to prepare individual
contracts; however, they will be needed by developers to understand the terms to create
codes for smart contracts.
● Vague terms: Since contracts include terms that are not always understood, smart
contracts are not always able to handle terms and conditions that are vague.
Niru Gang
● Contracts: Solidity contracts are written in a format similar to class declarations in
object-oriented languages. A contract can contain state variables, functions, and
modifiers.
○ State variables can be of any type, including user-defined types.
○ Functions can be called externally or internally (within the contract).
○ Modifiers can be used to change the behavior of functions.
○ Contracts can also interact with each other, allowing for the creation of complex
decentralized applications.
● Data types: Solidity provides several built-in types, including address, uint (unsigned
integer), int (signed integer), bool (boolean), and byte (a fixed-size byte array). Solidity
also allows for creating user-defined types, such as enums and structs.
● Contract deployment: Solidity contracts can be deployed on the Ethereum blockchain.
Once deployed, a contract can be interacted with by any party that has the contract’s
address.
● Solidity compiler: The language is not yet fully standardized, and no official reference
compiler exists. Solidity Compiler is maintained by the Ethereum Foundation.
● Easy to learn: Solidity is a high-level language, meaning it is easier to learn and use
than a lower-level language like EVM bytecode. Several resources are available to help
learn Solidity, including the official Solidity documentation.
● Smart contracts: Smart contracts are programs that run on the Ethereum blockchain
and can be used to facilitate transactions and agreements between parties. Smart
contracts can be used to create decentralized applications (d-apps).
● DEXes: Solidity is also used to create decentralized exchanges (DEXes). DEXes are
exchanges that allow for the trading of cryptocurrency without the need for a central
authority.
● Programming components: The Solidity programming language has several high-level
language components, which can be used to build contracts and programs. These
include
○ Data types.
○ Functions.
○ Control structures.
○ Inheritance.
○ Packages.
○ Error handling.
State Variable
Variables whose values are permanently stored in a contract storage.
Niru Gang
Local Variable
Variables whose values are available only within a function where it is defined. Function
parameters are always local to that function.
Global Variables
These are special variables which exist in global workspace and provide information
about the blockchain and transaction properties.
Niru Gang
Explain the fallback function used in solidity
● The solidity fallback function is executed if none of the other functions match the function
identifier or no data was provided with the function call.
● Only one unnamed function can be assigned to a contract and it is executed whenever
the contract receives plain Ether without any data.
● To receive Ether and add it to the total balance of the contract, the fallback function must
be marked payable.
● If no such function exists, the contract cannot receive Ether through regular transactions
and will throw an exception.
Niru Gang
● Instead, reference types store (or “reference”) the address of the data’s location and do
not directly share the data.
● Reference data types must be handled cautiously since they deal with storage locations.
● Data location affects the amount of gas used in a transaction and therefore can
negatively impact smart contract development performance.
● When using reference types, reference variables point a user to the location of value
storage, and these can take up more than 32B of memory in size.
● Two separate variables can refer to the exact location, and any change in one variable
can affect the other.
● Several variables that point to the same address can be used to effect a change in a
reference data type.
● There are several reference data types in Solidity: fixed-sized arrays, dynamic-sized
arrays, array members, byte arrays, string arrays, structs, and mapping.
Niru Gang
Error handling in solidity
Solidity provides various functions for error handling. Generally when an error occurs, the state
is reverted back to its original state.
Other checks are to prevent unauthorized code access. Following are some of the important
methods used in error handling −
● assert(bool condition) − In case condition is not met, this method call causes an invalid
opcode, and any changes done to state got reverted. This method is to be used for
internal errors.
● require(bool condition) − In case the condition is not met, this method call reverts to
the original state. - This method is to be used for errors in inputs or external components.
● require(bool condition, string memory message) − In case condition is not met, this
method call reverts to the original state. - This method is to be used for errors in inputs or
external components. It provides an option to provide a custom message.
● revert() − This method aborts the execution and reverts any changes done to the state.
● revert(string memory reason) − This method aborts the execution and reverts any
changes done to the state. It provides an option to provide a custom message.
Inheritance in Solidity
● It is a way of extending the functionality of a program, used to separate the code,
reduces the dependency, and increases the re-usability of the existing code.
● Solidity supports inheritance between smart contracts, where multiple contracts can be
inherited into a single contract.
● The contract from which other contracts inherit features is known as a base contract,
while the contract which inherits the features is called a derived contract.
Niru Gang
Chapter 4
Niru Gang
● Ethereum Virtual Machine Node: These are the nodes in the Ethereum network in
which Smart Contracts are implemented. By default, this node utilizes a 30303 port
number for the purpose of communication among themselves.
Ether:
● Ether is a type of cryptocurrency used in the Ethereum network just like 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.
● Ether is paid as a commission for any execution that affects the state in Ethereum.
● It is used in the Ethereum algorithm as an incentive for miners who connect blocks to the
blockchain using a proof-of-work method.
● It is the only currency that can be used to pay transaction costs, which go to miners as
well.
● Aside from paying for transactions, ether is often used to purchase gas, which is used to
pay for the computation of any transaction on the Ethereum network.
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.
Ethereum Accounts:
There are two types of Ethereum accounts. They are as follows.
● Externally owned account: These accounts are used to store transactions.
● Contract account: As the name itself suggests, these accounts store the details of
Smart Contracts.
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.
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.
Ethash:
The intended PoW algorithm for Ethereum 1.0 is Ethash. It’s the most recent version of
Dagger-Hashimoto, however, it’s no longer proper to call it that because many of the algorithms’
initial characteristics have been dramatically altered in the previous month of study and
development.
Niru Gang
Architecture of Ethereum
Workflow of Ethereum
● Ethereum implements an execution environment called Ethereum Virtual Machine
(EVM).
● When a transaction triggers a smart contract all the nodes of the network will execute
every instruction.
● All the nodes will run The EVM as part of the block verification, where the nodes will go
through the transactions listed in the block and runs the code as triggered by the
transaction in the EVM.
● All the nodes on the network must perform the same calculations for keeping their
ledgers in sync.
Niru Gang
● Every transaction must include
○ Gas limit.
○ Transaction Fee that the sender is willing to pay for the transaction.
● If the total amount of gas needed to process the transaction is less than or equal to the
gas limit then the transaction will be processed and if the total amount of the gas needed
is more than the gas limit then the transaction will not be processed the fees are still lost.
● Thus it is safe to send transactions with the gas limit above the estimate to increase the
chances of getting it processed.
Niru Gang
○ First block in the blockchain is called the Genesis Block and has no previous
block hash value.
Features of metamask.
● MetaMask allows users to store and manage account keys, broadcast transactions, send
and receive Ethereum-based cryptocurrencies and tokens, and securely connect to
decentralized applications through a compatible web browser or the mobile app's built-in
browser.
● Websites or other decentralized applications are able to connect, authenticate, and/or
integrate other smart contract functionality with a user's MetaMask wallet (and any other
similar blockchain wallet browser extensions) via JavaScript code that allows the website
to send action prompts, signature requests, or transaction requests to the user through
MetaMask as an intermediary.
Niru Gang
● The application includes an integrated service for exchanging Ethereum tokens by
aggregating several decentralized exchanges (DEXs) to find the best exchange rate.
This feature, branded as MetaMask Swaps, charges a service fee of 0.875% of the
transaction amount
Niru Gang
○ Go inside the ‘MAIN ACCOUNT’. The string below your account name is your
account address. It starts with 0x.
● Done!
Niru Gang
Chapter 5
Disadvantages:
● Trust Building: In a private network, there are fewer participants than in a public network.
● Lower Security: A private blockchain network has fewer nodes or members, so it is more
vulnerable to a security compromise.
● Centralization: Private blockchains are limited in that they require a central Identity and
Access Management (IAM) system to function.
Niru Gang
■ If an attacker sends a computationally intensive transaction to a smart
contract that actually prevents other transactions from being included in
the current block.
■ Another attack is to create a parasitic contract that drains all the gas
automatically, rendering the service unusable for other participants.
Niru Gang
● This can be achieved using the timestamp concept.
● So, whenever Alice and Bob are making the transactions, the transactions are
associated with the timestamp.
● This way, information will be executed on each server in that particular ordering
algorithm.
● Consequently, all will execute in the same order in which it was supported to be
executed.
● This way, all servers are reaching the same state.
Explain PAXOS.
● Paxos is an algorithm that is used to achieve consensus among a distributed set of
computers that communicate via an asynchronous network.
● One or more clients proposes a value to Paxos and we have consensus when a majority
of systems running Paxos agrees on one of the proposed values.
● Paxos is widely used and is legendary in computer science since it is the first consensus
algorithm that has been rigorously proved to be correct.
● Paxos simply selects a single value from one or more values that are proposed to it and
lets everyone know what that value is.
Niru Gang
Making a Proposal: Acceptor’s Message
● Acceptor prepares the response, including accept or decline status, biggest proposal
number, and accepted values.
Explain RAFT
● The idea behind the Raft consensus algorithm is that the nodes collectively select a
leader, and the remaining nodes become the followers.
● The leader is responsible for state transition log replication across the followers under
the closed distributed environment, assuming that all the nodes are trustworthy and have
no malicious intent.
● The system starts up and has a set of follower nodes.
● The follower nodes look for a leader.
● If a timeout happens, there is no leader, and there is a need to elect a leader in the
system.
● A few candidates stand for a leader in the election process, and the remaining nodes
vote for the candidate.
● The candidates who receive the majority votes become the leader.
● The leader proposes a proposal, and the followers can either vote for or against that
proposal.
Niru Gang
● This voting request contains 2 parameters:
○ Term: The last calculated number known to candidate + 1.
○ Index: Committed transactions available to the candidate.
Niru Gang
○ To break this tie, what other acceptors do, they block the proposer with a lower
height.
Explain BFT
● We imagine that several divisions of the Byzantine army are camped outside an enemy
city, each division commanded by its own general.
● The generals can communicate with one another only by messenger. After observing the
enemy, they must decide upon a common plan of action.
Niru Gang
● However, some of the generals may be traitors, trying to prevent the loyal generals from
reaching agreement.
● The generals must have an algorithm to guarantee that
○ All loyal generals decide upon the same plan of action.
○ A small number of traitors cannot cause the loyal generals to adopt a bad plan.
Explain pBFT
The basic assumption about the system and working environment: The system works in an
asynchronous distributed system, and it can tolerate delay and out-of-order messages.
It can also handle Byzantine failure where arbitrary nodes behave maliciously and privacy,
tamper-proof message, and authentication.
● The PBFT setting has a maximum of 3*f + 1 number of different replicas, and out of
these replicas, it has f number of faulty replicas and 2*f +1 numbers non-faulty replicas.
● The state machine is replicated across different nodes.
● The replicas move through successive configurations, known as views.
● One replica is a primary view, and others are backups.
● Views are changed when a primary is detected as faulty.
● A unique integer number v identifies every view.
● Only the messages from the current views are accepted.
Niru Gang
What is Three Phase Commit Protocol in pBFT
The PBFT algorithm goes through 3 phases, the pre-prepare, prepare, and commit phases.
In The Pre-Prepare phase they receive the request and create a proposal. It assigns a
sequence number n to the request and multicast a message
In this scenario Frodo is a faulty replica, hence the f next to its name
In this scenario Frodo is a faulty replica, hence the f next to its name
Niru Gang
Commit phase, the name says it all, they commit their agreement and reply back. In addition
they individually execute the request to check that they are getting the same results (to ensure
the consensus property safety).
In this scenario Frodo is a faulty replica, hence the f next to its name
Benefits of PBFT
● A pBFT doesn’t require carrying out high mathematical computations like PoW.
● It is an energy-efficient consensus model.
● It requires less time.
Limitations of pBFT
● pBFT has a high communication overhead that will increase with the number of nodes in
the network.
● It has scalability issues with more extensive networks.
● pBFT is susceptible to Sybil attacks in which one node controls or acts as multiple
network nodes.
Niru Gang
● Even though the project is hosted and driven by the free folk of the internet ‘Linux
Foundation’, technology giants like IBM, Intel, Samsung and many more have already
become part of the project.
● Hyperledger provides the platform to create personalized blockchain service according
to the need of business work.
● Unlike other platforms for developing blockchain based software, Hyperledger has an
advantage of creating secured and personalized blockchain networks.
Hyperledger fabric
● Hyperledger Fabric is an open-source platform for building distributed ledger solutions,
with a modular architecture that delivers high degrees of confidentiality, flexibility,
resiliency, and scalability.
● This enables solutions developed with fabric to be adapted for any industry.
● This is a private and confidential blockchain framework managed by the Linux
Foundation.
Niru Gang
List different hyperledger platform and explain features in details / Compare
different hyperledger platform
Niru Gang
Explain working of hyperledger fabric transactions
● Here when clients submit the transaction proposal through the Fabric SDK, this proposal
is sent to all Endorsing Peers.
● These endorsing peers check if the transaction verifies and executes and generates the
Read and Write set as output.
● Now, this response is again sent to the client. The client collects all responses from all
endorsing peers, and sends them to Orderer.
● Now, the Orderer sees all transactions and orders them in ascending order and forms a
block.
● Now, this block is sent to all committers which checks the transaction and add a new
block in their own copy of the ledger.
Niru Gang
Ethereum vs. Hyperledger Fabric
Niru Gang
Chapter 6
Niru Gang
Explain features of Ripple
● Ripple is an open-source protocol developed to support transactions in a cheap and fast
way.
● It is not just a platform but also a currency.
● The platform’s own currency is called XRP and it also lets businesses create their own
currency with the help of RippleNet.
● It was founded in 2012 and was renamed from Opencoin in 2015.
● The mission of RippleNet is to allow banks to process cross-border transactions in a less
costly and quick manner.
● Thus, it is an ideal option for the present global payment system used by most banks.
● XRP is touted to be faster and scalable than most other blockchains (4 seconds payment
settlement versus 1+ hour in Bitcoin with the ability to 1,500 transactions per second
compared to 3-6 for Bitcoin).
● Developers are leveraging XRP Ledger to develop creative software and products for
gaming, web monetization, and content where the currency is the main part.
● Businesses can develop robust finance applications on Ripple. The platform can also be
used to send receipts, invoices, and other types of digital documents.
● Big brands like Santander, American Express, MoneyGram International, SBI Holdings,
and Deloitte are testing the potential of Ripple’s Blockchain and planning to integrate it to
make the existing payment processes secure and faster.
Niru Gang
● It doesn’t employ the Proof of Work (PoW) consensus mechanism, instead relying on
vote-based and other techniques to execute thousands of operations per second,
according to how smart contracts and other networks are set up.
● Quorum can handle the bulk of Ethereum changes swiftly and efficiently since it only
alters Ethereum’s core to a limited extent.
● Quorum is also open sourced, free to use in perpetuity and encourages experimentation.
● Key features
○ Can swiftly handle tonnes of Ethereum changes.
○ Working is quite efficient.
● Basically, Quorum is an enhanced version of Ethereum .
● Quorum resolves the issue of the confidentiality of records that Ethereum and other
blockchains failed to handle by introducing private and public on-chain transactions.
● Use cases of Quorum blockchain in finance and banking include applications like
tokenized cash, supply chain finance, trade finance, and capital market data.
● Another example of using Quorum blockchain is in the healthcare industry. Synaptic
Healthcare Alliance is a pilot blockchain project that focuses on creating an industry-wide
database for healthcare providers using Quorum.
Niru Gang
Compare and contrast Corda, Ripple, and Quorum
Niru Gang
Explain difference platforms available and compare
Niru Gang
available to any user. Ethereum and the DeFi protocols running on it are also built with
open source code that is available for anyone to view, audit, and build upon.
● Permissionless. Unlike traditional finance, DeFi is defined by its open, permissionless
access: anyone with a crypto wallet and an Internet connection, regardless of their
geography and often without any minimum amount of funds required, can access DeFi
applications built on Ethereum.
● Self-Custody. By using Web3 wallets like MetaMask to interact with permissionless
financial applications and protocols, DeFi market participants always keep custody of
their assets and control of their personal data.
Niru Gang