Ethereum Virtual Machine

Slides:



Advertisements
Similar presentations
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
Advertisements

CS333 / Cutler Amortized Analysis 1 Amortized Analysis The average cost of a sequence of n operations on a given Data Structure. Aggregate Analysis Accounting.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Block Chain 101 May 2017.
Amortized Analysis.
Lesson Objectives Aims Key Words Paging, Segmentation, Virtual Memory
Introduction to Kernel
Introduction to Operating Systems
Jonathan Walpole Computer Science Portland State University
Processes and threads.
CSC 322 Operating Systems Concepts Lecture - 12: by
Operating Systems (CS 340 D)
Mechanism: Limited Direct Execution
Introduction to microprocessor (Continued) Unit 1 Lecture 2
Distributed Systems for Information Systems Management
Introduction of microprocessor
Introduction to Blockchain & Ethereum
Chapter 10 And, Finally... The Stack
Swapping Segmented paging allows us to have non-contiguous allocations
CSI 400/500 Operating Systems Spring 2009
In this lecture Global variables Local variables System stack
Main Memory Management
Operating Systems (CS 340 D)
Chapter 10 The Stack.
Deanonymization of Clients in Bitcoin P2P Network
Introduction to Operating Systems
Lecture 2: Processes Part 1
Java Byte Codes (0xCAFEBABE) cs205: engineering software
MEMORY MANAGEMENT & their issues
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Chapter 9: Virtual Memory
Blockchains (2) slides have been taken from:
CGS 3763 Operating Systems Concepts Spring 2013
Operating Systems.
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Blockchain Alexander Prenta 9/27/2018.
Process Description and Control
GasToken: A Journey Through Blockchain Resource Arbitrage
Lecture 3: Main Memory.
Lecture Topics: 11/1 General Operating System Concepts Processes
Chapter 10 And, Finally... The Stack
Chapter 2: Operating-System Structures
Swagatika (Jazz) Sarangi
Bitcoin & Blockchain Bina Ramamurthy 2/22/2019.
Introduction to Operating Systems
PROCESSES & THREADS ADINA-CLAUDIA STOICA.
Lecture 20: Intro to Transactions & Logging II
Lecture 19b: Intro to Transactions & Logging
CS510 Operating System Foundations
Computer System Overview
Data Structures in Ethereum
Bitcoin Data Structures
Off-Chain Payment Channels
Analysing Vulnerabilities in Smart Contracts
Chapter 2: Operating-System Structures
Solidity Pitfalls and Hazards
A Conceptual Model for Ethereum Blockchain Analytics
Chapter 8 & 9 Main Memory and Virtual Memory
Campbell R. Harvey Duke University and NBER
Blockchain Tech Big Picture
Explore Txs, block, blockchain in Bitcoin
Page Main Memory.
Presentation transcript:

Ethereum Virtual Machine CS1951 L Spring 2019 12 February 2019 Maurice Herlihy Brown University

UTXO Model

A txn can have multiple inputs … UTXO Model A txn can have multiple inputs …

UTXO Model … and multiple outputs

UTXO Model pizza order change

Can also place other conditions on transfer … UTXO Model Can also place other conditions on transfer … “smart contracts”

Account Model

In the beginning … state time

On the first day … Transaction (This happened) state new state time

Not long after … block Transaction (This happened) state new state time

Chain of Blocks Txn Txn Txn time

Chain of States state state state time

Block-State Duality Txn Txn Txn state state state time

My God, it’s full of accounts! Ethereum State My God, it’s full of accounts!

Ethereum State Account Address Account State Account Address

External Account Owned by person or organization Controlled by private keys Holds Ether balance Active agent: transfers Ether, calls contract code

External Account Address {balance}

Contract Account Holds Ether balance Associated with code Passive Agent: Code called by other accounts Code can transfer Ether, call other contracts

Contract Account Address {balance, code, storage}

Transaction Creation Submitted by external party

Contract Creation Transaction

Contract Creation Transaction Hello World!

Contract Creation Transaction Hello World! code storage

Message Call Transaction Run your code with these args Yes sir!

Message Call Transaction Run your code with these args Yes sir!

EOA to EOA Message Here’s the money I owe you thanks! transfer money

EOA to Contract & Vice-Versa function call function return

Contract to Contract Message function call function return

Money, Honey Native currency called Ether not this but this

Gas Caller pays fee for each transaction step Denial of Service attacks expensive

Gas Each step has fixed “gas” fee But gas price in Ether up to caller! Low price means low priority … And vice-versa

