Nothing Special   »   [go: up one dir, main page]

BlockChain Lab Assignments

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

LAKSHAMI NARAIN COLLEGE OF

TECHNOLOGY EXCELLENCE, BHOPAL (M.P.)

LABORATORY ASSIGNMENT

Block Chain Technologies


Lab Assignment

VIII SEM (CSE)

DEPARTMENT OF
COMPUTER SCIENCE & TECHNOLOGY
LAKSHAMI NARAIN COLLEGE OF
TECHNOLOGY EXCELLENCE, BHOPAL (M.P.)

DEPARTMENT OF
COMPUTER SCIENCE & TECHNOLOGY

CERTIFICATE

This is to certify that Mr./Ms. Devesh Singh with RGPV Enrollment

No. 0176CS171058 has satisfactorily completed the course of

experiments in Block Chain Technologies as prescribed by Rajiv

Gandhi Proudhyogiki Vishwavidhyalaya, Bhopal for CSE-VIII

Semester of the Computer Sciecne & Engineering Department during

Jan –June 2021.

Signature of
Faculty In-charge
Q1. Explain the process of Bitcoin mining; on what type of block chain
it is it based and how it works.

Ans. Bitcoin mining is the process of verifying bitcoin transactions


and recording them in the public blockchain ledger. In blockchain,
the transactions are verified by bitcoin users, so basically the
transactions have to be verified by the participants of the network.
Those who have the required hardware and computing power are
called miners.

We will talk more about them later, but the important concept to
understand here is that there is nothing like a centralized body—a
regulatory body, a governing body, a bank—to make bitcoin
transactions go through. Any user with mining hardware and
Internet access can be a participant and contribute to the mining
community.

The process is solved based on a difficult mathematical puzzle


called proof of work. The proof of work is needed to validate the
transaction and for the miner to earn a reward. All the miners are
completing amongst themselves to mine a particular transaction;
the miner who first solves the puzzle gets the reward. Miners are
the network participants who have the necessary hardware and
computing power to validate the transactions.
3 Concepts of Blockchain

To understand bitcoin mining, you have to first understand the


three major concepts of blockchain.

1. Public distributed ledger: A distributed ledger is a record of


all transactions maintained in the blockchain network across
the globe. In the network, the validation of transactions is done
by bitcoin users.
2. SHA-256: Blockchain prevents unauthorized access by
using a hash function called SHA-256 to ensure that the blocks
are kept secure. They are digitally signed. Their hash value,
once generated, cannot be altered. SHA-256 takes an input
string of any size and returns a fixed 256-bit output, and it is a
one-way function—you cannot derive the reverse of the input
reverse fully from the output (what you have generated).
3. Proof of work: In blockchain mining, miners validate
transactions by solving a difficult mathematical puzzle called
proof of work. To do that, the primary objective of the miner is
to determine the nonce value, and that nonce value is the
mathematical puzzle that miners are required to solve to
generate a hash that is less than the target defined by the
network for a particular block.
The goal of blockchain is to allow digital information to be
recorded and distributed, but not edited. Blockchain technology
was first outlined in 1991 by Stuart Haber and W. Scott Stornetta,
two researchers who wanted to implement a system where
document timestamps could not be tampered with. But it wasn’t
until almost two decades later, with the launch of Bitcoin in
January 2009, that blockchain had its first real-world application.

The Bitcoin protocol is built on a blockchain. In a research paper


introducing the digital currency, Bitcoin’s pseudonymous creator,
Satoshi Nakamoto, referred to it as “a new electronic cash system
that’s fully peer-to-peer, with no trusted third party.”

The key thing to understand here is that Bitcoin merely uses


blockchain as a means to transparently record a ledger of
payments, but blockchain can, in theory, be used to immutably
record any number of data points. As discussed above, this could
be in the form of transactions, votes in an election, product
inventories, state identifications, deeds to homes, and much
more. 
Currently, there is a vast variety of blockchain-based projects
looking to implement blockchain in ways to help society other than
just recording transactions. One good example is that of
blockchain being used as a way to vote in democratic elections.
The nature of blockchain’s immutability means that fraudulent
voting would become far more difficult to occur. 

For example, a voting system could work such that each citizen of
a country would be issued a single cryptocurrency or token. Each
candidate would then be given a specific wallet address, and the
voters would send their token or crypto to whichever candidate's
address they wish to vote for. The transparent and traceable
nature of blockchain would eliminate the need for human vote
counting as well as the ability of bad actors to tamper with
physical ballots.

Q2. What is the difference between Bitcoin block chain and Ethereum
block chain?

Ans. Bitcoin was the first true cryptocurrency and has been in


