0% found this document useful (0 votes)
63 views92 pages

L4 Bitcoin Blockchain

Uploaded by

Prateek Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views92 pages

L4 Bitcoin Blockchain

Uploaded by

Prateek Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 92

Professional Certification Program in

Blockchain
Bitcoin Blockchain
Learning Objectives

By the end of this lesson, you will be able to:

Explore Bitcoin and its elements

Identify and create different wallets for Bitcoin

Analyze the Bitcoin transaction mechanism

Identify the various types of Blockchain attacks

Understand Bitcoin scripting and mining


Introduction to Bitcoin
Introduction to Bitcoin

Bitcoin is the first application of blockchain technology. It was introduced in 2008 through a
paper called Bitcoin: A Peer-to-Peer Electronic Cash System and implemented in 2009.
Introduction to Bitcoin

Bitcoin is defined as a protocol, a digital currency, and a platform. It is a combination of networks,


protocols, and software that facilitates the creation and usage of digital currency.

Nodes in this peer-to-peer network talk to each other using the Bitcoin protocol.
Bitcoin Components

Bitcoin majorly consists of the following components:

Bitcoin
Wallets Blockchain Miners
Network

Transactions Digital Keys Hash Address


Limited Supply of Bitcoin

There is a finite supply of Bitcoins.

Halving: The number of


Bitcoins mined will be
halved after every 210,000
blocks

Difficulty Adjustment: The


Only 21 million Bitcoins will
rate of block creation is
be created for the currency
moderated after every
to maintain value
2016 blocks
Ways to Get Bitcoin

Different ways to get the bitcoins are:

Buying Online Buying Using Cash

• Platforms like Local Bitcoins help


• A user must create an account on
users find people near them who
an online exchange.
are willing to exchange Bitcoin with
• This helps to buy and sell Bitcoin.
cash.
• There are ATMs that send Bitcoins
to their wallet in exchange for cash.
Buying Bitcoin from an Exchange

Follow the given steps to buy bitcoins from any exchange:

1 2 33 4

Step 1: Choose an Step 2: Set up an Step 3: Connect Step 4: Buy Bitcoin


Exchange account bank account
Select the Bitcoin
Choose an exchange Set up an account on Connect the user’s
amount to buy or sell
bank account with
by entering country the exchange. Various and confirm purchase
their exchange
of residence forms of identification
account
are required
Bitcoin Exchanges

These are the different Bitcoin Exchange companies:

Binance Coinbase

Kraken Indacoin
Spending Bitcoins

Different ways of spending bitcoins are:

Spending Online Spending Offline

• Users can buy gift cards online • Users can now buy food and
using Bitcoin. beverages in multiple restaurants
• They can buy apps or games online using Bitcoin.
using Bitcoin. • They can pay for hotel booking
and tickets of cruises and ships.
Addresses in Bitcoin

It is a 64-bit hash address that is generated by hashing the public and private keys of the user with
the SHA-256 algorithm first and RIPEMD-160 next.

A typical bitcoin address looks like this:


1ANAguGG8bikEv2fYsTBnRUmx7QUcK58wt
Bitcoin Wallets
Bitcoin Wallets

The wallet is used to store private or public keys and bitcoin addresses. It also helps transact
and store cryptocurrency.

Wallets today act as both bitcoin client and wallet.


Types of Bitcoin Wallets

Bitcoin wallets are mainly categorized into:

Desktop or Software
Web Wallet Mobile Wallet Hardware Wallet
Wallet
Software or Desktop Wallet

It stores the users’ private keys on their computers.

Example

MultiBit HD
Web Wallet

It is accessed through an internet gateway from any capable device.

Example
Mobile Wallet

It stores the users’ private keys on their cell phones.

Example
Hardware Wallet

It is most secure as private keys are stored in an external USB device.

Example
Install a Software Wallet

Duration: 10 Min

Problem Statement:
You have to install a software wallet in your lab system.
Assisted Practice: Guidelines

Steps to install a software wallet:

1. Download and install the Exodus software wallet


Generate a Paper Wallet

Duration: 10 Min

Problem Statement:
You have to generate a paper wallet account.
Assisted Practice: Guidelines

Steps to generate a paper wallet:

1. Generate a single wallet and a paper wallet


Install a Web Wallet

Duration: 10 Min

Problem Statement:
You must install a web wallet in your lab machine.
Assisted Practice: Guidelines

Steps to install a web wallet:

1. Generate a Jaxx web wallet


Bitcoin Block
Bitcoin Block

A block in Bitcoin consists of a header, nonce, the size of the block, the number of transactions
recorded, and the translation information.

Header

