Sem 7

Blockchain Fundamentals

Unit 1 deck by Dr Panchami V: course overview, evolution and applications of blockchain, block structure and chaining, SHA-256 hashing, digital signatures, Proof of Work and mining.

Course overviewSearch on YouTube

Prerequisites: Computer Networks and Security, Information Security and Applied Cryptography.

Course objectives

  1. Introduce the concept and the basics of blockchain technology.
  2. Enable awareness of the different generations of blockchains.
  3. Provide knowledge of various applications of blockchain technologies.

Expected outcomes. A student who completes the course can:

  1. Understand the basics of blockchain technologies and their applications.
  2. Understand the cryptocurrency Bitcoin.
  3. Implement a smart contract using Ethereum.
  4. Identify problems to which blockchains could be applied.

Syllabus unitsSearch on YouTube

UnitTopics
IntroductionBlockchain history, basics, architectures, types of blockchain. Base technologies: Docker, hash function, digital signature (ECDSA), zero knowledge proof
BitcoinFundamentals, aspects and properties of Bitcoin, Bitcoin transactions, Bitcoin P2P network, block generation, consensus algorithms: Proof of Work, Proof of Stake, Proof of Burn
EthereumIntroduction, consensus mechanism, implementation, transactions, demonstrations, smart contracts
ApplicationsE-governance, smart cities, smart industries, anomaly detection, use cases, trends, serverless blocks, scalability issues, blockchain on clouds

Reference booksSearch on YouTube

  1. Kevin Werbach, The Blockchain and the New Architecture of Trust, MIT Press, 2018.
  2. Joseph J. Bambara and Paul R. Allen, Blockchain: A Practical Guide to Developing Business, Law, and Technology Solutions, McGraw Hill, 2018.
  3. Melanie Swan, Blockchain: Blueprint for a New Economy, O'Reilly, 2018.
  4. Jai Singh Arun, Jerry Cuomo, Nitin Gaur, Blockchain for Business, Pearson, 2019.
  5. Satoshi Nakamoto, Bitcoin: A Peer-to-Peer Electronic Cash System (see L02).

EvaluationSearch on YouTube

ComponentWeight (%)
Continuous evaluation25 (quiz 10, mini project 15)
Mid semester25
End semester50
Total100

Evolution of blockchain technologySearch on YouTube

The deck shows four generations of blockchain.

GenerationFocusKey features
Blockchain 1.0CurrencyDigital currency, distributed ledger, Merkle tree, blockchain data, PoW
Blockchain 2.0Smart contractsSmart contracts, virtual machine (EVM), decentralized applications
Blockchain 3.0DAppsScalability, good user interface and experience, interoperability, efficiency
Blockchain 4.0IndustryIndustry infrastructure, business-based blockchain ecosystem

Can Smart Devs Innovate: Currency, Smart contracts, DApps, Industry (1.0 to 4.0).

Applications of blockchain technologySearch on YouTube

The applications slide lists: cryptocurrencies, trade finance, banking, crowdfunding, insurance, legal, sharing economy, real estate, Internet of Things, IT cloud storage, healthcare and supply chain.

Why we need blockchainSearch on YouTube

Traditional online payment systems have four problems:

  • High transaction fee charged by banks and intermediaries.
  • Double spending: the same digital money spent twice.
  • Net frauds in online transactions.
  • Poor data recovery when a central server fails.

Bitcoin and blockchain technology solve these problems.

Bitcoin and blockchain technologySearch on YouTube

Bitcoin is a digital currency used to send and receive money across the world in a decentralized way with a minimum transfer fee. Bitcoin stores and transacts money over a distributed peer-to-peer network called the blockchain.

Blockchain is NOT Bitcoin. Bitcoin is one application built on a blockchain. Blockchain is also not just about cryptocurrency.

What exactly is blockchain technologySearch on YouTube

Blockchain is a cryptographically secure, open, distributed ledger.

A distributed public ledger is a database stored and updated independently by each node in the blockchain.

  • Its public and distributed nature makes it unique.
  • Records in a blockchain are immutable.
  • Every node on the network processes every transaction.

The deck draws four nodes (A, B, C, D), all connected to each other. Each node keeps its own full copy of the ledger. There is no central server.

Blockchain and blocksSearch on YouTube

Blockchain is a distributed public database of immutable records called blocks, secured using cryptography.