circulation since 2009. Ethereum is a far more recent
development, going live in 2015.
In the time between Bitcoin and Ethereum’s release, lots of other
cryptocurrencies emerged. Mostly, however, they were limited to
trying to improve on aspects of Bitcoin’s performance – for
example, increasing speed of transactions or improving the
security or anonymity of transactions.
Ethereum is certainly faster than Bitcoin – with transactions
typically settling in seconds, rather than minutes. But it also takes
things further. While still blockchain based, and operating as a
store of value, its fans and evangelists see it as a platform for
distributed computing, which comes with its own built-in currency,
called Ether.
While the Bitcoin blockchain can simply be pictured as a database
of accounts (or wallets) with an amount of currency stored in
each, the Ethereum network blockchain is a more sophisticated
construction, capable of storing computer code – applications –
that can use the CPU power going into the network to execute.
The currency – Ether – represents this CPU power – so the idea
is that Ether will be bought and sold by businesses, governments
or individuals to allow them to tap into the vast, distributed
resources of the Ethereum network to run their own apps.
The first of these applications are known as “smart contracts”.
This is a way of automating contracts and agreements so they will
execute when consensus says that conditions have been filled.
Though simple, their uses are potentially widespread – such as
enabling payment systems which will release funds on completion
of work, or authorising the transfer of ownership of good when
payment has been made.
The Ethereum network also allows the creation of other
cryptocurrencies, or tokens, using the same protocol as Ether but
distributed on different blockchains, which can be public or
private. This means they can be created by organisations to
represent shares, voting rights or as means of proving identity or
authorisationcredentials.
Ether (ETH), the cryptocurrency of the Ethereum network, is
arguably the second most popular digital token
after bitcoin (BTC). Indeed, as the second-largest cryptocurrency
by market cap, comparisons between Ether and BTC are only
natural.

Ether and bitcoin are similar in many ways: each is a digital


currency traded via online exchanges and stored in various types
of cryptocurrency wallets. Both of these tokens are decentralized,
meaning that they are not issued or regulated by a central bank or
other authority. Both make use of the distributed ledger
technology known as blockchain. However, there are also many
crucial distinctions between the two most popular
cryptocurrencies by market cap. Below, we'll take a closer look at
the similarities and differences between bitcoin and ether.

KEY TAKEAWAYS

 Bitcoin signaled the emergence of a radically new form of


digital money that operates outside the control of any
government or corporation.
 With time, people began to realize that one of the underlying
innovations of bitcoin, the blockchain, could be utilized for
other purposes. 
 Ethereum proposed to utilize blockchain technology not only
for maintaining a decentralized payment network but also for
storing computer code which can be used to power tamper-
proof decentralized financial contracts and applications.
 Ethereum applications and contracts are powered by ether,
the Ethereum network’s currency.
 Ether was intended to complement rather than compete with
bitcoin, but it has nonetheless emerged as a competitor on
cryptocurrency exchanges.

Bitcoin Basics
Bitcoin was launched in January of 2009. It introduced a novel
idea set out in a white paper by the mysterious Satoshi Nakamoto
—bitcoin offers the promise of an online currency that is secured
without any central authority, unlike government-
issued currencies. There are no physical bitcoins, only balances
associated with a cryptographically secured public ledger.
Although bitcoin was not the first attempts at an online currency of
this type, it was the most successful in its early efforts, and it has
come to be known as a predecessor in some way to virtually all
cryptocurrencies which have been developed over the past
decade.1

Over the years, the concept of a virtual, decentralized currency


has gained acceptance among regulators and government
bodies. Although it isn’t a formally recognized medium of payment
or store of value, cryptocurrency has managed to carve out a
niche for itself and continues to coexist with the financial system
despite being regularly scrutinized and debated.

 
At the start of the cryptocurrency boom in 2017, Bitcoin’s market
value accounted for close to 87% of the total cryptocurrency
market.

Ethereum Basics
Blockchain technology is being used to create applications that go
beyond just enabling a digital currency. Launched in July of 2015,
Ethereum is the largest and most well-established, open-ended
decentralized software platform.

Ethereum enables the deployment of smart contracts and


decentralized applications (dapps) to be built and run without any
downtime, fraud, control or interference from a third party.
Ethereum comes complete with its own programming language
which runs on a blockchain, enabling developers to build and run
distributed applications.

The potential applications of Ethereum are wide-ranging and are


