Lecture 2: Ethereum Basics
Instructor: Yu Feng, UCSB
CS190: Blockchain Programming and Applications
Understanding Ethereum as a decentralized world computer and its fundamental differences from Bitcoin's payment-focused design.
Bitcoin's Design Philosophy
Peer-to-Peer Electronic Cash
Bitcoin was designed as a digital currency system that eliminates the need for trusted third parties in financial transactions.
Reference
Nakamoto, S. (2008). Bitcoin: A Peer-to-Peer Electronic Cash System. Retrieved from unknown link
Bitcoin's Design Philosophy
UTXO Model
Unspent Transaction Outputs track discrete coin ownership, similar to physical cash where you can't partially spend a bill.
Bitcoin's Design Philosophy
Restricted Script Language
Bitcoin's scripting system is intentionally limited, focusing on simple payment conditions rather than complex computations.
Bitcoin's Design Philosophy
Proof of Work Consensus
Mining provides security through computational work, making it expensive to attack the network.
The Limits of Bitcoin's Architecture
Bitcoin's Constraints
Bitcoin's design prioritizes security and simplicity over programmability. The system is stateless, meaning there's no global account balance - only unspent outputs. The Script language deliberately excludes loops and persistent storage to prevent infinite execution and maintain predictable resource consumption.
  • No global state or account balances
  • Script language without loops or storage
  • Limited to payment-focused applications
  • Cannot build complex decentralized applications
What This Enables vs. Limits
What Bitcoin Can Do
  • Secure peer-to-peer payments
  • Multi-signature transactions
  • Time-locked payments
  • Basic escrow conditions
What It Cannot Do
  • Complex smart contracts
  • Decentralized applications
  • Persistent data storage
  • Advanced programmable logic
Ethereum's Revolutionary Vision
In 2013, 19-year-old Vitalik Buterin proposed a radical expansion of blockchain technology beyond simple payments. Instead of just a ledger, what if we could build a decentralized computer that anyone could use?
01
World Computer Concept
Ethereum reimagines blockchain as a global, decentralized computing platform where anyone can deploy and run applications without central control.
02
Ethereum Virtual Machine (EVM)
A Turing-complete virtual machine that can execute any computation, unlike Bitcoin's limited scripting capabilities.
03
Smart Contracts & dApps
Self-executing programs that run exactly as programmed, enabling decentralized applications from finance to gaming.
Buterin, V. (2013). ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER.
Ethereum as a Global State Machine
Unlike Bitcoin's stateless design, Ethereum maintains a global state - a complete snapshot of all account balances, contract storage, and code at any given moment.
1
Current State
The complete snapshot of all accounts, balances, and smart contract storage at block height N.
2
Transaction Processing
Each transaction modifies the global state according to predefined rules and smart contract logic.
3
New State
The updated global state at block height N+1, reflecting all processed transactions.
Every Ethereum node maintains an identical copy of this state machine. When transactions are processed, the state transitions deterministically - meaning every node will compute the exact same new state given the same inputs.
Key Insight: This global state enables complex applications because smart contracts can store data persistently and interact with each other's state.
Accounts vs UTXO: Two Fundamentally Different Models
🪙 UTXO: "Coins in Your Pocket"
Like physical cash, you either have specific coins or you don't. Each UTXO is discrete and independent.
🏦 Accounts: "Bank Ledger"
Like a bank account with a running balance that can be updated by various operations.
Two Types of Ethereum Accounts
Ethereum distinguishes between two fundamentally different types of accounts, each with distinct capabilities and purposes.
Externally Owned Accounts (EOAs)
  • Controlled by private keys
  • Can initiate transactions
  • No code execution capability
  • Used by human users and wallets
  • Has nonce, balance, but no code
Contract Accounts
  • Controlled by smart contract code
  • Cannot initiate transactions
  • Reactive - only responds to calls
  • Contains executable bytecode
  • Has storage for persistent data
This separation creates a clear distinction between user-controlled accounts and autonomous smart contracts, enabling complex decentralized applications while maintaining security.
Account Anatomy: The Four Essential Fields
Every Ethereum account, whether EOA or contract, contains exactly four pieces of information that define its state.
Nonce
For EOAs: transaction counter preventing replay attacks. For contracts: number of contracts created.
Balance
Amount of Ether (in wei) owned by this account. Even contracts can hold Ether.
CodeHash
Hash of the account's code. For EOAs, this is empty. For contracts, it points to executable bytecode.
StorageRoot
Root hash of the account's storage trie. Contains persistent data for smart contracts.