A block is a record book that holds the details of transaction data. In the simple model, a block has four fields:

  1. Hash of the previous block
  2. Transaction data
  3. Nonce
  4. Hash (of this block)

Chaining blocksSearch on YouTube

The first block is the genesis block. Its previous-hash field is all zeros (0000). Each later block stores the hash of the block before it:

BlockHashPrevious hash
1 (genesis)1Z8F0000
26BQ11Z8F
33H4Q6BQ1

If anyone changes block 1, its hash changes. Block 2 still stores the old hash 1Z8F, so the link breaks. This is why the chain is tamper-evident.

Block 1 (genesis)Prev: 0000Hash: 1Z8FBlock 2Prev: 1Z8FHash: 6BQ1Block 3Prev: 6BQ1Hash: 3H4Q

Mining demoSearch on YouTube

The deck shows a demo block with fields Block: 1, Nonce: 3522, Data: Hellow World, Prev: 0000...0000 and Hash: 0000fdgy..., plus a Mine button. Mining changes the nonce until the hash starts with the required number of zeros (here 0000). If you edit the data, the hash changes and no longer starts with zeros, so the block must be mined again.

Block structure (Bitcoin)Search on YouTube

A real Bitcoin block j has a header and a transaction list.

Header fieldMeaning
VersionProtocol version the block follows
hash(header_{j-1})Hash of the previous block's header; links block j to block j-1
Merkle_RootRoot of the Merkle tree of all transaction hashes
TimestampTime the block was created
Target_Hash_nBitsDifficulty target the block hash must meet
NonceNumber miners change to solve Proof of Work

The transactions (Tx0 to Tx3) are hashed into a Merkle tree of hashes: Hash0 to Hash3 at the leaves, then Hash01 and Hash23, then the Merkle root. Only the root goes into the header.

hash(header_j) is stored in block j+1. Proof of Work requires this hash to begin with n zeros.

Points from the slide:

  • A block is a batch of transactions.
  • The target is to create a new block every 10 minutes.
  • To create a new block, miners compete to find a nonce such that the hash of the block's header begins with n zeros.
  • Successful miners are rewarded with new coins and transaction fees.

The Merkle root is a fingerprint of every transaction in the block. Change one transaction and the root changes. The root sits in the header, so the header hash changes too, and the next block's link breaks.

Features of blockchain technologySearch on YouTube

Digital identity is established through:

  • SHA-256 hash
  • Digital signature
  • Public and private keys
  • Proof of Work
  • Mining

SHA-256 hashSearch on YouTube

SHA-256 takes a message (for example myfile.txt) and produces a 256-bit hash value, shown as 64 hex characters.

Hash function propertiesSearch on YouTube

  • Fixed length output (hash value)
    • A hash function converts data of arbitrary length to a fixed length. This is called hashing the data.
    • The hash is usually much smaller than the input, so hash functions are sometimes called compression functions.
    • A hash is a small representation of larger data, so it is also called a digest.
    • A hash function with an n-bit output is an n-bit hash function.
  • Efficiency of operation: for any hash function h and input x, computing h(x) is fast.
  • One-way function: given h(x), you cannot feasibly find x.
  • Collision resistance: it is infeasible to find two inputs with the same hash.

Avalanche effectSearch on YouTube

The deck hashes "Fox" and four versions of "The red fox jumps over the blue dog" with one-letter changes ("ouer", "oevr", "oer"). Every digest is completely different (for example DFCD 3454 ... for "Fox" and 0086 46BB ... for the full sentence). A tiny input change gives an unrelated output. This is how a blockchain detects even a one-character edit.

For a 2 or 3 mark question on hash properties, list: fixed length output, efficiency, one-way (pre-image resistance), collision resistance. Add the avalanche effect as the reason tampering is visible.

Digital signatureSearch on YouTube

The deck shows signing and verifying in two halves.

1. Signing the message with the private key

  1. Hash the data or message: Hash(message).
  2. Encrypt the hash using the signer's private key. The result is the digital signature.
  3. Attach the signature to the data. This gives digitally signed data.

2. Verifying the message with the public key

  1. Split the signed data into the data and the signature.
  2. Hash the data again.
  3. Decrypt the signature using the signer's public key. This recovers the original hash.
  4. The two hashes should match. If they match, the data is authentic and unchanged.

Bitcoin uses ECDSA (Elliptic Curve Digital Signature Algorithm) for signatures. See L05 for how Bitcoin Script checks the signature.

Proof of WorkSearch on YouTube

