DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
THE WORLD
COMPUTER
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
"IBM System 360 tape drives" by Erik Pitti from San Diego, CA, USA - IBM System/360 MainframeUploaded by Mewtu. Licensed under CC BY 2.0 via Wikimedia Commons -
https://commons.wikimedia.org/wiki/File:IBM_System_360_tape_drives.jpg#/media/File:IBM_System_360_tape_drives.jpg
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
The computer that
anyone can program and
everyone can trust
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
A planetary-scale
virtual machine:
Trusted Computation and
Storage Service Platform
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Peer-to-peer network:
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Peer-to-peer network:
Robust to connection problems and attacks
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Peer-to-peer network:
New connections can be made to repair connectivity
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Intrinsic features include:
Cryptographic Identity Checking and Custom Payment Logic
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Three classes of instruction:
1. Create a new Contract (program)
2. Execute a Function of a specific Contract
3. Transfer ether
Cryptographically Signed Instructions
State Data
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum Contracts are
EVM code + Persistent Storage
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum Contracts are
EVM code + Persistent Storage
Ethereum
Virtual
Machine
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Every time a contract execution is initiated:
A fresh new VM singleton is instantiated
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Every time a contract execution is initiated:
A fresh new VM singleton is instantiated
The contract's code is loaded into ROM
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Every time a contract execution is initiated:
A fresh new VM singleton is instantiated
The contract's code is loaded into ROM
The contract's storage is loaded into RAM
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Every time a contract execution is initiated:
A fresh new VM singleton is instantiated
The contract's code is loaded into ROM
The contract's storage is loaded into RAM
A usual raft of VM components are initialized:
PC, memory, stack, message data, etc
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
EVM opcodes are tailored to Ethereum's specific set-up:
0x00: STOP
0x01: ADD
0x02: MUL
0x03: SUB
0x04: DIV
0x05: SDIV
0x06: MOD
0x07: SMOD
0x08: ADDMOD
0x09: MULMOD
0x0A: EXP
0x0B: SIGNEDEXTEND
0x10: LT
0x11: GT
0x12: SLT
0x13: SGT
0x14: EQ
0x15: ISZERO
0x16: AND
0x17: OR
0x18: XOR
0x19: NOT
0x1A: BYTE
0x20: SHA3
0x30: ADDRESS
0x31: BALANCE
0x32: ORIGIN
0x33: CALLER
0x34: CALLVALUE
0x35: CALLDATALOAD
0x36: CALLDATASIZE
0x37: CALLDATACOPY
0x38: CODESIZE
0x39: CODECOPY
0x3A: GASPRICE
0x3B: EXTCODESIZE
0x3C: EXTCODECOPY
0x40: BLOCKHASH
0x00: STOP
0x01: ADD
0x02: MUL
0x03: SUB
0x04: DIV
0x05: SDIV
0x06: MOD
0x07: SMOD
0x08: ADDMOD
0x09: MULMOD
0x0A: EXP
0x0B: SIGNEDEXTEND
0x10: LT
0x11: GT
0x12: SLT
0x13: SGT
0x14: EQ
0x15: ISZERO
0x16: AND
0x41: COINBASE
0x42: TIMESTAMP
0x43: NUMBER
0x44: DIFFICULTY
0x45: GASLIMIT
0x50: POP
0x51: MLOAD
0x52: MSTORE
0x53: MSTORE8
0x54: SLOAD
0x55: SSTORE
0x56: JUMP
0x57: JUMPI
0x58: PC
0x59: MSIZE
0x5A: GAS
0x5B: JUMPDEST
0x6X: PUSHX
0xF0: CREATE
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Many tools and several compilers have
been created to help write Ethereum
contracts to skip the need to code in
assembler.
Today I will focus on the Solidity programming
language, which can be compiled using:
the solc executable
online at https://chriseth.github.io/browser-solidity
using the geth javascript console
implicitly in the alethzero/alethone GUI or
intrinsically in the Mix IDE
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Make money at home – create your own currency
contract token {
mapping (address => uint) public coinBalanceOf;
event CoinTransfer(address sender, address receiver, uint amount);
/* Initializes contract with initial supply tokens to the creator of the contract *
function token(uint supply) {
coinBalanceOf[msg.sender] = (supply || 10000);
}
/* Very simple trade function */
function sendCoin(address receiver, uint amount) returns(bool sufficient) {
if (coinBalanceOf[msg.sender] < amount) return false;
coinBalanceOf[msg.sender] -= amount;
coinBalanceOf[receiver] += amount;
CoinTransfer(msg.sender, receiver, amount);
return true;
}
} Code example by
Alex Van De Sande
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Cryptographically Signed Instructions
State Data
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum
“daemon”
Instructions
State Data
ÐΞVp2p
Ethereum
Interface
Instructions
State Data
JSON RPC
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum
“daemon”
Instructions
State Data
ÐΞVp2p
Ethereum
Interface
Instructions
State Data
JSON RPC
Ideally: local machine via http
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum
“daemon”
Instructions
State Data
ÐΞVp2p
Ethereum
Interface
Instructions
State Data
JSON RPC
Web browser
(e.g. Mist)
Alethzero/Alethone
Eth (C++)
Geth (Go)
Pythereum (Python)
Also: Java, Javascript, Haskell …
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
JSON RPC example:
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":
["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"],"id":1}'
// Result
{
"id":1,
"jsonrpc": "2.0",
"result": "0x0234c8a3397aab58" // 158972490234375000
}
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Problem:
If anyone can upload contracts and anyone can have them be
executed, DDOSing the network becomes trivial.
Solution:
Anti-spam payment token required for running contract code.
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Problem:
If anyone can upload contracts and anyone can have them be
executed, DDOSing the network becomes trivial.
Solution:
Anti-spam payment token required for running contract code.
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ether buys GAS to fuel the EVM
Every opcode instruction executed by the EVM uses up Gas.
https://openclipart.org/detail/83173/tsdpetrol-pump
MUL
ADD
SHA3
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ether buys GAS to fuel the EVM
Every opcode instruction executed by the EVM uses up Gas.
If the VM instance runs out of Gas then execution stops.
https://openclipart.org/detail/226524/fuel-gauge
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ether buys GAS to fuel the EVM
An amount of Gas is bought using ether when the instruction to
execute a contract's code is accepted by the Ethereum network,
and given to the VM that is created to fulfill the instruction.
Only if execution completes successfully are the effects of
the execution saved.
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Transfer Funds
Run Contract
New Contract
CLIENTS
balances statestaten-1
staten
TransactionPool
PoW
balances state
verify
execute
select
ProcessList
gas
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
CLIENTS
Transaction
Pool
UTXOsblockn-1
UTXOsblockn
select
Classic Blockchains
verify
PoW
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum is explicitly state-based
Blocks record state-updates.
This makes efficiencies, such as state-pruning, much
easier and more effective.
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
So what is Ethereum good for?
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Taxi image: www.nyc.gov
Businessman image: openclipart.org/detail/19483/businessman-on-phone
Dollar sign: openclipart.org/detail/167795/money-20
Location marker: openclipart.org/detail/166612/google-places
Example: taxi escrow contract
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Taxi Escrow Taxi Escrow Taxi Escrow
Example: taxi escrow contract
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
Taxi Escrow Taxi Escrow Taxi Escrow
Example: taxi escrow contract
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0
THE WORLD
COMPUTER
DEVIEW 2015-09-15 aeron.buchanan@ethereum.org Aeron Buchanan, V1, CC BY-SA 3.0