Header • Version : 4 bytes


• Root of previous hash : 32 bytes
Size Magic No.
• Merkle tree root : 32 bytes

Transaction Count • Timestamp : 4 bytes

• Difficulty target : 4 bytes

Transaction • Proof of work Nonce : 4 bytes


Details
Components of Bitcoin Block

Magic Number It is a 4-byte value that is always 0xD9B4BEF9.

Block Size The average size of the block in bitcoin is 1 MB.

Block Header It contains important metadata such as hash values.

Transaction
Count It depicts the number of transactions stored in that block.

Transaction List It lists the details of all transactions stored in that block.
Bitcoin Block Header

Different block header fields are:

Version Previous Block Hash


Provides the version of the It links to the previous block
block and the technology or parent block, effectively
used securing the chain.

Difficulty Timestamp
Contains a Unix epoch
Decides the time taken to
timestamp of the creation
mine a block for rewards
of the block
Review and Analyze a Bitcoin Block on Explorer

Duration: 10 Min

Problem Statement:
You must download the contents of a Bitcoin block and analyze the information in it using
Explorer.
Assisted Practice: Guidelines

Steps to Review and Analyze a Bitcoin Block on Explorer:

1. Visit https://www.blockchain.com/explorer
2. Go to the Latest Blocks section
3. Click on the first block to see all the details like block header and transaction details
Bitcoin Transaction
Bitcoin Transaction

Scenario: Rosa wants to transfer 10 BTC to Joe.


These are the steps that occur for the transaction to be completed:

Step 1 Step 2
Rosa creates a transaction and
Rosa and Joe exchange their
adds a message, Joe’s address,
addresses through a trusted
and 10 BTC to it, and initiates the
medium of communication.
transaction.

Step 4 Step 3
Once verification is done, the
Rosa broadcasts the transaction
amount is credited to Joe and the
on the Bitcoin network and the
transaction is updated in the
miners start validating it.
ledger.
Unspent Transaction Output (UTXO)

It is like a cheque or a coin of a certain


UTXO is the factor by which one denomination. One cannot spend a
determines the wallet balance of a partial amounts in that money is not
user. divisible natively, but instead must
utilize the whole amount.

Each UTXO represents a chain of The UTXOs are all stored in a global
ownership. The owner signs the register from which the miners can
transaction with his signature and verify if the currency is legitimate or
transfers it to the recipient. not.
Unspent Transaction Output (UTXO)

• Let us consider an example where Rosa wants to transfer 0.15 BTC to Joe.
• Bitcoin miners will search for the closest UTXO in terms of amount.
• The whole UTXO will be entered into the transaction, breaking off into two parts.

0.15
The amount transferred
0.5 0.6 0.5 0.6 Rosa’s Wallet
to Joe’s wallet
Bal: 2.75 BTC
1.5 0.3 1.5 0.15

The amount transferred


Rosa’s Wallet as change back to Rosa
Bal: 2.9 BTC
Unspent Transaction Output (UTXO)

• The first part is 0.15 BTC, which is to be transferred to Joe.


• The second part is the 0.15 BTC change that must be returned to Rosa.
• After the transaction is complete, Rosa’s wallet will be updated with the 0.15 BTC and the 0.3
BTC UTXO will be completely removed from the wallet to prevent double spend.

0.15
The amount transferred
0.5 0.6 0.5 0.6 Rosa’s Wallet
to Joe’s wallet
Bal: 2.75 BTC
1.5 0.3 1.5 0.15

The amount transferred


Rosa’s Wallet as change back to Rosa
Bal: 2.9 BTC
Blockchain Transaction Structure

A Bitcoin transaction has three pieces of information:


Input: This is a record of the Bitcoin addresses involved in the transaction
Amount: The number of Bitcoins that the sender intends to transfer
Output: The remaining amount of currency sent back to the sender as UTXO

2. Amount

5BTC In 2BTC
Amount
Sender address Reciever address
34gusdiuh2cghfhiojjjpomfpkfghfjfjkzf
18gusdiuh24iuhiuhiojjjpomfpkokzjfkapl Out
3BTC 3. Output
1. Input
Change sent
to sender’s
address
Analyze a Bitcoin Transaction

Duration: 10 Min

Problem Statement:
You have to analyze a legacy Bitcoin transaction.
Assisted Practice: Guidelines

Steps to Analyze a Bitcoin Transaction:

1. Visit https://www.blockchain.com/explorer
2. Go to the Latest Transactions section
3. Check the Hash of the transactions
4. Click on the first transaction to see the details like hash and fees
Bitcoin Scripts
Bitcoin Scripts

