2. 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
9. 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
13. 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
14. 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
15. 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
16. 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
17. 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
18. 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
21. 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
22. 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 …
24. 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.
25. 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.
26. 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
27. 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
28. 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.
29. 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
31. 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.