Technical Note: The storage trie allows contracts to store arbitrary key-value pairs efficiently, enabling complex data structures like mappings and arrays.
These four fields completely define an account's state and are stored in Ethereum's global state trie, enabling the network to track all accounts efficiently.
What is an Ethereum Transaction?
A transaction is a cryptographically signed instruction from an externally owned account (EOA) that triggers a state change in the Ethereum network.
01
Transaction Creation
An EOA creates and signs a transaction with their private key, specifying the desired operation.
02
Network Propagation
The signed transaction is broadcast to the Ethereum network and enters the mempool waiting for inclusion.
03
Validation & Execution
Miners/validators verify the transaction signature and execute it, updating the global state accordingly.
Transactions can accomplish three main purposes:
  • Transfer Ether: Send ETH from one account to another
  • Call Contract Functions: Execute code in existing smart contracts
  • Deploy Contracts: Create new smart contracts on the network

Important: Only EOAs can initiate transactions. Smart contracts can only react to incoming transactions or calls from other contracts.
Transaction Fields: The Complete Structure
Every Ethereum transaction contains specific fields that define its behavior and resource consumption. Understanding these fields is crucial for blockchain programming.
These fields work together to ensure transactions are secure, properly priced, and resource-bounded.
Three Types of Ethereum Transactions
Ethereum transactions fall into three distinct categories, each serving different purposes in the ecosystem.
💸 Simple Transfer
  • to: recipient address
  • value: ETH amount
  • data: empty
Transfers Ether from one EOA to another, similar to a bank wire transfer.
⚙️ Contract Call
  • to: contract address
  • value: ETH (optional)
  • data: function call
Executes a function in an existing smart contract, potentially changing contract state.
🏗️ Contract Deployment
  • to: empty (null)
  • value: ETH (optional)
  • data: bytecode
Creates a new smart contract by deploying bytecode to the network.
Each type requires different gas amounts and has different implications for network state changes.
Why Gas Exists: Solving the Halting Problem
Gas is Ethereum's solution to a fundamental computer science problem: how do you run arbitrary code without risking infinite loops that could freeze the entire network?
The Halting Problem
It's mathematically impossible to determine if an arbitrary program will halt or run forever. Without limits, malicious code could freeze Ethereum nodes.
Gas as Resource Metering
Every operation consumes a predetermined amount of gas. When gas runs out, execution stops immediately, preventing infinite loops.
Network Protection
Gas ensures computational resources are fairly distributed and prevents denial-of-service attacks through resource exhaustion.

Key Principle: Gas makes computation costly, ensuring only valuable operations are executed on the global computer.
How Gas Works: Metering Execution
Gas operates like fuel in a car - each operation consumes a specific amount, and when you run out, execution stops immediately.
1
Transaction Starts
User pays upfront for gasLimit × maxFeePerGas, creating a gas budget for execution.
2
Operations Execute
Each EVM instruction consumes predetermined gas: ADD (3), STORE (20,000), etc.
3
Gas Exhausted
If gas runs out mid-execution, the transaction reverts but gas fees are still consumed.
Common Gas Costs
  • Basic operations: 3-5 gas (ADD, MUL)
  • Memory operations: 3-200 gas
  • Storage write: 20,000 gas
  • Contract creation: 32,000 gas

Gas Refunds: Some operations like freeing storage can provide partial gas refunds, incentivizing efficient code.
EIP-1559: The Modern Fee Market
Ethereum Improvement Proposal 1559 revolutionized how transaction fees work, introducing a more predictable and efficient fee structure.
1
Base Fee
Network-determined fee that adjusts based on block fullness. This portion gets burned, reducing ETH supply.
2
Priority Fee (Tip)
User-set tip to incentivize miners/validators to include the transaction quickly.
3
Total Fee
GasUsed × (BaseFee + PriorityFee) determines the final transaction cost.
Fee Calculation Formula:
Total Fee = Gas Used × (Base Fee + Priority Fee) Max Fee = Gas Limit × Max Fee Per Gas
This mechanism makes fees more predictable while creating deflationary pressure on ETH through base fee burning.
Key Takeaways
Understanding these fundamental concepts is essential for blockchain programming and building decentralized applications.
1
Bitcoin vs Ethereum Philosophy
Bitcoin prioritizes security and simplicity as digital cash, while Ethereum embraces complexity to enable programmable money and decentralized computing.
2
Ethereum's Account Model
The account-based system with persistent state enables sophisticated smart contracts but requires careful gas management to prevent resource abuse.
3
Gas: Safety and Fairness
Gas serves dual purposes - protecting the network from infinite loops while ensuring computational resources are fairly allocated and compensated.

Remember: These architectural decisions create trade-offs. Ethereum's flexibility comes at the cost of complexity, while Bitcoin's simplicity limits its programmability.
Preview: Next Lecture
Now that you understand Ethereum's architecture, we'll dive into actually programming smart contracts.
01
Solidity Programming Basics
Learn the syntax and patterns of Ethereum's primary smart contract language, including data types, functions, and control structures.
02
Development Environment Setup
Configure your local development environment with tools like Hardhat, MetaMask, and test networks.
03
Lab: "Hello World" Contract
Deploy your first smart contract to a test network and interact with it through transactions.
Come prepared with:
  • Node.js installed on your development machine
  • A code editor (VS Code recommended)
  • MetaMask browser extension configured
Get ready to write code that runs on the world computer!