Unit 2 Notes
Unit 2 Notes
What is Bitcoin, The Bitcoin Network, The Bitcoin Mining Process, Mining
Developments, Bitcoin Wallets, Decentralization and Hard Forks, Ethereum Virtual
Machine (EVM), Merkle Tree, Double- Spend Problem, Blockchain and Digital
Currency, Transactional Blocks, Impact of Blockchain Technology on Cryptocurrency.
2.1Bitcoin
Bitcoin (BTC) is a cryptocurrency, a virtual currency designed to act as money
and a form of payment outside the control of any one person, group, or entity, thus
removing the need for third-party involvement in financial transactions. It is rewarded to
blockchain miners for the work done to verify transactions and can be purchased on
several exchanges.
“Satoshi Nakamoto” is presumed to be the pen name for the person or people
who designed the original bitcoin. Bitcoin was first introduced in the year 2009 as a
medium of exchange. Bitcoin then started as a peer-to-peer network to generate a
system for electronic transactions. Since then, there has been a rapid growth in the
usage as well as the value of bitcoin which is a popular system of digital currency.
There are 3 ways you can get a bitcoin in your electronic storage:
1. Trade Money For Bitcoin: Say that the value of a bitcoin is 1 lakh rupees, so if
you want a bitcoin, you can trade a bitcoin in place of 1 lakh rupees. This Bitcoin
will further be stored in your electronic storage media which you can further use.
2. Trade Goods For Bitcoin: Say that the value of a bitcoin is 1 lakh rupees and you
have a commodity that has its value as 1 lakh rupees, so you can trade that
commodity in place of a bitcoin, and the bitcoin will be stored in your electronic
storage media.
3. Mine Bitcoins: Other than trading, you can also mine bitcoins. Since it is a
decentralized currency, there is no authority that brings bitcoins into the market.
Bitcoins only come into the market by mining them.
2.1.1 Features:
Distributed: All bitcoin transactions are recorded in a public ledger known as
the blockchain. There are nodes in the network that maintain copies of the ledger
and contribute to the correct propagation of the transactions following the rules of
the protocols making it impossible for the network to suffer downtime.
Decentralized: There is no third party or no CEO who controls the bitcoin network.
The network consists of willing participants who agree to the rules of a protocol
and changes to the protocol are done by the consensus of its users. This makes
bitcoin a quasi-political system.
Transparent: The addition of new transactions to the blockchain ledger and the
state of the bitcoin network is arrived upon by consensus in a transparent manner
according to the rules of the protocol.
Peer-to-peer: In Bitcoin transactions, the payments go straight from one party to
another party so there is no need for any third party to act as an intermediary.
Censorship resistant: As bitcoin transactions are pseudo-anonymous and users
possess the keys to their bitcoin holdings, so it is difficult for the authorities to ban
users from using their assets. This provides economic freedom to the users.
Public: All bitcoin transactions are available publicly for everyone to see. All the
transactions are recorded, which eliminates the possibility of fraudulent
transactions.
Permissionless: Bitcoin is completely open access and ready to use for everyone,
there are no complicated rules of entry. Any transaction that follows the set
algorithm will be processed with certainty.
Pseudo-anonymous: Bitcoin transactions are tied to addresses that take the form
of randomly generated alphanumeric strings.
• Each node stores the history of the chain of blocks, containing validated
transactions
• Unlike previous P2P network models, members of the Bitcoin network are
incentivized to participate through cryptocurrency.
• Specifically, the incentive is for the people who mint (create) Bitcoin,
called miners.
2.1.3 Benefits of Bitcoin
• The inputs identify which bitcoins are being spent, and the
outputs assign those bitcoins to their new owners.
• Each input is just a digitally signed reference to some output from a previous
transaction.
• Note that nobody’s real name appears anywhere within a transaction. That’s
why Bitcoin is often said to be pseudonymous.
Obviously, if you want to receive bitcoins, you need to have a Bitcoin address. Your
wallet can generate addresses for you.
In order to generate an address, your wallet first generates a private key. A private key
is nothing but a large number roughly between 1 and 2256.
To make such numbers shorter to write, it’s customary to encode them as sequence of
numbers and letters.
Bitcoin Address
Next, your wallet converts that private key to a Bitcoin address using a well-
known function. This function is very straightforward for a computer to perform.
If anyone knows your private key, they could easily convert it to a Bitcoin
address, too.
In Bitcoin, a valid digital signature serves as proof that the transaction was
authorized by the address’s owner.
Just as a private key was required to generate that address, the same private key
is required, once again, to generate a valid digital signature.
Mempool
The Mempool (Shortcut for Memory Pool) is where the transactions stay until the
miner is ready to get them.
In the bitcoin's blockchain, the miner prioritize the biggest transactions over the
smallest ones.
The nodes of the blockchain network are based on the concept that no one in the
network can be trusted. Proof of work is accepted by nodes to validate any
transaction. Proof of work involves doing hefty calculations to find a 32-bit hash value
called nonce to solve the mathematical puzzle. The miners create new blocks by
abiding by the fact that the transaction volume must be less than 21 million. 21 million
is the total number of bitcoins that can be generated. The verified transaction gets a
unique identification code and is linked with the previous verified transaction.
Let’s understand this with the help of an example-
Suppose Alice wants to transfer 10 BTC to Bob.
Now the transaction data of A is shared with the miners from the memory pool. A
memory pool is a place where an unconfirmed or unverified transaction waits for its
confirmation.
Miners start competing with themselves to solve the mathematical riddle in order to
validate and verify the transaction using proof of work.
The miner who solves the problem first shares his result with other nodes(miners).
Once maximum nodes agree with the solution, the transaction block is verified and
is then added to the blockchain.
At the same time, the miner who solved the puzzle gets a reward of 6.25 bitcoins.
Now, after the addition of the transaction block, the 10 BTC associated with the
transaction data is transferred to Bob from Alice.
2.3.6 How to Start Mining Bitcoin?
A cryptocurrency wallet is a digital wallet that is used to store and transact in different
cryptocurrencies. The crypto wallet doesn't exactly "store" the currency as real-world
wallets do. Instead, it stores public and private keys which help in sending and
receiving money. Bitcoin owners save bitcoins in either an online wallet or a paper
wallet which are similar to a physical wallet. Wallet holds keys to each bitcoin, securing
them and preventing any fraud.
A wallet is used to −
Send and receive money as cryptocurrency
Collect and store coins created by the miner
Synchronize blockchain with all nodes of the network
Opening a wallet is fairly simple; one can download free and paid bitcoin wallets from
internet. Some deal only in bitcoins while others handle multiple cryptocurrencies.
A Bitcoin wallet is simply an app, software, website, or device that manages Bitcoin
private keys for you.
2.4.1Desktop Wallet
Desktop wallets are installable software packs that are available for most
desktop operating systems such as Mac, Windows, and Linux. For example,
Electrum, Exodus.
Desktop wallets are programs that store and manage the private key for your Bitcoins on
your computer’s hard drive.
Mobile wallets are the fourth most secure way to store your cryptocurrencies
because they are always connected to the internet (hot wallets) and can be
flawed by the development community itself. It is available on both IOS and
Android. For example, Jaxx, and Breadwallet.
• A mobile wallet is a virtual wallet that stores payment card information on
a mobile device.
Web wallets are hot wallets that are always connected to the internet and can be
accessed through different browsers such as Google Chrome, Firefox, and
Internet Explorer. For example, Coinbase, and Binance.
• They are ideal for small investments and allow quick transactions.
Most popular hardware wallets are Ledger Nano S and Trezor, KeepKey.
• Hardware wallets are hardware devices that individually handle public addresses
and keys.
• It looks like a USB with OLED screen and side buttons.
• when you open a wallet (in the hardware wallet or software wallet) you are
provided with 2 pair of keys (sometimes more).
Public key and the private key.
• public key is used to generate the public cryptocurrency address you can use
to receive the cryptocurrency, the private key is used to sign the transactions
confirming your ownership over it.
Basically forks are divided into two categories i.e. Codebase Fork and Live
Blockchain Fork. And then Live Blockchain Fork is divided into further two parts
i.e. Intentional Fork and Accidental Fork, as you can see in the above mentioned
figure the Intentional fork is then further divided into two parts i.e. Soft Fork and Hard
Fork.
CODEBASE FORK: In codebase blockchain fork you can copy the entire code of a
particular software. Let us take BITCOIN as an example, so suppose you copied the
whole blockchain code and modified it according to your need, say that you decreased
the block creation time, made some crucial changes and created a faster software
than BITCOIN and publish / launch it has a new whole software named against you,
by completing the whole white paper work process. So in these way a new
BLOCKCHAIN will be created from an empty blank ledger. It’s a fact that many of
these ALT COINS which are now running on the blockchain are been made in these
way only by using the codebase fork i.e. they have made little up and down changes
in the code of BITCOIN and created their whole new ALT COIN.
LIVE BLOCKCHAIN FORK: Live Blockchain fork means a running blockchain is been
divided further into two parts or two ways. So in live blockchain at a specific page the
software is same and from that specific point the chain is divided into two parts. So in
context to this fork the Live Blockchain Fork can occur because of two reasons :
ACCIDENTAL FORK / TEMPORARY FORK: When multiple miners mine a new
block at nearly the same time, the entire network may not agree on the choice of
the new block. Some can accept the block mined by one party, leading to a
different chain of blocks from that point onward while others can agree on the other
alternatives (of blocks) available. Such a situation arises because it takes some
finite time for the information to propagate in the entire blockchain network and
hence conflicted opinions can exist regarding the chronological order of events. In
this fork, two or more blocks have the same block height. Temporary forks resolve
themselves eventually when one of the chain dies out (gets orphaned) because
majority of the full nodes choose the other chain to add new blocks to and sync
with. Example (TEMPORARY FORK / ACCIDENTAL FORK): Temporary forks
happen more often than not and a usual event that triggers this fork is mining of a
block by more than one party at nearly the same time.
INTENTIONAL FORK: In intentional fork the rules of the blockchain are been
changed, knowing the code of the software and by modifying it intentionally. This
gives rise to two types of forks which can occur based on the backwards-
compatibility of the blockchain protocol and the time instant at which a new block is
mined. So Intentional fork can be of two types:
SOFT FORK: When the blockchain protocol is altered in a backwards-compatible way.
In soft fork you tend to add new rules such that they do not clash with the old rules.
That means there is no connection between the old rules and new rules. Rules in soft
fork are tightened. When there is a change in the software that runs on the nodes
(better called as ‘full nodes’) to function as a network participant, the change is such
that the new blocks mined on the basis of new rules (in the Blockchain protocol) are
also considered valid by the old version of the software. This feature is also called as
backwards-compatibility. Example (SOFT FORK): The Bitcoin network’s SegWit
update added a new class of addresses (Bech32). However, this didn’t invalidate the
existing P2SH addresses. A full node with a P2SH type address could do a valid
transaction with a node of Bech32 type address.
Ethereum Virtual Machine (EVM) is designed as the runtime environment for smart
contracts in Ethereum. It is sandboxed and isolated from the other parts of the system.
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.
An EVM is the runtime environment that executes Ethereum smart contracts.
Ethereum contains its own Turing-complete scripting language, called Solidity, and
with this comes a need to execute this code.
A program called the Ethereum Virtual Machine (EVM) can do this task.
It runs on top of the Ethereum network, meaning that all nodes reach a consensus
about what code should be executed at every given time.
2.6.1 Purpose of EVM
Execute untrusted code without risking data: One can execute untrusted code
without putting the data at risk. EVM guarantees that its computations will not
interfere with anything else happening in the system or with the personal files.
Can run complex smart contracts: One can run complex smart contracts in EVM
without worrying about how they interact with each other. One can write them once
and then run them on multiple platforms, which allows for the creation of a single
contract that runs on multiple computing environments.
Deterministic processing: Smart contracts written on EVM have access to all of
Ethereum’s states at any given time, allowing for processing to happen in a
deterministic way and giving more guarantees about their correctness. For
example, one cannot make an infinite loop in EVM by calling the same function
twice. It would stop executing and return a finite value.
Distributed consensus: One of the potential applications of Ethereum is to allow
for distributed consensus where everyone is running the same program but from
their own computers.
Robust against failure: This is a complex process because the network needs to
be able to come to a consensus at any given time. This way, the system becomes
more robust against failures of individual nodes and you can update several nodes
simultaneously without worrying that they might end up disagreeing with each other
because of how code was written.
Easy to write stateful contracts: From a developer perspective, EVM is designed
for writing smart contracts as well as for creating DApps (decentralized
applications), which are programs running on distributed networks in a way that
ensures all of them are seeing the same version. It also makes it incredibly easy to
write stateful contracts, which need access to some kind of persistent storage.
High cost of storing data: First is gas, which is what you need to use in order to
pay the fee to run a smart contract, and the other is the high cost of storing data on
the blockchain, which could take up more than 3TB
High gas cost: In Ethereum, all transactions require a fee to execute. These fees
are called “gas”, and are paid in ETH tokens. Gas is priced at the moment of
execution, and depends on the complexity of executing a transaction. The more
difficult the computation for a transaction, the higher its gas cost will be.
High gas price during network congestion: During times when there is high
network congestion due to many transactions being pushed onto the blockchain,
gas prices rise because there are fewer transactions that can go through (the same
amount of computational power has to service more transactions).
Technical expertise required: Writing smart contracts and using EVM requires
technical expertise. It’s a Turing-complete system, which allows programmers to
write scripts in any programming language they wish. This can be excellent or
disastrous, depending on the intention behind the code being written. Programming
languages are not inherently good or bad in their nature; it all depends on who is
using them and for what purpose. The downside of this technology is that it could
create a lot of complicated problems because with more power comes more
responsibility for the writer of code.
The concept of Merkle Tree is named after Ralph Merkle, who patented the idea
in 1979. Fundamentally, it is a data structure tree in which every leaf node labelled with
the hash of a data block, and the non-leaf node labelled with the cryptographic hash of
the labels of its child nodes. The leaf nodes are the lowest node in the tree.
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. The Merkle
Trees are constructed in a bottom-up approach.
Every leaf node is a hash of transactional data, and the non-leaf node is a hash of its
previous hashes. Merkle trees are in a binary tree, so it requires an even number of leaf
nodes. If there is an odd number of transactions, the last hash will be duplicated once to
create an even number of leaf nodes.
Root node: The root of the Merkle tree is known as the Merkle root and this
Merkle root is stored in the header of the block.
Leaf node: The leaf nodes contain the hash values of transaction data. Each
transaction in the block has its data hashed and then this hash value (also known
as transaction ID) is stored in leaf nodes.
Non-leaf node: The non-leaf nodes contain the hash value of their respective
children. These are also called intermediate nodes because they contain the
intermediate hash values and the hash process continues till the root of the tree.
4. Bitcoin uses the SHA-256 hash function to hash transaction data continuously till
the Merkle root is obtained.
5. Further, a Merkle tree is binary in nature. This means that the number of leaf
nodes needs to be even for the Merkle tree to be constructed properly. In case there
is an odd number of leaf nodes, the tree duplicates the last hash and makes the
number of leaf nodes even.
Merkle Root is stored in the block header. The block header is the part of the bitcoin
block which gets hash in the process of mining. It contains the hash of the last block, a
Nonce, and the Root Hash of all the transactions in the current block in a Merkle Tree.
So having the Merkle root in block header makes the transaction tamper-proof. As this
Root Hash includes the hashes of all the transactions within the block, these
transactions may result in saving the disk space.
The blockchain is a hash-based linked list of blocks, where each block consists of a
header and transactions. The transactions are arranged in a tree-like fashion, known
as the Merkle tree.
2.7.1 Example: Consider a block having 4 transactions- T1, T2, T3, T4. These four
transactions have to be stored in the Merkle tree and this is done by the following
steps-
Step 1: The hash of each transaction is computed.
H1 = Hash(T1).
Step 2: The hashes computed are stored in leaf nodes of the Merkle tree.
Step 3: Now non-leaf nodes will be formed. In order to form these nodes, leaf nodes
will be paired together from left to right, and the hash of these pairs will be calculated.
Firstly hash of H1 and H2 will be computed to form H12. Similarly, H34 is computed.
Values H12 and H34 are parent nodes of H1, H2, and H3, H4 respectively. These are
non-leaf nodes.
H12 = Hash(H1 + H2)
H34 = Hash(H3 + H4)
Step 4: Finally H1234 is computed by pairing H12 and H34. H1234 is the only hash
remaining. This means we have reached the root node and therefore H1234 is the
Merkle root.
H1234 = Hash(H12 + H34)
Merkle tree works by hashing child nodes again and again till only one hash remains.
The above example is the most common and simple form of a Merkle tree, i.e., Binary
Merkle Tree. There are four transactions in a block: T1, T2, T3, and T4. Here you can
see, there is a top hash which is the hash of the entire tree, known as the Root Hash,
or the Merkle Root. Each of these is repeatedly hashed, and stored in each leaf node,
resulting in Hash 1, 2, 3, and 4. Consecutive pairs of leaf nodes are then summarized in
a parent node by hashing Hash1 and Hash2, resulting in Hash12, and separately
hashing Hash3 and Hash4, resulting in Hash34. The two hashes
(Hash12 and Hash34) are then hashed again to produce the Root Hash or the Merkle
Root.
Double spending means spending the same money twice. As we know, any transaction
can be processed only in two ways. One is offline, and another is online.
Double spending can never arise physically. It can happen in online transactions. This
mostly occurs when there is no authority to verify the transaction. It can also happen if
the user’s wallet is not secured. Suppose a user wants to avail of services from
Merchant ‘A’ and Merchant ‘B’.
The user first made a digital transaction with Merchant ‘A’.
The copy of the cryptocurrency is stored on the user’s computer.
So the user uses the same cryptocurrency to pay Merchant ‘B’
Now both the merchants have the illusion that the money has been credited since
the transactions were not confirmed by the miners.
Let us consider this example:
You go to Restaurants and order a cappuccino worth $5. You pay in cash. The
service provider at Restaurants instantly confirmed that you have paid, and you
received your coffee in exchange for the money. Now is it possible to spend the
same $5 somewhere else to make another purchase? The answer is NO. But
what if the answer is YES? It means the same person can use the same cash
more than one times. This type of problem is known as Double Spending
Problem.
In a physical currency, the double-spending problem can never arise. But in
digital cash-like bitcoin, the double-spending problem can arise. Hence, bitcoin
transactions have a possibility of being copied and rebroadcasted. It opens up
the possibility that the same BTC could be spent twice by its owner.
Let us suppose you have 1 BTC and try to spend it twice. You made the 1 BTC
transaction to Alice. Again, you sign and send the same 1 BTC transaction to Bob. Both
transactions go into the pool of unconfirmed transactions where many unconfirmed
transactions are stored already. The unconfirmed transactions are transactions which
do not pick by anyone. Now, whichever transaction first got confirmations and was
verified by miners, will be valid. Another transaction which could not get enough
confirmations will be pulled out from the network. In this example, transaction T1 is
valid, and Alice will receive the bitcoin.
To tackle these double-spending issues, some security measures are taken. They are:
Validation: Validation of transactions by a maximum number of nodes in the
network. Once a block is created, it is added to a list of pending transactions.
Users send validation for the block. If the verifications are done then only the block
is added to the blockchain.
Timestamp: The confirmed transactions are timestamped, therefore they are
irreversible. If a transaction is involved with a bitcoin it is verified and done. But in
the future, if other transactions are made with the same bitcoin, the transactions
will be canceled.
Block Confirmations: Merchants get block confirmations so that they are assured
that there was no case of double spending. In bitcoin, a minimum of 6
confirmations are done.
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.
2.8.4 What happened if both the transactions are taken simultaneously by the
miners?
Suppose two different miners will pick both transactions at the same time and start
creating a block. Now, when the block is confirmed, both Alice and Bob will wait for
confirmation on their transaction. Whichever transaction first got confirmations will be
validated first, and another transaction will be pulled out from the network.
Now suppose if both Alice and Bob received the first confirmation at the same time,
then there is a race will be started between Alice and Bob. So, whichever transaction
gets the maximum number of confirmations from the network will be included in the
blockchain, and the other one will be discarded.
What is Cryptocurrency?
Intangible
Both blockchain and cryptocurrencies are intangible. Cryptocurrencies are intangible
digital tokens, which you cannot hold physically like the US dollar or the Indian rupee.
The blockchains used for storing cryptocurrencies do not exist in a single place or one
physical data centre.
Advanced
Both blockchain and cryptocurrencies are technological advancements. Blockchain is
the underlying technology behind cryptocurrencies. Blockchain is much more advanced
and secure than traditional databases. Cryptocurrencies are technologically advanced
than physical or paper-based currencies.
Interdependent
Blockchain came into existence to record transactions of bitcoin, the world’s first
cryptocurrency. All major cryptocurrencies have blockchains for recording transactions.
If someone buys a new bitcoin, it is recorded in a bitcoin blockchain.
2.9.2 Differences Between Blockchain and Cryptocurrency
Inherent Nature
Blockchain is a storage technology used for saving data on decentralized
networks. Cryptocurrency is a medium of exchange like the US dollar. A blockchain can
be used for storing different types of information beyond cryptocurrency transaction
records.
Monetary Value
All cryptocurrencies have a monetary value. You must have heard of Bitcoin hitting a
high of 65,000 dollars (around 48 lac rupees) or Ether reaching 4,000 dollars (about 3
lac rupees). A blockchain does not have any monetary value.
Usage
Blockchain technology has uses beyond cryptocurrencies. Blockchain can be used for
recording transactions in banking, healthcare, supply chain, and retail. Cryptocurrency
is digital money, which can be used for buying goods and services and for investment.
Mobility
Blockchain technology is decentralized and distributed all over the world. There is no
single location where all records of a blockchain are stored. Cryptocurrencies, although
held in blockchains, can be accessed via mobile wallets. If you have a bitcoin wallet,
you can use it anywhere for transacting with parties accepting bitcoins.
Transparency
Blockchain, being a public ledger, is highly transparent. Anyone can join a blockchain
network and view the information available. On the other hand, cryptocurrencies offer
anonymity. So, while anyone can see the source/destination of a bitcoin transaction, no
one can know who is behind the transaction.
2.10 Transactional Blocks
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.
This lifecycle follows the journey of a single transaction as it makes its way through
each stage in the process of joining the blockchain. 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.
Let us understand the various stages in a blockchain transaction life cycle with the
help of an example.
Sourav and Suraj are two Bitcoin users. Sourav wants to send 1 bitcoin to Suraj.
1. First, Sourav gets Suraj’s wallet address (a wallet in the blockchain is a digital
wallet that allows users to manage their transactions). Using this information, he
creates a new transaction for 1 bitcoins from his wallet and includes a transaction
fee of 0.003 bitcoin.
2. Next, he verifies the information and sends the transaction. Each transaction that is
initiated is signed by a digital signature of the sender that is basically the private
key of the sender. This is done in order to make the transaction more secure and
to prevent any fraud.
3. Sourav’s wallet then starts the transaction signing algorithm which signs his
transaction using his private key.
4. The transaction is now broadcasted to the memory pool within the network.
5. This transaction is eventually accepted by the miners. These miners, group this
transaction into a block, find the Proof of Work, and assign this block a hash
value to be mapped into the blockchain.
6. This block is now placed on the Blockchain.
7. As this block gains confirmation, it is accepted as a valid transaction in the
network.
8. Once this transaction is accepted, Suraj finally gets his bitcoin.
The below diagram is a pictorial representation of the various stages in a transaction
life cycle as discussed above.
2.11 Impact of Blockchain Technology on Cryptocurrency
Asset Management
Efficient Payments
Consumers can identify which products are made by a particular brand, reducing
Blockchain is a relatively new and emerging technology that has been used successfully
in healthcare for many years. All prominent members of the network and healthcare
providers participate in smooth, efficient data sharing and delivery, which contributes to
the development of economical therapies and sophisticated treatments for various
diseases. In the coming years, the growth in healthcare will accelerate. A recent report
shows that Blockchain technology offers advantages to the logistics sector and the
healthcare sector.
A patient’s information is stored.
Analyse whether a particular procedure had an effect
Valuation
Ensure safety and transparency
Maintaining health records
The clinical trial
The food industry can use blockchain in various ways. Blockchain has several lucrative
uses, which you will see.