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
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
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
- Blocks
- Chain
- Consensus
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"
};
Blocks are linked together in a chain:
graph LR
A[Block 1] --> B[Block 2]
B --> C[Block 3]
C --> D[Block 4]
D --> E[Block N]
Each block references the previous block's hash, creating an immutable chain.
Consensus mechanisms ensure all participants agree on the state:
- Proof of Work (PoW): Bitcoin, early Ethereum
- Proof of Stake (PoS): Ethereum 2.0, Cardano
- Delegated Proof of Stake (DPoS): EOS, Tron
🌍 Real-World Applications
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
- Generation 1
- Generation 2
- Generation 3
Bitcoin (2009)
- Digital currency
- Proof of Work consensus
- Limited scripting capabilities
Key Innovation: Decentralized digital money
Ethereum (2015)
- Smart contracts
- Turing-complete programming
- dApp platform
Key Innovation: Programmable blockchain
Modern Blockchains
- Scalability solutions
- Cross-chain interoperability
- Advanced consensus mechanisms
Key Innovation: Enterprise-ready infrastructure
🔧 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
- Bitcoin Whitepaper - Satoshi Nakamoto
- Ethereum Whitepaper - Vitalik Buterin
- Mastering Bitcoin - Andreas Antonopoulos
🎯 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
Ready for hands-on practice? Check out the lab exercises to start building your first blockchain application!