powered by its native cryptographic token, ether (commonly
abbreviated as ETH). In 2014, Ethereum launched a presale for
ether, which received an overwhelming response. Ether is like the
fuel for running commands on the Ethereum platform and is used
by developers to build and run applications on the platform.
Ether is used mainly for two purposes—it is traded as a digital
currency on exchanges in the same fashion as
other cryptocurrencies, and it is used on the Ethereum network to
run applications. According to Ethereum, “people all over the
world use ETH to make payments, as a store of value, or as
collateral.”2

Key Differences
While both the Bitcoin and Ethereum networks are powered by
the principle of distributed ledgers and cryptography, the two differ
technically in many ways. For example, transactions on the
Ethereum network may contain executable code, while data
affixed to Bitcoin network transactions are generally only for
keeping notes. Other differences include block time (an ether
transaction is confirmed in seconds compared to minutes for
bitcoin) and the algorithms that they run on (Ethereum uses
ethash while Bitcoin uses SHA-256). 

More importantly, though, the Bitcoin and Ethereum networks are


different with respect to their overall aims. While bitcoin was
created as an alternative to national currencies and thus aspires
to be a medium of exchange and a store of value, Ethereum was
intended as a platform to facilitate immutable, programmatic
contracts, and applications via its own currency. 

BTC and ETH are both digital currencies, but the primary purpose
of ether is not to establish itself as an alternative monetary
system, but rather to facilitate and monetize the operation of the
Ethereum smart contract and decentralized application (dapp)
platform.

Ethereum is another use-case for a blockchain that supports the


Bitcoin network, and theoretically should not really compete with
Bitcoin. However, the popularity of ether has pushed it into
competition with all cryptocurrencies, especially from the
perspective of traders. For most of its history since the mid-2015
launch, ether has been close behind bitcoin on rankings of the top
cryptocurrencies by market cap. That being said, it's important to
keep in mind that the ether ecosystem is much smaller than
bitcoin's: as of January 2020, ether's market cap was just under
$16 billion, while bitcoin's is nearly 10 times that at more than
$147 billion.

Q3. Which cryptographic algorithm is used in Block chain?

Ans. Blockchains make use of two types of cryptographic algorithms,


asymmetric-key algorithms, and hash functions. Hash functions are used
to provide the functionality of a single view of blockchain to every
participant. Blockchains generally use the SHA-256 hashing algorithm
as their hash function. 
Cryptographic hash functions provide the following benefits to the
blockchain:
 Avalanche effect – A slight change in the data can result in a
significantly different output.
 Uniqueness – Every input has a unique output.
 Deterministic – Any input will always have the same output if
passed through the hash function.
 Quickness – The output can be generated in a very small amount
of time.
 Reverse engineering is not possible, i.e. we cannot generate the
input by having the output and the hash function.
Hash functions have a major role in linking the blocks to one another
and also to maintain the integrity of the data stored inside each block.
Any alteration in the block data can lead to inconsistency and break the
blockchain, making it invalid. This requirement is achieved by the
property of the hash functions, called the ‘avalanche effect’.
According to this, if we make even a slight change in the input to the
hash function, we will end up getting a totally unrelated output as
compared to the original output. Let us take an example of an SHA-256
hash function, and compare their outputs, 
Input: Blockchain at upGrad
Output: 04f0ecc95159533982d7571eada5f8d76592b6e97ead964467c6
03d31b9e7a9c
Input with a slight difference: Blockchain at upGrad
Output: 80b069904b6a8db46ed94e7091ff4e5fc72fae5422d46cc57d8f6
6db7abf4781 
You can notice the huge difference in output after changing a single
character at the input from lowercase to uppercase. This makes the data
reliable and secure on the blockchain; any changes in the block data will
lead to this difference in hash value and make the blockchain invalid,
making it immutable.
Asymmetric-key cryptography is where the private key generally needs
to be produced by a random number algorithm, and the public key is
calculated by executing an irreversible algorithm. The asymmetric
encryption algorithm has the advantage of having separate public and
private keys, which can be transferred over unsecured channels.
Likely, it also has several disadvantages, some of them being low
processing speed and unsatisfactory encryption strength. It is very much
necessary to ensure the security of the asymmetric encryption algorithm
during the transmission of data on the blockchain.
One of the major parts of asymmetric-key cryptography is digital
signatures. Digital signatures provide integrity to the process; they are
easily verifiable and cannot be corrupted. They also hold the quality of
non-repudiation, making them similar to the signatures in the real-world.
The digital signatures ensure that the blockchain is valid and the data is
verified and correct. 
Hashing, public-private key pairs, and the digital signatures together
constitute the foundation for the blockchain. These cryptographic
features make it possible for blocks to get securely linked by other
blocks, and also ensure the reliability and immutability of the data stored
on the blockchain.
There are a huge number of applications of blockchain technology, and
cryptography makes it possible. One of the major real-world
applications of cryptography in the blockchain is cryptocurrencies. Let
us look at its application in cryptocurrencies.
Source
Cryptocurrencies are one of the major applications of blockchains, and they
use public-private key pairs to maintain the addresses of the users on the
blockchain. For cryptography in blockchain, the public key is used as the
address of the person. The public key is visible globally, i.e. it is visible to
any participant of the participant. The private key is a secret value and is used
to access that address data and authorize any of the actions for the ‘address’,
which are generally transactions. 

