L4 Bitcoin Blockchain
L4 Bitcoin Blockchain
Blockchain
Bitcoin Blockchain
                      Learning Objectives
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
         Nodes in this peer-to-peer network talk to each other using the Bitcoin protocol.
                               Bitcoin Components
 Bitcoin
                            Wallets                    Blockchain                   Miners
Network
1 2 33 4
Binance Coinbase
 Kraken                                  Indacoin
                                Spending Bitcoins
• 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.
The wallet is used to store private or public keys and bitcoin addresses. It also helps transact
                                   and store cryptocurrency.
Desktop or Software
                            Web Wallet           Mobile Wallet       Hardware Wallet
      Wallet
          Software or Desktop Wallet
Example
                                                            MultiBit HD
                             Web Wallet
Example
                     Mobile Wallet
Example
                           Hardware Wallet
Example
Install a Software Wallet
Duration: 10 Min
      Problem Statement:
      You have to install a software wallet in your lab system.
                           Assisted Practice: Guidelines
Duration: 10 Min
     Problem Statement:
     You have to generate a paper wallet account.
                           Assisted Practice: Guidelines
Duration: 10 Min
      Problem Statement:
      You must install a web wallet in your lab machine.
                           Assisted Practice: Guidelines
A block in Bitcoin consists of a header, nonce, the size of the block, the number of transactions
                            recorded, and the translation information.
Header
  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
  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
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
   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)
 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
                                         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
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
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
                                      DUP HASH160
                                       <PubKHash>         This is the complete
   <sig> <PubK>
                                      EQUALVERIFY          transaction script.
                                        CHECKSIG
     scriptSig                        scriptPubKey
                           Bitcoin Transaction Script Execution
<PubK>
                                                                  <sig>
  Value of the public key is pushed to the stack.
                                                                  Stack
 <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>
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
                                                                               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
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
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
    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?
 Here, cybercriminals act as providers (exchange, wallet, and so on) and send
                   phishing emails as shown in the figure.
                   Different Ways of Crypto 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.
     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
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.
Note
       Private Blockchains are not vulnerable to 51% attacks.
Bitcoin Network
Bitcoin Networks
Main Network
Test 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
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
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
Joining node selects an address from the list and requests to join the network.
                                    Seed mode
                         Joining the Bitcoin 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
                                                     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
  ● 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
● 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.
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
 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
C. Version, Previous block hash, Merkle root hash, Timestamp, and Difficulty
A. Version, Previous block hash, Merkle root hash, Timestamp, Difficulty, and Nonce
C. Version, Previous block hash, Merkle root hash, Timestamp, and Difficulty
 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
C. It never halves
C. It never halves
 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
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
 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.