Blockchain basics
Core Questions & Concepts
1. What is Blockchain and How Does It Work?
Blockchain is a distributed, immutable ledger that stores data in cryptographically linked blocks.
Key Components:
- Block Structure: Index, Timestamp, Data, Previous Hash, Hash, Nonce
- Chain Linking: Each block references the previous block’s hash
- Cryptographic Hashing: SHA-256 ensures data integrity
- Immutability: Changing any block breaks the entire chain
How Blocks Connect:
[Genesis Block] → [Block 1] → [Block 2] → [Block 3]
Hash: abc123 Hash: def456 Hash: ghi789 Hash: jkl012
Prev: abc123 Prev: def456 Prev: ghi789
2. How Does Mining Work?
Mining is finding a special number (nonce) that makes the block’s hash start with zeros.
Process:
- Create block with transaction data
- Try different nonce values (0, 1, 2, 3…)
- Calculate hash for each nonce
- Stop when hash starts with required zeros (e.g., “00abc123…”)
Example:
Nonce = 0: Hash = "f4ca89..." ❌
Nonce = 1: Hash = "8b2d1a..." ❌
Nonce = 47: Hash = "3c8af2..." ❌
Nonce = 48: Hash = "00d4e8..." ✅ Found it!
Why Mine?
- Proof of Work: Proves computational effort was spent
- Spam Prevention: Makes adding blocks costly
- Security: To change history, must re-mine all subsequent blocks
Difficulty Levels:
- Difficulty 1: Find “0…” (~16 attempts)
- Difficulty 2: Find “00…” (~256 attempts)
- Difficulty 3: Find “000…” (~4,096 attempts)
3. Consensus Mechanisms Comparison
Proof of Work (PoW)
- How: Miners compete to solve puzzles
- Selection: Fastest miner wins
- Energy: High (computational puzzles)
- Examples: Bitcoin, our demo
- Pros: Decentralized, anyone can participate
- Cons: Slow, energy intensive
Proof of Stake (PoS)
- How: Validators chosen by stake amount
- Selection: Higher stake = higher chance
- Energy: Low (no mining)
- Examples: Ethereum 2.0, Cardano
- Pros: Fast, energy efficient
- Cons: Rich get richer, initial distribution
Proof of Authority (PoA)
- How: Pre-approved validators take turns
- Selection: Round-robin or scheduled
- Energy: Very low (no competition)
- Examples: Private networks, consortium blockchains
- Pros: Very fast, predictable
- Cons: Centralized, requires trust
4. Validator Economics in PoS
Why Validators Get Paid:
- Run servers 24/7 (costs money)
- Risk their stake (could lose it)
- Verify transactions (takes resources)
- Maintain network (ensure availability)
How They Earn:
- Block Rewards: New coins created (e.g., 2 ETH per block)
- Transaction Fees: Users pay for inclusion (e.g., 0.5 ETH fee)
- Annual Yield: ~4-5% on staked amount
Risk vs Reward:
Honest Behavior: +5% yearly rewards
Dishonest Behavior: -50% to -100% stake loss
Why Dishonesty Fails:
- Cryptographic signatures prove who did what
- Evidence is permanent on blockchain
- Other validators can report violations
- Economic loss always exceeds potential gain
5. Blockchain as Database
Traditional Database vs Blockchain:
Traditional DB | Blockchain |
---|---|
Can UPDATE/DELETE | Only INSERT (append) |
Central control | Distributed copies |
Fast queries | Sequential reads |
Mutable history | Immutable history |
Storage Methods:
- In Memory: Temporary (lost when program stops)
- File Storage: JSON, binary files
- Specialized DBs: LevelDB (Bitcoin), BadgerDB
- Hybrid: SQL indexes + blockchain data
Real Examples:
- Bitcoin: ~500GB (LevelDB + flat files)
- Ethereum: ~1TB+ (LevelDB + state tries)
- Our Demo: ~50MB for 10,000 votes
6. Joining a Blockchain Network
The Challenge: New validators need all history from genesis block.
Sync Strategies:
Full Sync
- Download everything since genesis
- Time: Days/weeks
- Storage: 500GB+
- Security: Maximum
Checkpoint Sync
- Start from trusted recent state
- Time: Hours
- Storage: 1-10GB
- Security: High
Light Sync
- Only download block headers
- Time: Minutes
- Storage: <100MB
- Security: Medium (trust others for data)
Trade-offs:
Full Sync: Maximum security, very slow
Checkpoint: Good security, fast
Light: Basic security, very fast
7. Multi-Worker Network Dynamics
How Multiple Workers Collaborate:
- Competition: All workers try to mine each block
- Winner Takes All: Fastest miner gets the block
- Propagation: Winner broadcasts to network
- Validation: Others verify and accept/reject
- Consensus: Network converges on longest valid chain
Network Characteristics:
- Mining Power: Affects winning probability
- Network Delay: Geographic/connection differences
- Automatic Consensus: No central coordinator needed
- Fault Tolerance: Works despite failures/partitions
Key Insights for Voting Systems
Why Blockchain for Voting?
- Immutable: Votes cannot be changed after casting
- Transparent: Anyone can verify the blockchain
- Decentralized: No single point of control/failure
- Auditable: Complete history of all actions
- Tamper-Proof: Changing past requires enormous effort
Security Benefits:
- Vote Integrity: Cryptographic hashing prevents tampering
- No Double Voting: System prevents duplicate votes
- Transparent Counting: Results mathematically verifiable
- Audit Trail: Every action permanently recorded
Real-World Implementation:
- Small Elections: Full sync acceptable
- Large Elections: Checkpoint sync needed
- Massive Scale: Light nodes + proof systems
- Hybrid Approach: Combine multiple consensus mechanisms
This summary covers the fundamental blockchain concepts learned through building a practical voting system implementation in Go.