Digital signatures are widely used for cryptocurrencies. They are used to
approve transactions by signing them securely (offline) and are also used for
multi-signature contracts and digital wallets on the blockchain. To perform
any action from these multi-signature contracts and digital wallets, the digital
signatures from multiple (different) private keys are required before any
action to be executed.
Q4. What are Merkle trees? How important are Merkle trees in
Block chains?

Ans. Merkle trees are a fundamental part of blockchain


technology. A merkle tree is a structure that allows for efficient
and secure verification of content in a large body of data. This
structure helps verify the consistency and content of the data.
Merkle trees are used by both Bitcoin and Ethereum
.
How do Merkle trees work?
A Merkle tree summarizes all the transactions in a block by
producing a digital fingerprint of the entire set of transactions,
thereby enabling a user to verify whether or not a transaction is
included in a block.
Merkle trees are created by repeatedly hashing pairs of nodes
until there is only one hash left (this hash is called the Root Hash,
or the Merkle Root). They are constructed from the bottom up,
from hashes of individual transactions (known as Transaction
IDs).
Each leaf node is a hash of transactional data, and each non-leaf
node is a hash of its previous hashes. Merkle trees are binary and
therefore require an even number of leaf nodes. If the number of
transactions is odd, the last hash will be duplicated once to create
an even number of leaf nodes.
The Merkle Tree of transactions A, B, C & D.

Let’s look at an example of four transactions in a block: A, B, C,


and D. Each of these is hashed, and the hash stored in each leaf
node, resulting in Hash A, B, C, and D. Consecutive pairs of leaf
nodes are then summarized in a parent node by hashing Hash A
and Hash B, resulting in Hash AB, and separately hashing Hash
C and Hash D, resulting in Hash CD. The two hashes (Hash AB
and Hash CD) are then hashed again to produce the Root Hash
(the Merkle Root).
This process can be conducted on larger data sets, too:
consecutive blocks can be hashed until there is only one node at
the top. Hashing is usually conducted using the SHA-
2 cryptographic hash function, though other functions can also be
used.
The Merkle Root summarizes all of the data in the related
transactions, and is stored in the block header. It maintains the
integrity of the data. If a single detail in any of the transactions or
the order of the transactions changes, so does the Merkle Root.
Using a Merkle tree allows for a quick and simple test of whether
a specific transaction is included in the set or not.

A Merkle tree differs from a hash-list in that with a Merkle tree,


one branch can be downloaded at a time and the integrity of each
branch can be immediately verified, even if the rest of the tree is
not yet available. This is advantageous because files can be split
up into very small data blocks, such that only small blocks need to
be downloaded again if the original version is damaged.
Uses
Using a Merkle tree can significantly reduce the amount of data
that a trusted authority has to maintain for verification purposes. It
separates the validation of the data from the data itself. A Merkle
tree can reside locally, or on a distributed system.
Merkle trees have three major benefits:
1. They provide a means to prove the integrity and validity of data
2. They require little memory or disk space as the proofs are
computationally easy and fast
3. Their proofs and management only require tiny amounts of
information to be transmitted across networks
The ability to prove that a log is complete and consistent is
essential to blockchain technology and the general ledger
concept. Merkle trees help verify that later versions of a log
include everything from an earlier version and that all data is
recorded and presented in chronological order. Proving that a log
is consistent requires showing that no previous records have
been added, altered or tampered with, and that the log has never
been branched or forked.
Merkle trees benefit miners and users on the blockchain. A miner
can calculate hashes progressively, as the miner receives
transactions from peers. A user can verify parts of blocks
individually and can check individual transactions using hashes of
other branches of the tree.
Simplified Payment Verification (SPV)
Simplified Payment Verification (SPV) is a method of verifying if
particular transactions are included in a block without
downloading the entire block. Merkle trees are used extensively
by SPV nodes.
SPV nodes do not have data from all transactions in a block. They
only download block headers. Merkle trees enable SPV nodes on
the blockchain to check if miners have verified the transactions in
a block without downloading all the transactions in a block. This
method is currently used by some lightweight Bitcoin clients.
Ethereum
Ethereum uses three different Merkle Roots in each block:
1. The first root is of the transactions in the block
2. The second root represents the state
3. The third root is for transaction receipts
Ethereum uses a special type of hash tree called the ‘Merkle
Patricia Tree’
Q5. Explain the components of Block chain Ecosystem?

