Ethereum: Coding Society

30
ethereum Coding society
  • date post

    14-Sep-2014
  • Category

    Software

  • view

    102
  • download

    0

description

Gavin Wood's introduction to Ethereum and contract programming, given at Assembly 2014, Helsinki, Finland. https://www.youtube.com/watch?v=xO1AxsYAkU8

Transcript of Ethereum: Coding Society

Page 1: Ethereum: Coding Society

ethereumCoding society

Page 2: Ethereum: Coding Society

ethereum

Internet is to communicationas

Ethereum is to agreements

Page 3: Ethereum: Coding Society

basic premise

Place & run code in a decentralised singleton isolated machine;

code can call into other people’s code on the machine;

all transactions with the machine are crypto-signed and archived;

state fully deterministic.

Page 4: Ethereum: Coding Society

blockchain

Diffuse Singleton Data-Structure

(non-localised, no-authority, no-centre)

Page 5: Ethereum: Coding Society

bitcoin & crypto-currencies

Used blockchain to implement basicclearing house ‘contract’

Page 6: Ethereum: Coding Society

ethereum & crypto-law

Uses blockchain to implement basicarbitrary contracts

Page 7: Ethereum: Coding Society

ethereum

Ethereum is to Bitcoinas

the iPhone is to a calculator

Page 8: Ethereum: Coding Society

ethereum

100% Free software, open developmentgithub.com/ethereum

C++, Go, Python implementations(Java & Javascript, too)

Page 9: Ethereum: Coding Society

ethereum

State of Ethereum is just the state of a number of accounts.

Page 10: Ethereum: Coding Society

state: accounts

Address(160-bit excerpt from the 256-bit public key)

Balance, Nonce[, Code, Storage](latter two non-null if a ‘contract’)

Page 11: Ethereum: Coding Society

transactions: state alteration

Alter state by introducing transactions:

either send a message callor

create a contract.

Page 12: Ethereum: Coding Society

contract creation

endowment (ETH), init codegas, signature

Page 13: Ethereum: Coding Society

on creation

Places a new account in the system with code

(code in account is whatever is returned from the init routine)

Page 14: Ethereum: Coding Society

message calls

recipient, value (ETH), datagas, signature

Page 15: Ethereum: Coding Society

on message receipt

value is transferred to recipient’s balance;recipient’s code (if any) runs.

Page 16: Ethereum: Coding Society

code execution: virtual machine

Arbitrary size stackPUSH, POP, SWAP, DUP

Arbitrary temp memory (2256 bytes addressable)MLOAD, MSTORE

Code stored in virtual ROMCODESIZE, CODECOPY

Page 17: Ethereum: Coding Society

virtual machine

Arithmetic/Logic & CryptoADD, EXP, EQ, AND, LT, BYTE, SHA3 &c

Flow controlJUMP, JUMPI, PC

Page 18: Ethereum: Coding Society

vm: environment

Can read message input dataCALLDATALOAD, CALLDATASIZE, CALLDATACOPY

Can halt & give message output dataRETURN, STOP, SUICIDE

Page 19: Ethereum: Coding Society

vm: environment

Arbitrary storage (2256 words addressable)ISOLATED FROM OTHER ACCOUNTS

SLOAD, SSTORE

Can create & send messages.CREATE, CALL

Page 20: Ethereum: Coding Society

vm: environment

Can query blockchain informationTIMESTAMP, PREVHASH, NUMBER, COINBASE, &c.

Other informationADDRESS, BALANCE, ORIGIN, CALLER

Page 21: Ethereum: Coding Society

vm

Storage, memory & processing costs ETH

(actually, costs GAS butGAS ⇔ ETH)

Page 22: Ethereum: Coding Society

lll: basics

expression := ( <op-code> [<operand> ...] )<operand> is just expression

0 -> PUSH 0

(mload 0x20) -> PUSH 0x20 MLOAD

Page 23: Ethereum: Coding Society

contract: currency(sstore (caller) 0x1000000000000)(returnlll (when (= (calldatasize) 64) (seq(mstore 0 (sload (caller)))(when (>= (mload 0) (calldataload 32)) (seq(sstore (caller) (sub (mload 0) (calldataload 32)))(sstore (calldataload 0)(add (sload (calldataload 0)) (calldataload 32))))))))

Page 24: Ethereum: Coding Society

lll: advanced

variables: (set ‘name <expression>)

(mload x) / (mstore y z): @x / [y] z

(sload x) / (store y z): @@x / [[y]] z

(calldataload x): $x

Page 25: Ethereum: Coding Society

contract: currency

[[ (caller) ]] 0x1000000000000(returnlll (when (= (calldatasize) 64) { (set ‘a @@(caller)) (when (>= @a $32) { [[(caller)]] (- @a $32) [[$0]] (+ @@ $0 $32) })}))

Page 26: Ethereum: Coding Society

transaction: transfer

to: <currency-contract>data: <recipient’s-address> <amount-to-transfer>

Page 27: Ethereum: Coding Society

lll: advanced

variadic arithmetic/logic

macros: (def ‘sqr (x) (* x x)) (sqr 4): (* 4 4)

Page 28: Ethereum: Coding Society

lll: name registration

(def ‘registrar 0x50441127ea5b9dfd835a9aba4e1dc9c1257b58ca)[0] 'register[32] 'Exchange(call (- (gas) 21) registrar 0 0 64 0 0)

Page 29: Ethereum: Coding Society

exchange walkthrough...

Page 30: Ethereum: Coding Society

thanks

Looking for devs, too...

C++ in Berlin especially!