Proof of Work is the process of finding a number (the nonce) that, together with a cryptographic hash algorithm, produces a hash value lower than a predefined target.

  • The miner's main task is to find the nonce that makes the hash less than or equal to the target.
  • To find the nonce, miners need to try about 20.6 quadrillion nonce values to get a valid hash.
SHA256(SHA256(header with nonce))≤target\text{SHA256}(\text{SHA256}(\text{header with nonce})) \le \text{target}

How Proof of Work worksSearch on YouTube

  1. Transaction data is distributed across the users of the Bitcoin network.
  2. Miners validate the unverified transactions and add them to a block.
  3. Miners compete to solve a difficult puzzle based on the nonce and a cryptographic hash function. This puzzle is Proof of Work.
  4. The first miner who solves the puzzle gets the reward.
  5. The rewarded block is added to the existing chain.

Candidate blockSearch on YouTube

  • A miner who sees block #1000 confirmed starts building block #1001.
  • The miner listens to the transaction pool for new transactions and puts them into the candidate block.
  • Cycle: transaction pool, candidate block, Proof of Work, transmit the block to the network.
  • After solving the puzzle, the result is sent back to the network.

MiningSearch on YouTube

  • When the transactions in a block are confirmed, a new block is added to the chain. The bitcoin in those transactions can then be spent.
  • The miner who solves the puzzle gets a reward of 3.125 bitcoins.
  • The reward per block is halved every 210,000 blocks (about every 4 years).

Reward history: 50 BTC (2009), 25, 12.5, 6.25, now 3.125 BTC (since the April 2024 halving). Halving interval: 210,000 blocks, about 4 years.

How a transaction gets into the blockchainSearch on YouTube

  1. A transaction is requested and authenticated.
  2. A block representing that transaction is created.
  3. The block is sent to every node (participant) in the network.
  4. Nodes validate the transaction.
  5. Nodes receive a reward for Proof of Work, typically in cryptocurrency.
  6. The block is added to the existing blockchain.
  7. The update is distributed across the network.
  8. The transaction is complete.

Quick self-testSearch on YouTube

Define blockchain. What are the four fields of a block in the simple model?

A blockchain is a distributed public database of immutable records called blocks, secured using cryptography. A block holds the hash of the previous block, transaction data, a nonce, and its own hash.

Name the four generations of blockchain and one feature of each.

1.0 Currency (digital currency, PoW); 2.0 Smart contracts (virtual machine, DApps); 3.0 DApps (scalability, interoperability); 4.0 Industry (business-based ecosystem).

List the fields in a Bitcoin block header.

Version, previous block header hash, Merkle root, timestamp, target (nBits) and nonce.

What is the genesis block and what is its previous hash?

The first block in the chain. It has no parent, so its previous-hash field is all zeros.

Why are hash functions called compression functions and digests?

They map input of any length to a short fixed-length output. The output is usually much smaller than the input, so it compresses it, and it is a small summary of the data, so it is a digest.

State the four properties of a hash function from the slides.

Fixed length output, efficiency of operation, one-way function, collision resistance.

How is a digital signature created and verified?

The signer hashes the message and encrypts the hash with the private key. The verifier hashes the received message, decrypts the signature with the public key, and checks the two hashes match.

What is Proof of Work?

Finding a nonce so that the hash of the block header is below a predefined target. It is hard to find (about 20.6 quadrillion tries) but easy for anyone to check.

What is the current block reward and when does it change?

3.125 BTC. It halves every 210,000 blocks, about every 4 years.

Why does editing an old block break the chain?

The edit changes the block's hash. The next block stores the old hash as its previous hash, so the link no longer matches. The new hash also fails the PoW target, so the attacker must re-mine that block and every block after it.

  • Blockchain is a cryptographically secure, open, distributed ledger; every node keeps and processes a copy.
  • Generations: 1.0 currency, 2.0 smart contracts, 3.0 DApps, 4.0 industry.
  • A block holds previous hash, transactions, nonce and its hash; the genesis block's previous hash is zero.
  • Bitcoin header: version, previous hash, Merkle root, timestamp, target, nonce.
  • Hash properties: fixed length, efficient, one-way, collision resistant; the avalanche effect exposes edits.
  • Digital signature: hash then sign with private key; verify with public key and compare hashes.
  • Proof of Work: find a nonce so hash is at most the target; reward 3.125 BTC, halved every 210,000 blocks.