Gas If a call runs out of gas … Effects discarded Gas not refunded If a call has leftover gas … Unused gas refunded

Block Gas Limit Bitcoin has limit on block size Ethereum has limit on block gas Block full when transactions’ gas costs reach limit We will see how this can be exploited later

Transaction Fields Gas price Value Gas limit Data Nonce Et cetera To

Transaction Fields Gas price Value Gas limit Data Nonce Et cetera To How much caller pays for gas, In Ether Gas limit Data Nonce Et cetera Miners collect gas fees, prioritize higher prices To Extra-low price may never run

Transaction Fields Gas price Value Gas limit Data Nonce Et cetera To Max gas caller willing to spend Gas limit Data Call aborts if exceeded Nonce Et cetera No refunds! To

Transaction sequence number Transaction Fields Gas price Value Transaction sequence number (from sender) Gas limit Data Nonce Et cetera To

(external or contract) Transaction Fields Gas price Value Gas limit Data Nonce Et cetera destination address (external or contract) To

How much Ether to transfer Transaction Fields Gas price Value Gas limit Data How much Ether to transfer Nonce Et cetera To

function name, args ,etc. … Transaction Fields Gas price Value Gas limit Data Nonce Et cetera Payload: function name, args ,etc. … To

Transaction Fields Gas price Value Gas limit Data Nonce Et cetera To ECDSA signature args ….

Ethereum Virtual Machine EVM Code EVM engine

Ethereum Virtual Machine EVM Code) (immutable) Program Counter Gas Available Stack Memory (volatile) storage (persistent)

Most operations act on stack Types of Instructions Stack operations Load, store No registers Control Flow Most operations act on stack Block Info PUSH1 0x1 PUSH2 0x2 ADD SHA-3 Logging Environment

Types of Instructions Stack operations Load, store Control Flow Local control flow Control Flow Block Info SHA-3 Call other contracts Logging Call system libraries Environment

Types of Instructions Stack operations Load, store Control Flow Various crypto hashes provided Block Info SHA-3 Logging Environment Gas costs too expensive to compute directly

Types of Instructions Stack operations Load, store Control Flow Caller’s address Load, store Control Flow Ether balance Block Info Gas costs SHA-3 Logging Lots more … Environment

Types of Instructions Stack operations Load, store Control Flow Block Info SHA-3 Load and store from non-stack memory Logging Environment

Types of Instructions Stack operations Load, store Control Flow block number Stack operations Load, store and more … Control Flow Block Info SHA-3 Logging 256 latest block hashes block timestamp Environment

communicate with outside world Types of Instructions Stack operations Load, store communicate with outside world Control Flow Block Info SHA-3 Logging Environment Write events to log debug

EVM Stack … All operations act on stack 1024 elements PUSH, POP, COPY, SWAP … 256 bits

EVM Memory … byte-addressable Grows dynamically Gas charged for growth 8 bits 256-bit load 256-bit or 8-bit store byte-addressable Grows dynamically Gas charged for growth

Observation: Storage is Expensive Users need incentive to free up unneeded storage Ethereum give a gas refund for Freeing storage (overwrite with 0s) Destroying contracts This has had unexpected consequences …

Costs 5000 to zero out location Details: Costs 5000 to zero out location 15000 gas added to refund counter At transaction end, … Refund counter added to unused gas (up to half of total gas used) Destroying contracts similar arithmetic

Gas Token GasToken managed by a contract Create GasToken when gas is cheap Token allocates memory Or creates an empty contract Tokens can be transferred, sold, traded

Gas Token When gas prices climb, …. Buy GasTokens Send to contract for destruction Destruction gets gas refund Up to half of contract’s gas costs

Is That Ethical? Negative effects: Uses memory only for speculation Storage, network, etc underpriced GasToken might drive up prices Miners may be worse off

Is That Ethical? Positive Effects Gas-banking service for users Hedge against increases Predictability in face of volatility

Proposal for Rent Storage is forever Cost to system: bytes X time Cost to user: bytes Partial fix: refund for deletion

Proposal for Rent Keep track of: Last block to access data: last_accessed Size in bytes: storage_bytes On store, extra charge of: O((block.number – last_accessed) * storage_bytes)

Proposal for Rent Why would anyone want this? May benefit dapps that use storage for short durations Disk space for a full node may go down This proposal still under discussion.

Ideas we covered in this lecture UTXO versus Account Mode Block-State duality Accounts, External and Contract Ether and Gas Transaction state Ethereum Virtual Machine