Blockchain

Week 3 - Advanced Blockchain Concepts

"Beyond the Basics?"

Week 2: Recap

  • Public Key Cryptography
  • Hash Functions
  • Digital Signatures
  • Consensus Mechanisms

Advanced Blockchain Concepts

  • Different layers of blockchain architecture
  • Explore Ethereum and smart contracts

Layer 0: The Base Network Infrastructure

  • What it is: The foundational network connecting multiple blockchains or enabling interoperability between them.
  • Purpose: Provides the communication, consensus, and cross-chain protocols that allow layer 1 blockchains to exist.
  • Examples: Polkadot, Cosmos, Avalanche(L0/L1) hybrid.
  • Key Role: Network-Level Consensus, Interoperability, Cross-Chain Messaging.

Layer 1: The Base Blockchain

  • What it is: The main blockchain network that processes and validates transactions, executes smart contracts.
  • Purpose: Handles consensus, ledger maintenance, and base smart contract execution.
  • Examples: Bitcoin, Ethereum, Solana, Cardano, Binance Smart Chain.
  • Key Role: Transaction Processing, Smart Contract Execution, Security, Decentralization

Layer 2: Scaling Solutions

  • What it is: Secondary frameworks or protocols built on top of layer 1 blockchains to enhance scalability and efficiency.
  • Purpose: Offloads transactions from the main chain to reduce congestion and improve speed.
  • Examples: Lightning Network (Bitcoin), Optimistic Rollups, zk-Rollups (Ethereum), Polygon.
  • Key Role: Transaction Throughput, Reduced Latency, Lower Fees, Scalability without sacrificing L1 security.

Layer 3: Application/Service Layer

  • What it is: Sometimes called application layer, it's a layer that builds on L2s or L1s to offer specialized services or platforms.
  • Purpose: Abstracts the complexity of L1/L2, often offering custom logic, modular chains, or enterprise solutions.
  • Examples: Decentralized applications (dApps), DeFi platforms, NFT marketplaces, DAOs.
  • Key Role: User Interaction, Specialized Services, Custom Logic, Enhanced Functionality

Quick Analogy

  • Layer 0: The roads and highways connecting cities (blockchains).
  • Layer 1: The city itself (Ethereum, Solana).
  • Layer 2: Express lanes or bypasses built to reduce congestion in the city.
  • Layer 3: Businesses and apps in the city that use those roads to operate efficiently.

Ethereum and Smart Contracts

Programmable Blockchain and Open World Computer

Ethereum Overview

  • Launched in 2015 by Vitalik Buterin (was 19 at the time)
  • Unlike Bitcoin (digital money only), Ethereum is:
    • Programmable
    • Runs smart contracts (we’ll get to that!)
    • Base for DApps (Decentralized Applications)
      Think of it like:
  • Bitcoin = Calculator
  • Ethereum = Entire Laptop

Ethereum Architecture

  • EVM (Ethereum Virtual Machine):
    Runs all the code, like a global computer.
  • Accounts:
    • EOA (Externally Owned Account) → humans with wallets
    • Contract Account → smart contracts with code
  • Gas:
    • Every transaction costs gas
    • Paid in ETH
    • Like Uber: “you can go anywhere, but you gotta pay the ride” 🚕

Consensus Mechanism

  • Ethereum originally: Proof of Work (like Bitcoin)
  • Now (after The Merge, Sept 2022): Proof of Stake
    • Validators stake ETH
    • Randomly chosen to propose blocks
    • Misbehave → get slashed
      Why?
  • Environment-friendly
  • Faster and more secure

Ethereum Ecosystem

  • Wallets → MetaMask, Rainbow, Coinbase Wallet
  • DeFi (Decentralized Finance) → lending, trading without banks
  • NFTs → art, music, even memes
  • DAOs → internet-native organizations
  • Gaming → in-game items as real assets

Scalability Solutions

Ethereum today = slow & expensive sometimes

  • Solutions:
    • Layer 2 Rollups (Arbitrum, Optimism, zkSync)
    • Sidechains (Polygon, Gnosis)
    • Sharding (coming in upgrades!)
  • Think of it like:
    • Ethereum = the main city
    • Layer 2s = suburbs with faster traffic

Why Ethereum Matters

  • The backbone of Web3
  • Enables permissionless innovation
  • Powers billions in:
    • Finance
    • Art
    • Governance
    • Social media

Ethereum is not just money—it’s a new trust layer for the internet.

Recap

  • Ethereum = a global programmable blockchain
  • Runs on the EVM
  • Uses Proof of Stake consensus
  • Hosts DeFi, NFTs, DAOs, and more
  • Scaling fast with Layer 2s

Smart Contracts: The Code of Web3

If Ethereum is the laptop, Smart Contracts are the apps.

What is a Smart Contract?

  • A program stored on the blockchain
  • Executes automatically when conditions are met
  • Cannot be changed once deployed
  • Lives forever… even if you regret writing it 😬

Think of it as:

  • A vending machine
    → You put coins, it gives you snacks.
    → No cashier, no trust issues.

Anatomy of a Smart Contract

  • State Variables → store data (like account balances)
  • Functions → rules of interaction
  • Events → logs that tell the outside world what happened
  • Modifiers → extra checks on functions (like “onlyOwner”)

Example:

uint public count;
function increment() public {
    count++;
}

Solidity Basics

Solidity = programming language for Ethereum

  • Versioning matters -> pragma solidity ^0.8.20;
  • Common types:
    • uint, int, address, bool, string
    • mapping, struct, array
  • Functions can be public, private, internal, external
  • Smart Contracts are public by default.
  • It's like open-source, but everyone must see your code.

Contract Lifecycle

  1. Write the contract in Solidity
  2. Compile it to bytecode
  3. Deploy it to the Ethereum network (costs gas)
  4. Interact with it via transactions
  5. Upgrade (if designed for it, using proxies)

Once deployed, it's permanent.

Security Concerns

Smart contracts handle real money, so bugs = disasters.

Rule #1 of Web3:

  • Don't trust the code. Audit the code.

Tools of the Trade

  • Remix IDE → browser-based Solidity editor
  • Truffle/Hardhat → frameworks for building/testing
  • Ethers.js/Web3.js → libraries to interact with Ethereum
  • OpenZeppelin → secure contract templates
  • Foundry -> rust-style, super fast

Wallets for interaction:

  • MetaMask, Rainbow, Coinbase Wallet
  • WalletConnect for mobile

Real World Use Cases

  • DeFi: Uniswap, Aave, Compound
  • NFTs: CryptoPunks, Bored Ape Yacht Club
  • DAOs: MakerDAO, Aragon
  • Gaming: Axie Infinity, Decentraland
  • Supply Chain: Provenance, VeChain
  • Identity: uPort, Civic