Ans. To understand how blockchain technology, as distinct from


its application to cryptocurrencies, it is necessary to understand
the logical components of a blockchain ecosystem and what each
component does. The four (4) main components of any blockchain
ecosystem are as follows:

1. a node application

2. a shared ledger

3. a consensus algorithm

4. a virtual machine

1. Node Application

Each Internet-connected computer needs to install and run a


computer application specific to the ecosystem they wish to
participate in. Using the case of Bitcoin as an example ecosystem,
each computer must be running the Bitcoin wallet application.

(In slightly more technical parlance, the blockchain ecosystem


constitutes a service overlay network (SON) and to be a node in
the network your computer must be able to process application-
specific messages and affect the shared state of the SON.)

In some blockchain applications, like Bankchain, participation is


restricted and requires special permissions to join (referred to as
permissioned blockchains). Bankchain only permits banks to run
the node application. Whereas the Bitcoin ecosystem allows
anyone to download and install the node application and thus
participate in the ecosystem.Regardless of how one is qualified,
once one has a node application one can participate in the
respective blockchain ecosystem.

2. Shared Ledger

This is a logical component. The distributed ledger is a data


structure managed inside the node application. Once you have the
node application running, you can view the respective ledger (or
blockchain) contents for that ecosystem.

If you are running the Ethereum client, you can see the Ethereum


ecosystem ledger and interact according to the rules of that
ecosystem (smart contracts, payments, etc.). If you are running
the Bitcoin client, you can participate in the Bitcoin ecosystem,
according to the rules set out in the program code of the Bitcoin
node application.

You can run as many node applications as you like and are
permitted to use, and each will participate in their respective
blockchain ecosystems. It is important to note that regardless of
how many ecosystems you are a participant in, you will only have
one shared ledger for each ecosystem.

3. Consensus Algorithm

This, too, is a logical component of the ecosystem. The


consensus algorithm is implemented as part of the node
application, providing the ‘rules of the game’ for how the
ecosystem will arrive at a single view of the ledger. Different
ecosystems have different methods for attaining consensus
depending on the desired features the ecosystem needs. For
example, Bitcoin arrives at consensus of the ledger in a few
minutes, the Lightning ecosystem provides Guardtime’s industrial
blockchain platform provides sub-second consensus formation
times, and Ripple guarantees consensus in a few seconds.
Participation in the consensus building process, the method for
determining the “world state” of the ecosystem can be vested in a
number of different schemes: proof-of-work, proof-of-stake, proof-
of-elapsed-time; each method qualifies nodes as honest in a
different way before participate in the consensus building process.

4. Virtual Machine

The virtual machine is the final logical component implemented as


part of the node application that every participant in the ecosystem
runs. To understand the capabilities added to an ecosystem by
including a virtual machine let’s take a quick look at what a virtual
machine is.

To understand virtual machines it helps to understand how a


computer program runs on your computer. When a physical
computer runs a computer program, the instructions in the
computer program tells the computer to changes its “state”. We
sense the changes of “state” on the physical computer in multiple
ways: as a display showing information and graphics, as the
alteration of information held in memory, as sound sent out to the
speakers, as information stored on a solid-state drive.
A virtual machine is a representation of a machine (real or
imaginary) created by a computer program and operated with
instructions embodied in a language. It is an abstraction of a
machine, held inside a machine. To some degree we are already
are accustomed to abstraction of real world objects and entities as
virtual objects in a computer. Think of a button in a graphical user
interface of an application. You press the button on the screen
and the state of the program inside the computer changes.
Another example might be your driver’s license as it represented
in a government computer. It is an abstraction of your real-world
legal authorisation to operate a motor vehicle and it is largely what
counts these days, rather than the real-world physical printed
driver’s license.

Ethereum is a blockchain ecosystem that, like Bitcoin, implements


a virtual machine. The virtual machine lives in the Ethereum node
application, called a wallet, and unlike Bitcoin, it can understand a
wider range of instructions making it possible to manage the state
of a digital contracts aka smart contracts. The instructions take the
form of a special programming languagethat instructs the
Ethereum virtual machine in the node application to enforce the
terms of the contract consuming and releasing a digital token
called “ether” as part of the transaction. The contract cannot be
tampered with, again because of the cryptographic integrity of
information on the Ethereum blockchain.

You might also like