A bitcoin script describes how a


All bitcoin transactions have
user can access the bitcoin. It is a
scripts embedded into their
stack-based programming
inputs and outputs.
language like Forth.

A list of instructions are present with


each transaction. Instructions in
bitcoin are composed of opcodes.
Components of Bitcoin Scripts

This is the hash of the


Transaction Input scriptSig 1ats6365xchagv6bs
user’s Digital Signature
cadhgc75465vy4yt
and Public Key.

OP_DUP These consist of opcodes


OP_HASH160
Transaction Output scriptPubKey that help verify the
PubKHash
authenticity of the
OP_EQUALVERIFY
OP_CHECKSIG transaction.

DUP HASH160
<PubKHash> This is the complete
<sig> <PubK>
EQUALVERIFY transaction script.
CHECKSIG

scriptSig scriptPubKey
Bitcoin Transaction Script Execution

<sig> <PubK> DUP HASH160 <PubKHash> EQUALVERIFY CHECKSIG

Value of the signature <sig> is pushed to the stack.

<sig> <PubK> DUP HASH160 <PubKHash> EQUALVERIFY CHECKSIG


<PubK>

<PubK>

<sig>
Value of the public key is pushed to the stack.
Stack
<sig> <PubK> DUP HASH160 <PubKHash> EQUALVERIFY CHECKSIG

Value of the public key is duplicated in the stack.


Bitcoin Transaction Script Execution

<sig> <PubK> DUP HASH160 <PubKHash> EQUALVERIFY CHECKSIG

This instruction hashes the PubK value twice with RIPEMD160 and SHA-
<PubKHash>
256, resulting in the formation of <PubKHash>.
<PubKHash>

<PubK>

<sig>

<sig> <PubK> DUP HASH160 <PubKHash> EQUALVERIFY CHECKSIG Stack

This pushes the value onto the stack.


Bitcoin Transaction Script Execution

<sig> <PubK> DUP HASH160 <PubKHash> EQUALVERIFY CHECKSIG

This operation determines whether the two values on top of the stack are the
same or not. If they are the same, the values are popped from the stack. <PubK>
<sig>

Stack

<sig> <PubK> DUP HASH160 <PubKHash> EQUALVERIFY CHECKSIG

This instruction checks whether the signature corresponds to the public


key of the user. If true, true is pushed to the stack and the transaction is
completed. True

Stack
Double Spending Problem
Double Spending Problem

Spending the same Bitcoin in more than one transaction is called double spending problem.

Tina

Mark
Balance = 5 BTC
Lisa
Preventing Double Spending

Different ways to prevent double spending are:

• A group of transactions is timestamped.

• Transaction details are sent to all or as many nodes


in the network.

• Blockchain is constantly growing, and each peer


maintains a copy of Blockchain.
Preventing Double Spending

Different ways to prevent double spending are:

• Blockchain ensures that any modification in the


block will lead to recomputing of the following
blocks.

• Anyone can validate the transactions, and this


prevents double spending.
Bitcoin Attacks
Bitcoin Attacks

Blockchain Networks are vulnerable to cyberattacks and fraud despite providing a tamper-proof
ledger of transactions.

People with malicious intent can exploit known vulnerabilities in Blockchain technology and have
been successful in several hacks and frauds over the years.
Bitcoin Attacks

Hackers and fraudsters threaten Blockchains in four primary ways:

Phishing Sybil Attacks


Bitcoin Attacks

Hackers and fraudsters threaten Blockchains in four primary ways:

Routing 51% Attack


Bitcoin Attacks: Sybil

In a Sybil attack, hackers create and use many false network identities to flood the network
and crash the system.

Sybil refers to a famous book character diagnosed with a multiple identity disorder.
Types of Sybil Attack

The two types of Sybil attacks are:

Sybil Honest Sybil Middle Honest


Node Node Node Node Node

Direct attack: Sybil node directly Indirect attack: Sybil node influences
influences the honest node. the middle node, which, in turn,
influences the honest node.
Why Is Sybil Attack Done?

Sybil attacks are done:

• To take control of the network and


allow malicious blocks and transactions
• To prevent transactions from being
confirmed
• To reverse the transactions
• To perform double-spending
Prevent Sybil Attack in Bitcoin

Different methods used to prevent Sybil attacks are:

The proof of Work (PoW)


Many miners exist across The transactions are verified
consensus algorithm is used
different geographical by every node and rejected as
to prevent Sybil attacks on
regions. invalid if faulty transactions
Bitcoin.
are included in the block.
Bitcoin Attacks: Phishing

Phishing is a scamming attempt to attain a user's credentials.

