DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
THE WORLD COMPUTER
DEVIEW 2015-09-15 [email protected] 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 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
The computer that anyone can program and everyone can trust
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
A planetary-scalevirtual machine:
Trusted Computation and Storage Service Platform
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Peer-to-peer network:
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Peer-to-peer network:Robust to connection problems and attacks
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Peer-to-peer network:New connections can be made to repair connectivity
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Intrinsic features include:
Cryptographic Identity Checking and Custom Payment Logic
DEVIEW 2015-09-15 [email protected] 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 Contract3. Transfer ether
Cryptographically Signed Instructions
State Data
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum Contracts are
EVM code + Persistent Storage
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum Contracts are
EVM code + Persistent Storage
EthereumVirtualMachine
DEVIEW 2015-09-15 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
EVM opcodes are tailored to Ethereum's specific set-up:0x00: STOP0x01: ADD0x02: MUL0x03: SUB0x04: DIV0x05: SDIV0x06: MOD0x07: SMOD0x08: ADDMOD0x09: MULMOD0x0A: EXP0x0B: SIGNEDEXTEND0x10: LT0x11: GT0x12: SLT0x13: SGT0x14: EQ0x15: ISZERO0x16: AND
0x17: OR0x18: XOR0x19: NOT0x1A: BYTE0x20: SHA30x30: ADDRESS0x31: BALANCE0x32: ORIGIN0x33: CALLER0x34: CALLVALUE0x35: CALLDATALOAD0x36: CALLDATASIZE0x37: CALLDATACOPY0x38: CODESIZE0x39: CODECOPY0x3A: GASPRICE0x3B: EXTCODESIZE0x3C: EXTCODECOPY0x40: BLOCKHASH
0x00: STOP0x01: ADD0x02: MUL0x03: SUB0x04: DIV0x05: SDIV0x06: MOD0x07: SMOD0x08: ADDMOD0x09: MULMOD0x0A: EXP0x0B: SIGNEDEXTEND0x10: LT0x11: GT0x12: SLT0x13: SGT0x14: EQ0x15: ISZERO0x16: AND
0x41: COINBASE0x42: TIMESTAMP0x43: NUMBER0x44: DIFFICULTY0x45: GASLIMIT0x50: POP0x51: MLOAD0x52: MSTORE0x53: MSTORE80x54: SLOAD0x55: SSTORE0x56: JUMP0x57: JUMPI0x58: PC0x59: MSIZE0x5A: GAS0x5B: JUMPDEST0x6X: PUSHX0xF0: CREATE
DEVIEW 2015-09-15 [email protected] 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 consoleimplicitly in the alethzero/alethone GUI orintrinsically in the Mix IDE
DEVIEW 2015-09-15 [email protected] 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 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Cryptographically Signed Instructions
State Data
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum“daemon”
Instructions
State Data
ÐΞVp2pEthereumInterface
Instructions
State Data
JSON RPC
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum“daemon”
Instructions
State Data
ÐΞVp2pEthereumInterface
Instructions
State Data
JSON RPC
Ideally: local machine via http
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Ethereum“daemon”
Instructions
State Data
ÐΞVp2pEthereumInterface
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 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
JSON RPC example:
// Requestcurl -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 [email protected] 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 [email protected] 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 [email protected] 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
MULADDSHA3
DEVIEW 2015-09-15 [email protected] 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 [email protected] 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 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Transfer Funds
Run Contract
New Contract
CL
IEN
TS
balances statestaten-1
staten
Tra
nsac
tion
Poo
l
Po
W
balances state
verify
execute
select
Pro
cess
Lis
t
gas
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
CL
IEN
TS
Tra
nsac
tion
Poo
l
UTXOsblockn-1
UTXOsblockn
select
Classic Blockchains
verify
Po
W
DEVIEW 2015-09-15 [email protected] 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 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
So what is Ethereum good for?
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Taxi image: www.nyc.govBusinessman image: openclipart.org/detail/19483/businessman-on-phoneDollar sign: openclipart.org/detail/167795/money-20Location marker: openclipart.org/detail/166612/google-places
Example: taxi escrow contract
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Taxi Escrow Taxi Escrow Taxi Escrow
Example: taxi escrow contract
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
Taxi Escrow Taxi Escrow Taxi Escrow
Example: taxi escrow contract
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0
THE WORLD COMPUTER
DEVIEW 2015-09-15 [email protected] Aeron Buchanan, V1, CC BY-SA 3.0