ethereum hackers

30
ethereum Coding society

Upload: gavofyork

Post on 01-Jul-2015

169 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Ethereum hackers

ethereumCoding society

Page 2: Ethereum hackers

ethereum

Internet is to communicationas

Ethereum is to agreements

Page 3: Ethereum hackers

basic premisePlace & 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 hackers

blockchain

Diffuse Singleton Data-Structure

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

Page 5: Ethereum hackers

bitcoin & crypto-currencies

Used blockchain to implement basicclearing house ‘contract’

Page 6: Ethereum hackers

ethereum & crypto-law

Uses blockchain to implement basicarbitrary contracts

Page 7: Ethereum hackers

ethereum

Ethereum is to Bitcoinas

the iPhone is to a calculator

Page 8: Ethereum hackers

ethereum

100% Free software, open developmentgithub.com/ethereum

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

Page 9: Ethereum hackers

ethereum

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

Page 10: Ethereum hackers

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 hackers

transactions: state alteration

Alter state by introducing transactions:

either send a message callor

create a contract.

Page 12: Ethereum hackers

contract creation

endowment (ETH), init codegas, signature

Page 13: Ethereum hackers

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 hackers

message calls

recipient, value (ETH), datagas, signature

Page 15: Ethereum hackers

on message receipt

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

Page 16: Ethereum hackers

code execution: virtual machineArbitrary size stack

PUSH, POP, SWAP, DUP

Arbitrary temp memory (2256 bytes addressable)

MLOAD, MSTORE

Code stored in virtual ROMCODESIZE, CODECOPY

Page 17: Ethereum hackers

virtual machine

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

Flow controlJUMP, JUMPI, PC

Page 18: Ethereum hackers

vm: environment

Can read message input dataCALLDATALOAD, CALLDATASIZE, CALLDATACOPY

Can halt & give message output dataRETURN, STOP, SUICIDE

Page 19: Ethereum hackers

vm: environment

Arbitrary storage (2256 words addressable)ISOLATED FROM OTHER ACCOUNTS

SLOAD, SSTORE

Can create & send messages.CREATE, CALL

Page 20: Ethereum hackers

vm: environment

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

Other informationADDRESS, BALANCE, ORIGIN, CALLER

Page 21: Ethereum hackers

vm

Storage, memory & processing costs ETH

(actually, costs GAS butGAS ⇔ ETH)

Page 22: Ethereum hackers

lll: basics

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

0 -> PUSH 0

(mload 0x20) -> PUSH 0x20 MLOAD

Page 23: Ethereum hackers

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 hackers

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 hackers

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

Page 26: Ethereum hackers

transaction: transfer

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

Page 27: Ethereum hackers

lll: advanced

variadic arithmetic/logic

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

Page 28: Ethereum hackers

lll: name registration

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

Page 29: Ethereum hackers

exchange walkthrough...

Page 30: Ethereum hackers

thanks

Looking for devs, too...

C++ in Berlin especially!