1. Fraudsters send emails to wallet


key owners that appear to come
from a legitimate source.
2. The emails ask users for their
credentials using fake hyperlinks.
Crypto Phishing

In Crypto phishing, cybercriminals try to steal cryptocurrencies from the owner.

Here, cybercriminals act as providers (exchange, wallet, and so on) and send
phishing emails as shown in the figure.
Different Ways of Crypto Phishing

Different ways of crypto phishing are:

Google AdWord Message phishing


Chat phishing
phishing

Social media
Email phishing
phishing
Bitcoin Attacks: Routing

Blockchains rely on real-time, large data transfers. Hackers can intercept data while it is being
transferred to internet service providers.

1. In a routing attack, Blockchain


participants typically can't see the
threat, so everything looks normal.

2. However, behind the scenes,


fraudsters have extracted
confidential data or currencies.
Impact of Routing Attack

Let's take an example of Bitcoin where miners solve a puzzle to create a new block and
send that block to the network for confirmation.

Imagine that the attacker does not allow the block to reach the Blockchain and delays it until
another miner solves the same block and gets the reward. The actual miner, however, does not get
any reward.
Routing Attack on Bitcoin

BGP ASes

The Border Gateway


Protocol is the glue that The Internet is made up of
holds the Internet together approximately 67,000
by disseminating Autonomous Systems, each
information about how to with its own AS number (ASN)
reach destinations in and a set of IP prefixes.
remote networks.
Routing Attack on Bitcoin

Another problem arises when 50% of Bitcoin nodes are concentrated in 3 countries only and it is
difficult to image that China alone has around 80% of bitcoin mining pools in the world.

According to the research, 60% of


bitcoin connections use only 3 ASes, so if
an attacker hacks these 3 ASes, they can
disrupt the bitcoin network.
Bitcoin Attacks: 51% Attack

• Mining, especially for large-scale public


Blockchains, requires a significant amount
of computing power.

• If a miner, or a group of miners, could


rally enough resources, they could attain
more than 50% of a Blockchain network's
mining power.

• Having more than 50% of the power


means having control over the ledger and
the ability to manipulate it.

Note
Private Blockchains are not vulnerable to 51% attacks.
Bitcoin Network
Bitcoin Networks

• Bitcoin is an ad-hoc network with a mesh


topology.
• The protocol runs on TCP 8333.
• All the nodes are treated equally in the Bitcoin
network.
• New nodes can join the network anytime, and the
non-responsive nodes are removed after three
hours.
Bitcoin Networks

The two types of Bitcoin networks are:

Main Network

This is the actual network on which all the cryptocurrency


exchanges and transactions are conducted.

Test Network

This is a network that mimics the behavior of the main


network and is used to test new applications and scripts.
Bitcoin Nodes

The two types of Bitcoin nodes are:

Full Node Light Node

Full nodes are


implementations of
These nodes are capable
bitcoin core clients
of only wallet and
performing the wallet,
network routing
miner, blockchain
functionality.
storage, and network
routing functions.
Joining the Bitcoin Network

The steps performed to join the Bitcoin network as an active node (miner) are:

Requesting Retrieving
Selecting the Updating the
the seed the address
peer node network
nodes list
Joining the Bitcoin Network

Step 1: Requesting the Seed Nodes

There are certain special nodes in the bitcoin network called seed nodes that have a list of all
the active (Full) Nodes. New joining nodes ask for the list of addresses from the seed node.

Give me
the
Seed
address
mode
Joining the Bitcoin Network

Step 2: Retrieving the Address List

In response to the node's request to join the network, the seed node sends them the address list.

<Address
list>
Seed
mode
Joining the Bitcoin Network

Step 3: Selecting the Peer Node

Joining node selects an address from the list and requests to join the network.

Seed mode
Joining the Bitcoin Network

Step 4: Updating the Network

A newly joined node gets the most recent copy of the blockchain from its peers.

Seed mode

Receives an
updated copy
of blockchain
Bitcoin Mining
Bitcoin Mining

Bitcoin mining is the process of creating new bitcoins by solving complex


mathematical problems.

Proof of Work
Include the A new block is
Verify the (PoW) consensus
verified added to the
legitimacy of the among all the
transactions in a chain once the
transaction active nodes
block consensus is
generate a
achieved
Nonce
Bitcoin Mining

Step 1: Transaction Verification and Inclusion

● Each node that receives the transaction copy verifies the transaction.
● All validated transactions get stored in a pool called mempool.
● Miners then bundle these transactions to the candidate block.

Transaction
pool
TX1 TX2 … TX9
TX1 TX2 … TX3

