Skip to main content

Introduction to Blockchains

Welcome to the Blockchain Summer School! In this lecture, we'll explore the fundamental concepts that make blockchain technology revolutionary.

🎯 Learning Objectives

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

  • Understand what blockchain technology is and why it matters
  • Explain the difference between centralized and decentralized systems
  • Identify the key components of a blockchain
  • Recognize real-world applications of blockchain technology

🏗️ The Software Stack Evolution

Traditional Software Architecture

In traditional software systems, we have a clear hierarchy:

graph TD
A[User Interface] --> B[Application Layer]
B --> C[Database Layer]
C --> D[Operating System]
D --> E[Hardware]

Blockchain Software Stack

Blockchain introduces a new paradigm:

graph TD
A[dApp Interface] --> B[Smart Contracts]
B --> C[Consensus Layer]
C --> D[Network Layer]
D --> E[Blockchain Protocol]

🔄 Centralized vs Decentralized Systems

Centralized Systems

Definition
A **centralized system** has a single point of control and failure.

Examples:

  • Traditional banks
  • Social media platforms
  • Government databases

Characteristics:

  • ✅ Fast and efficient
  • ✅ Easy to maintain
  • ❌ Single point of failure
  • ❌ Requires trust in central authority

Decentralized Systems

Definition
A **decentralized system** distributes control across multiple participants.

Examples:

  • Bitcoin network
  • Ethereum ecosystem
  • IPFS (InterPlanetary File System)

Characteristics:

  • ✅ No single point of failure
  • ✅ Trustless operation
  • ❌ Slower than centralized systems
  • ❌ More complex to coordinate

🧱 What is a Blockchain?

A blockchain is a distributed, immutable ledger that records transactions across a network of computers.

Key Components

Each block contains:

  • Header: Metadata about the block
  • Transactions: List of validated transactions
  • Hash: Unique identifier linking to previous block
// Example block structure
const block = {
header: {
version: "1.0",
previousHash: "0x123...abc",
timestamp: 1640995200,
nonce: 12345
},
transactions: [
{ from: "Alice", to: "Bob", amount: 100 },
{ from: "Bob", to: "Charlie", amount: 50 }
],
hash: "0x456...def"
};

🌍 Real-World Applications

Financial Services

DeFi Revolution
Decentralized Finance (DeFi) is disrupting traditional banking with permissionless financial services.
  • Lending & Borrowing: Aave, Compound
  • Decentralized Exchanges: Uniswap, SushiSwap
  • Stablecoins: USDC, DAI

Digital Identity

  • Self-Sovereign Identity: Users control their own identity data
  • Verifiable Credentials: Tamper-proof digital certificates
  • Privacy-Preserving Authentication: Zero-knowledge proofs

Supply Chain Management

  • Product Traceability: Track goods from source to consumer
  • Counterfeit Prevention: Immutable product records
  • Automated Compliance: Smart contracts enforce regulations

🚀 The Evolution of Blockchains

Blockchain Generations

Bitcoin (2009)

  • Digital currency
  • Proof of Work consensus
  • Limited scripting capabilities

Key Innovation: Decentralized digital money

🔧 Technical Deep Dive

Cryptographic Foundations

Blockchain relies on several cryptographic primitives:

# Example: Creating a digital signature
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import rsa, padding

# Generate key pair
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
)
public_key = private_key.public_key()

# Sign a message
message = b"Hello, Blockchain!"
signature = private_key.sign(
message,
padding.PSS(
mgf=padding.MGF1(hashes.SHA256()),
salt_length=padding.PSS.MAX_LENGTH
),
hashes.SHA256()
)

Hash Functions

Hash functions are crucial for blockchain integrity:

// Example: SHA-256 hashing
const crypto = require('crypto');

function createHash(data) {
return crypto.createHash('sha256').update(data).digest('hex');
}

const blockData = "Block #123: Alice sends 100 BTC to Bob";
const hash = createHash(blockData);
console.log(hash); // Output: 64-character hex string

🎓 Interactive Exercise

Let's create a simple blockchain in JavaScript:

const SHA256 = require('crypto-js/sha256');

class Block {
constructor(timestamp, data, previousHash = '') {
this.timestamp = timestamp;
this.data = data;
this.previousHash = previousHash;
this.hash = this.calculateHash();
this.nonce = 0;
}

calculateHash() {
return SHA256(this.previousHash + this.timestamp + JSON.stringify(this.data) + this.nonce).toString();
}

mineBlock(difficulty) {
while (this.hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")) {
this.nonce++;
this.hash = this.calculateHash();
}
console.log("Block mined: " + this.hash);
}
}

class Blockchain {
constructor() {
this.chain = [this.createGenesisBlock()];
this.difficulty = 2;
}

createGenesisBlock() {
return new Block("01/01/2025", "Genesis Block", "0");
}

getLatestBlock() {
return this.chain[this.chain.length - 1];
}

addBlock(newBlock) {
newBlock.previousHash = this.getLatestBlock().hash;
newBlock.mineBlock(this.difficulty);
this.chain.push(newBlock);
}

isChainValid() {
for (let i = 1; i < this.chain.length; i++) {
const currentBlock = this.chain[i];
const previousBlock = this.chain[i - 1];

if (currentBlock.hash !== currentBlock.calculateHash()) {
return false;
}

if (currentBlock.previousHash !== previousBlock.hash) {
return false;
}
}
return true;
}
}

// Usage example
let myCoin = new Blockchain();
console.log("Mining block 1...");
myCoin.addBlock(new Block("02/01/2025", { amount: 4 }));
console.log("Mining block 2...");
myCoin.addBlock(new Block("02/01/2025", { amount: 10 }));

console.log("Is blockchain valid? " + myCoin.isChainValid());

📚 Further Reading

🎯 Summary

In this lecture, we've covered:

  • ✅ The fundamental concepts of blockchain technology
  • ✅ Differences between centralized and decentralized systems
  • ✅ Key components of blockchain architecture
  • ✅ Real-world applications and use cases
  • ✅ The evolution of blockchain generations
  • ✅ Basic cryptographic foundations
Next Steps
In the next lecture, we'll dive deeper into **Smart Contracts and Virtual Machines**, where you'll learn how to program on the blockchain!

Ready for hands-on practice? Check out the lab exercises to start building your first blockchain application!