[213] ethereum

  • 1.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 THE WORLD COMPUTER
  • 2.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 "IBM System 360 tape drives" by Erik Pitti from San Diego, CA, USA - IBM System/360 MainframeUploaded by Mewtu. Licensed under CC BY 2.0 via Wikimedia Commons - https://commons.wikimedia.org/wiki/File:IBM_System_360_tape_drives.jpg#/media/File:IBM_System_360_tape_drives.jpg
  • 3.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 The computer that anyone can program and everyone can trust
  • 4.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 A planetary-scale virtual machine: Trusted Computation and Storage Service Platform
  • 5.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Peer-to-peer network:
  • 6.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Peer-to-peer network: Robust to connection problems and attacks
  • 7.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Peer-to-peer network: New connections can be made to repair connectivity
  • 8.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Intrinsic features include: Cryptographic Identity Checking and Custom Payment Logic
  • 9.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Three classes of instruction: 1. Create a new Contract (program) 2. Execute a Function of a specific Contract 3. Transfer ether Cryptographically Signed Instructions State Data
  • 10.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ethereum Contracts are EVM code + Persistent Storage
  • 11.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ethereum Contracts are EVM code + Persistent Storage Ethereum Virtual Machine
  • 12.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Every time a contract execution is initiated: A fresh new VM singleton is instantiated
  • 13.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Every time a contract execution is initiated: A fresh new VM singleton is instantiated The contract's code is loaded into ROM
  • 14.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Every time a contract execution is initiated: A fresh new VM singleton is instantiated The contract's code is loaded into ROM The contract's storage is loaded into RAM
  • 15.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Every time a contract execution is initiated: A fresh new VM singleton is instantiated The contract's code is loaded into ROM The contract's storage is loaded into RAM A usual raft of VM components are initialized: PC, memory, stack, message data, etc
  • 16.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 EVM opcodes are tailored to Ethereum's specific set-up: 0x00: STOP 0x01: ADD 0x02: MUL 0x03: SUB 0x04: DIV 0x05: SDIV 0x06: MOD 0x07: SMOD 0x08: ADDMOD 0x09: MULMOD 0x0A: EXP 0x0B: SIGNEDEXTEND 0x10: LT 0x11: GT 0x12: SLT 0x13: SGT 0x14: EQ 0x15: ISZERO 0x16: AND 0x17: OR 0x18: XOR 0x19: NOT 0x1A: BYTE 0x20: SHA3 0x30: ADDRESS 0x31: BALANCE 0x32: ORIGIN 0x33: CALLER 0x34: CALLVALUE 0x35: CALLDATALOAD 0x36: CALLDATASIZE 0x37: CALLDATACOPY 0x38: CODESIZE 0x39: CODECOPY 0x3A: GASPRICE 0x3B: EXTCODESIZE 0x3C: EXTCODECOPY 0x40: BLOCKHASH 0x00: STOP 0x01: ADD 0x02: MUL 0x03: SUB 0x04: DIV 0x05: SDIV 0x06: MOD 0x07: SMOD 0x08: ADDMOD 0x09: MULMOD 0x0A: EXP 0x0B: SIGNEDEXTEND 0x10: LT 0x11: GT 0x12: SLT 0x13: SGT 0x14: EQ 0x15: ISZERO 0x16: AND 0x41: COINBASE 0x42: TIMESTAMP 0x43: NUMBER 0x44: DIFFICULTY 0x45: GASLIMIT 0x50: POP 0x51: MLOAD 0x52: MSTORE 0x53: MSTORE8 0x54: SLOAD 0x55: SSTORE 0x56: JUMP 0x57: JUMPI 0x58: PC 0x59: MSIZE 0x5A: GAS 0x5B: JUMPDEST 0x6X: PUSHX 0xF0: CREATE
  • 17.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Many tools and several compilers have been created to help write Ethereum contracts to skip the need to code in assembler. Today I will focus on the Solidity programming language, which can be compiled using: the solc executable online at https://chriseth.github.io/browser-solidity using the geth javascript console implicitly in the alethzero/alethone GUI or intrinsically in the Mix IDE
  • 18.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Make money at home – create your own currency contract token { mapping (address => uint) public coinBalanceOf; event CoinTransfer(address sender, address receiver, uint amount); /* Initializes contract with initial supply tokens to the creator of the contract * function token(uint supply) { coinBalanceOf[msg.sender] = (supply || 10000); } /* Very simple trade function */ function sendCoin(address receiver, uint amount) returns(bool sufficient) { if (coinBalanceOf[msg.sender] < amount) return false; coinBalanceOf[msg.sender] -= amount; coinBalanceOf[receiver] += amount; CoinTransfer(msg.sender, receiver, amount); return true; } } Code example by Alex Van De Sande
  • 19.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Cryptographically Signed Instructions State Data
  • 20.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ethereum “daemon” Instructions State Data ÐΞVp2p Ethereum Interface Instructions State Data JSON RPC
  • 21.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ethereum “daemon” Instructions State Data ÐΞVp2p Ethereum Interface Instructions State Data JSON RPC Ideally: local machine via http
  • 22.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ethereum “daemon” Instructions State Data ÐΞVp2p Ethereum Interface Instructions State Data JSON RPC Web browser (e.g. Mist) Alethzero/Alethone Eth (C++) Geth (Go) Pythereum (Python) Also: Java, Javascript, Haskell …
  • 23.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 JSON RPC example: // Request curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params": ["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"],"id":1}' // Result { "id":1, "jsonrpc": "2.0", "result": "0x0234c8a3397aab58" // 158972490234375000 }
  • 24.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Problem: If anyone can upload contracts and anyone can have them be executed, DDOSing the network becomes trivial. Solution: Anti-spam payment token required for running contract code.
  • 25.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Problem: If anyone can upload contracts and anyone can have them be executed, DDOSing the network becomes trivial. Solution: Anti-spam payment token required for running contract code.
  • 26.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ether buys GAS to fuel the EVM Every opcode instruction executed by the EVM uses up Gas. https://openclipart.org/detail/83173/tsdpetrol-pump MUL ADD SHA3
  • 27.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ether buys GAS to fuel the EVM Every opcode instruction executed by the EVM uses up Gas. If the VM instance runs out of Gas then execution stops. https://openclipart.org/detail/226524/fuel-gauge
  • 28.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ether buys GAS to fuel the EVM An amount of Gas is bought using ether when the instruction to execute a contract's code is accepted by the Ethereum network, and given to the VM that is created to fulfill the instruction. Only if execution completes successfully are the effects of the execution saved.
  • 29.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Transfer Funds Run Contract New Contract CLIENTS balances statestaten-1 staten TransactionPool PoW balances state verify execute select ProcessList gas
  • 30.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 CLIENTS Transaction Pool UTXOsblockn-1 UTXOsblockn select Classic Blockchains verify PoW
  • 31.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Ethereum is explicitly state-based Blocks record state-updates. This makes efficiencies, such as state-pruning, much easier and more effective.
  • 32.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 So what is Ethereum good for?
  • 33.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Taxi image: www.nyc.gov Businessman image: openclipart.org/detail/19483/businessman-on-phone Dollar sign: openclipart.org/detail/167795/money-20 Location marker: openclipart.org/detail/166612/google-places Example: taxi escrow contract
  • 34.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Taxi Escrow Taxi Escrow Taxi Escrow Example: taxi escrow contract
  • 35.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 Taxi Escrow Taxi Escrow Taxi Escrow Example: taxi escrow contract
  • 36.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0 THE WORLD COMPUTER
  • 37.
    DEVIEW 2015-09-15 aeron.buchanan@ethereum.orgAeron Buchanan, V1, CC BY-SA 3.0