5 BTC
5 BTC R J
R J

5 BTC
5 BTC R J
Ross R J Joey
Bitcoin Mining

Step 2: PoW Consensus

● Miners now start looking for a nonce value to generate a block hash that requires certain
leading zeros.
● Miners construct the block and block header that contains version, Merkle root, previous
block hash, difficulty target, and Nonce.

● Root of previous hash


Header
Magic
● Merkle tree root
Size
No. ● Nonce
Transaction
Count ● Difficulty
● Version
Transaction
Details
● Timestamp
Bitcoin Mining

Step 3: Creation of New Block

Once miners create a new block, it gets added to the blockchain


network.

Header Header Header Header


Magic Magic Magic Size Magic
Size Size Size
No. No. No. No.
Txn Count Txn Count Txn Count Txn Count

Transaction Transaction Transaction Transaction


Details Details Details Details

Existing Chain New Block


Orphan Block and Its Rewards

When two valid blocks are mined at the same time and broadcasted in the network, but one block
is not accepted in the main blockchain, such a block is referred to as an orphan block.

Block3b

Block1 Block2 Block3a Block4

Miners will not get any rewards for orphan block.


Key Takeaways

Bitcoin is a cryptocurrency introduced in 2009, and it consists


of various elements, such as miners and wallets.

There are four different types of wallets: hardware, software,


desktop, and mobile.

Bitcoin scripts consist of the scriptSig and scriptPubKey, along


with the opcodes.

Blockchain networks are vulnerable to cyberattacks and fraud


despite providing a tamper-proof ledger of transactions.

Anyone can join the Bitcoin network as a miner by following


four steps and can help verify transactions.
Knowledge Check
Knowledge
Check
How is Bitcoin address generated?
1

A. Hash of public key

B. Hash of private key

C. Hash of the person’s name

D. Hash of any random value


Knowledge
Check
How is Bitcoin address generated?
1

A. Hash of public key

B. Hash of private key

C. Hash of the person’s name

D. Hash of any random value

The correct answer is A

Public keys are hashes of private key, but addresses are hashes of a public key.
Knowledge
Check
What does a Bitcoin block header consist of ?
2

A. Version, Previous block hash, Merkle root hash, Timestamp, Difficulty, and Nonce

B. Version, Merkle root hash, Timestamp, Difficulty, and Nonce

C. Version, Previous block hash, Merkle root hash, Timestamp, and Difficulty

D. Version, Previous block hash, Timestamp, and Difficulty


Knowledge
Check
What does a Bitcoin block header consist of ?
2

A. Version, Previous block hash, Merkle root hash, Timestamp, Difficulty, and Nonce

B. Version, Merkle root hash, Timestamp, Difficulty, and Nonce

C. Version, Previous block hash, Merkle root hash, Timestamp, and Difficulty

D. Version, Previous block hash, Timestamp, and Difficulty

The correct answer is A

A block header consists of the Version, Hash of the previous block, Merkle root hash, Creation Timestamp, Difficulty,
and Nonce.
Knowledge
Check
How frequently is a block mining reward halved?
3

A. After every 100,000 blocks or 8 months, whichever comes first

B. After every 210,000 blocks or 4 years, whichever comes first

C. It never halves

D. After every year


Knowledge
Check
How frequently is a block mining reward halved?
3

A. After every 100,000 blocks or 8 months, whichever comes first

B. After every 210,000 blocks or 4 years, whichever comes first

C. It never halves

D. After every year

The correct answer is B

Reward that comes as a result of mining halves every 210,000 blocks or every fours years, whichever comes first.
Knowledge
Check
Which of the following statements is true in the context of Bitcoin?
4

A. Miners only verify the transaction, and they alone can reject transactions

B. Miners must solve a mathematical puzzle to generate a block with certain leading zeros

C. Miners do not get any reward in Bitcoin

D. Miners create new Bitcoins for other users


Knowledge
Check
Which of the following statements is true in the context of Bitcoin?
4

A. Miners only verify the transaction, and they alone can reject transactions

B. Miners must solve a mathematical puzzle to generate a block with certain leading zeros

C. Miners do not get any reward in Bitcoin

D. Miners create new Bitcoins for other users

The correct answer is B

A miner is the one who uses a nonce to generate a block hash that has certain leading zeros.
Conduct a Transaction of Bitcoin Using Electrum Wallet

You are a Blockchain expert and have been asked to download and set up
the Electrum wallet to conduct a transaction of Bitcoins.

1. Download and set up the Electrum software wallet


2. Create a new Electrum wallet
3. Perform a transaction of Bitcoins using the Electrum wallet

You might also like