Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ethereum Virtual Machine

Similar presentations


Presentation on theme: "Ethereum Virtual Machine"— Presentation transcript:

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

2 UTXO Model

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

4 UTXO Model … and multiple outputs

5 UTXO Model pizza order change

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

7 Account Model

8 In the beginning … state time

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

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

11 Chain of Blocks Txn Txn Txn time

12 Chain of States state state state time

13 Block-State Duality Txn Txn Txn state state state time

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

15 Ethereum State Account Address Account State Account Address

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

17 External Account Address {balance}

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

19 Contract Account Address {balance, code, storage}

20 Transaction Creation Submitted by external party

21 Contract Creation Transaction

22 Contract Creation Transaction
Hello World!

23 Contract Creation Transaction
Hello World! code storage

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

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

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

27 EOA to Contract & Vice-Versa
function call function return

28 Contract to Contract Message
function call function return

29 Money, Honey Native currency called Ether not this but this

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

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

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

33 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

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

35 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

36 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

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

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

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

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

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

42 Ethereum Virtual Machine
EVM Code EVM engine

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

44 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

45 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

46 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

47 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

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

49 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

50 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

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

52 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

53 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 …

54 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

55 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

56 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

57

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

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

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

61 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)

62 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.

63

64 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

65


Download ppt "Ethereum Virtual Machine"

Similar presentations


Ads by Google