ethereum 101

82
>g³¬ @ncu 2017.01.20 1

Upload: chang-wu-chen

Post on 06-Apr-2017

130 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Ethereum 101

g

@ncu

2017.01.20

1

Page 2: Ethereum 101

$whoami •  9N J N和 享 ⽤是

–  3(( N J N (–  和 享⼩ e⼒

•  z t 也 後–  3 第⽂ 電–  ⼒ 給 加 也 第⽂

•  都d⽚ ⽚t ⾝ 出 ⽤–  –  j機 ⼦

•  可⼒ d 實7:F9–  FN HGF3 得這 e 也

2C I B ( B A DB

Page 3: Ethereum 101

u•  +))1 )

–  FJ RBJTJ z 同#⼤ 個本 以•  +))2

–  ⽤–  個本 ⽤–  ) ))) 個本 家fm

•  +) )– –  3((KR RW P(

3

Page 4: Ethereum 101

•  點本•  本 兩•  本 明•  g⼀p果 #

4

Page 5: Ethereum 101

b•  w p 點本 多

–  來意 點本 明學–  來意 點本 名

5

Page 6: Ethereum 101

6

Page 7: Ethereum 101

s

7

⽂ 博⽂

Secp256k1

Page 8: Ethereum 101

)A Sd D

8

Alice Bob

點本 ~u 明學來 eh7UR N

Page 9: Ethereum 101

)A Sd D

9

Alice Bob

7UR N ⽂ – 點本8 K

點本 ~u 明學來 eh7UR N

密文

Page 10: Ethereum 101

)A Sd D

10

Alice Bob

7UR N p 8 Kfm 本e點本 hu 明學

密文

Page 11: Ethereum 101

S y

11

Alice Bob

  8 K re 本k來g+   來 7UR N全,   來種 m 本 k 明

Page 12: Ethereum 101

y

12

Alice Bob

#12344

#12345

n 本 ⼀pfm 新e

Page 13: Ethereum 101

P

13

Alice Bob

#12345

⾼ hgh7UR Ne+ 7UR Nk ⾼

#12345

Alice:100->99

Bob:100->101

Page 14: Ethereum 101

Recap•  ⽂

–  本 名–  多eg #

•  新–  沒 本 意

14

Page 15: Ethereum 101

ZT•  ⽂

–  本 名–  多eg #

•  新 mlvh果–  沒 本 意

15

果 全 讓 e全和 享 8U JRW#

Page 16: Ethereum 101

)A Sd D

16

Alice Bob

#12345

Alice:100->99

Bob:100->101

Page 17: Ethereum 101

Double-spending

17

Alice Bob

#12345

#12345

Charlie l 來 全

Page 18: Ethereum 101

l Xkk

18

Alice Bob

#12345

#12345

Charlie

~ 作

Page 19: Ethereum 101

19

Alice Bob

#12345

#12345

Charlie

klv r 多 博 7UR N在 e點本8 K 9 J URN ou沒

Page 20: Ethereum 101

20

Alice Bob

#12345

#12345

Charlie

7UR N種 k點本 +,-. j會 8 Ki

Page 21: Ethereum 101

Recap•  來意 作•  全 e 間•  y l博 多 全

21

Alice

7UR N 有

SybilaHack

Page 22: Ethereum 101

S•  讓 下 h t 讓•  讓 下 gh t ⻑ 讓

•  讓 下 h fm中 ln– ⽣全–  中 le p

22

Page 23: Ethereum 101

ProofofWork•  博 多 下•  多博 們 有 FaKRUJ J T#•  ⼤ 的 # 他博 多

•  ⽽ #•  意 全 #

23

和 沒 G

Page 24: Ethereum 101

2D •  mlv~說 D bbUN#

– f v~說•  gukl ⽣全如 ⽣和 e如 #

–  ⽅

24

r W45,el ⽣全

Page 25: Ethereum 101

SHA-2562(“abc”+“1”)=

158c09e82d88955d8a051934d12f74a53ea205743778165d1140a8903686e1ac

SHA-2562(“abc”+“2”)=

c72b0720d3302d76cd7b6b3f3dcb554d05f14fee8567cdda3ee8b7ff51e02015

.

.

.

SHA-2562(“abc”+“19”)=

005eR2ff3e871185b95bf7c8628e212d15a7d08c42235a381e06caa55856a0c

2D •  ⽽ 博 多 很分

25

Hash(TXs+nonce)<number

00000000000000005b95bf7c8628e212d15a7d08c42235a381e06caa55856a0c

Page 26: Ethereum 101

SHA-2562(“abc”+“1”)=

158c09e82d88955d8a051934d12f74a53ea205743778165d1140a8903686e1ac

SHA-2562(“abc”+“2”)=

c72b0720d3302d76cd7b6b3f3dcb554d05f14fee8567cdda3ee8b7ff51e02015

.

.

.

SHA-2562(“abc”+“19”)=

005eR2ff3e871185b95bf7c8628e212d15a7d08c42235a381e06caa55856a0c

2D •  ⽽ 博 多 很分

26

算力越強的人越有機會擁有寫帳權 但不代表掌握 70% 算力別人就沒機會,只是概率低

Page 27: Ethereum 101

a

27

Alice

#12345

#21397

#81345

#22345

Page 28: Ethereum 101

28

Block1

...

Block2

...

Block3

...

Block4

...

r和

Hash(Block3|TXs|nonce) o e

區塊

Page 29: Ethereum 101

AD @ C

29

Block4

...

Block5

...

Block6

...

Block7

...

Block8

...

Block9

...

NJW3c ) 地 D R WMR RK R W#

BlockN

...⋯⋯⋯

困難度 (Difficulty)

區塊高度 (Block height) 區塊深度 (Block depth)

w m h

Page 30: Ethereum 101

Recap•  來意 作

–  D 作 ⽅–  多博 信r想m為–  有下 看 ⾏⽔ j

•  全 e 間•  y l博 多 全

30

Alice

7UR N 有

Page 31: Ethereum 101

Blockchain

•  Demo

31

Page 32: Ethereum 101

Ethereum101

32

Page 33: Ethereum 101

cWPEthereum?

33

VitalikButerin

“BitcoinwasdesignedtobeaSMTP.It’saprotocol

that is very goodatoneparacular task. It is good

fortransferringmoney,butitwasnotdesignedasa

foundaaonal layer for any kind of protocols to be

builtontop.”

Page 34: Ethereum 101

cWPEthereum?

34

VitalikButerin

“Theneedforatechnologythatwasmore

expansive,andthatreplicatedthefuncaonalityof

Turing-completeprogramminglanguagesinaway

thatwouldbesopowerfulastodescribeany

blockchainapplicaaon.”

Page 35: Ethereum 101

Bitcoin Ethereum Creator Satoshi Nakamoto Ethereum

Player type cryptocurrency Smart contract platform with own cryptocurrency

Liquidity decent decent currency code Bitcoin/�/BTC Ether/�/ETH

Public/Private blockchain public public User identity pseudonymous pseudonymous

Consensus algorithm PoW PoW/PoS/Casper

Scripting language Bitcoin Script

Language Solidity

Smart contracts yes (limited) yes Turing completeness no yes

Governance (development decisions, etc) Core team Ethereum Foundation

Transaction speed >10.0m 15s

Rapid payments Lightning Network Raiden Network

Processing cost (CPU,GPU,ASIC) high high Other features UTXO GHOST

35

Page 36: Ethereum 101

Components•  Acryptographictoken•  Anaddresssystem

•  Anetworkofvalidators(miners)

•  Aconsensusalgorithm

•  Ablockchainledger•  TheEthereumVirtualMachine

•  Asetofprograminglanguages

•  Complexeconomicstructures

36

Page 37: Ethereum 101

TechnologyStack(1/2)

37

•  Fullnode–  go-ethereum(Golang)

–  Parity(Rust)–  cpp-ethereum(C++)

–  EthereumJ(Java)

–  pyethereum(Python)

–  ruby-ethereum(Ruby)

Page 38: Ethereum 101

TechnologyStack(2/2)

38

•  Smartcontractprogramming

–  Solidity(JavaScript-like)

–  Serpent(Python-like)

–  LLL(Lisp-like)

–  Viper

–  Bamboo

Page 39: Ethereum 101

ru t•  Ethereumhasablockchain

•  Ethereumispublicandpermissionless

•  EthereumhasProof-of-Work(PoW)mining

–  Ethash•  Ethereumhasaninbuiltcryptocurrency(Ether)

39

Page 40: Ethereum 101

ru t•  Ethereum’sblockameisshorter(15seconds)

•  Ethereumhassmallerblocks

–  2,000,000gasperblock–  Limitedbythegasà(2,000,000/x)transacaons

•  TheEthereumVirtualMachinecanrunsmartcontracts

•  ETHtokenissuance

40

Page 41: Ethereum 101

ETHtokenissuanceG JU G 5D N RWN 8U T N J M HW UN N J M HW UN NON NW RWP N J M

•  D N RWN3 太還沒 0+)) m 本 有 eg fe太還 要 1)) m 本

•  8U T N J M3們 fm和 的 h.m 本 fm和 e ⼿ -動 家發f k++. m和 ,/. +- /) /)( -# +. m 本

•  HW UN N J M3j z k 和 j f gh j享s 裡 HW UN和 個本ze 和 C JWKU T# 和~ e和 說了 和 e的 的 e 要

. 0(1#5- ,0.m 本 HW UN和 e沒 ⽅ f ⼿k 0)) m 本

•  HW UN NON NW RWP N J M3 jHW UN和 e和 ) . 本f#

•  的 e= U . NNMa NJ RN 1K N NM K NN#41

Page 42: Ethereum 101

圖片來自 https://bitsonblocks.net 42

Page 43: Ethereum 101

  沒 ⽂ /- (,+Ka N #

+   ⽂ 到 9:F7下 +1 (/-Ka N #,   -) (+)Ka N #

–  /-Ka N–  – J J e成下 @N JT +./ J J ,+Ka N–  ,+Ka N e +Ka N 現 於 e+)Ka N oh -) #

•  N WJUJMM N N #•  ⼿ 9 W J JMM N N #

43

Page 44: Ethereum 101

Timeline

44

  H rE H pn lO  ,D )HH @ +1, DE D B GE

Page 45: Ethereum 101

45

hHps://etherscan.io/block/3000000

Page 46: Ethereum 101

46

hHps://etherscan.io/block/3000000

hHps://etherscan.io/tx/0xb95ab9484280074f7b8c6a3cf5ffe2bf0c39168433adcdedc1aacd10d994d95a

Page 47: Ethereum 101

Ether&Gas•  Ether:token•  Gas:computaaoncost

47

Page 48: Ethereum 101

Gas•  n所 多 JW J R W#看 ⼿ W J #j N N s 主

e 要y m 樣看y m ⼀p⾞ e 因時fm vu ⾞ ePJ 明每e ⼀p ⾞事ye下 ⼀ePJ

•  PJ m 有 h p種 ⼿~ gue ⾞

48

Page 49: Ethereum 101

Gas•  j8R RWz f⾼ 多⼀p 所 hx 多et

JW J R W RbN#因 j N N e e 下j和 享 s ⼀pe

•  n j N N z m ⼿ ⽤ t g k ~e⽤ ⾞ ePJ 主 e y 定r J,因j8R RW 多就才e y et t 事

49

Page 50: Ethereum 101

50

Totalcost=gasUsed*gasPrice

Page 51: Ethereum 101

Gasprice•  PJ R N mPJ 上 y N N PJ R Nu能這 ⼀不被•  PJ R Ne h NR NR5 ) 1N N•  PJ R Ne 之

51

Page 52: Ethereum 101

52

Page 53: Ethereum 101

53

韩梅梅 李雷

0.319BTC

Fees0.001BTC

0.32BTC

1AnLpMkAmf7jy2BNkP3oYw1phzhNuLws7M(0.32BTC) 1GJYiog3ato17SSTFCCdkZ44H6LdkW9j1V(0.319BTC)

TxFee:0.001BTC

u

BitcoinUnconfirmedTransacaon( )!!!

Page 54: Ethereum 101

54

{

"hash":"7c4025...",

"ver":1,

"vin_sz":1,

"vout_sz":1,

"lock_ame":0,

"size":224,

"in":[{

"prev_out":{

"hash":"2007ae...",

"n":0

},

"scriptSig":"304502...042b2d..."

}],

"out":[{

"value":"0.31900000",

"scriptPubKey":"OP_DUPOP_HASH160a7db6fOP_EQUALVERIFYOP_CHECKSIG"

}]

}

metadata

Input(s)

output(s)

•  交易 ID (流水號) •  版本 •  Input 數量 •  output數量 •  區塊鎖定時間 •  交易大小

hHps://blockchain.info/rawtx/7c402505be883276b833d57168a048cfdf306a926484c0b58930f53d89d036f9

Page 55: Ethereum 101

55

{

"hash":"7c4025...",

"ver":1,

"vin_sz":1,

"vout_sz":1,

"lock_ame":0,

"size":224,

"in":[{

"prev_out":{

"hash":"2007ae...",

"n":0

},

"scriptSig":"304502...042b2d..."

}],

"out":[{

"value":"0.31900000",

"scriptPubKey":"OP_DUPOP_HASH160a7db6fOP_EQUALVERIFYOP_CHECKSIG"

}]

}

metadata

Input(s)

output(s)

hHps://blockchain.info/rawtx/7c402505be883276b833d57168a048cfdf306a926484c0b58930f53d89d036f9

•  之前的交易 ID (pointer) •  第幾個 ouput

•  簽名 scriptSig:<sig><pubKey>

Page 56: Ethereum 101

56

{

"hash":"7c4025...",

"ver":1,

"vin_sz":1,

"vout_sz":1,

"lock_ame":0,

"size":224,

"in":[{

"prev_out":{

"hash":"2007ae...",

"n":0

},

"scriptSig":"304502...042b2d..."

}],

"out":[{

"value":"0.31900000",

"scriptPubKey":"OP_DUPOP_HASH160a7db6fOP_EQUALVERIFYOP_CHECKSIG"

}]

}

metadata

Input(s)

output(s)

hHps://blockchain.info/rawtx/7c402505be883276b833d57168a048cfdf306a926484c0b58930f53d89d036f9

•  轉出金額 •  bitcoin script

Page 57: Ethereum 101

57

{

"hash":"7c4025...",

"ver":1,

"vin_sz":1,

"vout_sz":1,

"lock_ame":0,

"size":224,

"in":[{

"prev_out":{

"hash":"2007ae...",

"n":0

},

"scriptSig":"304502...042b2d..."}],

"out":[{

"value":"0.31900000",

"scriptPubKey":"OP_DUPOP_HASH160a7db6fOP_EQUALVERIFYOP_CHECKSIG"}]

}

metadata

Input(s)

output(s)

hHps://blockchain.info/rawtx/7c402505be883276b833d57168a048cfdf306a926484c0b58930f53d89d036f9

Page 58: Ethereum 101

58

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

Page 59: Ethereum 101

59

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

Page 60: Ethereum 101

60

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

<pubKey>

Page 61: Ethereum 101

61

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

<pubKeyHash>

Page 62: Ethereum 101

62

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

<pubKeyHash>

<pubKeyHash>

Page 63: Ethereum 101

63

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

Page 64: Ethereum 101

64

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

True

a7db6ff121871c65a8924b8e40f160d385515ad7

Page 65: Ethereum 101

Turing-complete

programminglanguages

65

Page 66: Ethereum 101

cWP•  )

–  (– – 

• 

• 

•  (– – 

66

圖片來自 https://bitsonblocks.net

Page 67: Ethereum 101

ir

67

•  合約的執行會依據不同時間的事件或設定的規則,而更新狀態或價值

Page 68: Ethereum 101

BlockchainistheInternet'ssociety,andsmartcontractsareitslaws.

Page 69: Ethereum 101
Page 70: Ethereum 101

70

Page 71: Ethereum 101

•  f–  ⼈ N N URNW–  URMR a ⽣ ⼿–  URMR a RUN –  NK, S ⼿在 更

•  ⼀pk年 享看 享 年 #•  前每

71

•  Fullnode

–  go-ethereum(Golang)

–  Parity(Rust)

Page 72: Ethereum 101

Truffle+Testrpc•  Truffle

–  hHps://github.com/ConsenSys/truffle

•  Testrpc–  hHps://github.com/ethereumjs/testrpc

•  ⾼–  hHps://cl.ly/iqCw/ETH_dev.html

–  hHps://cl.ly/i7Sd/truffle.html

•  g⼀p更開 分為•  j 年 主 ⼿•  分•  說對BR Te⾼ t ⽤ #

–  3(( NMR (6 NM T

72

Page 73: Ethereum 101

73

Page 74: Ethereum 101

DatacarrierforDApps

74

•  Oraclize:hHp://www.oraclize.it/

–  hHps://github.com/oraclize/ethereum-examples/tree/master/solidity

• 

Page 75: Ethereum 101

EthereumAlarmClock•  Scheduletransacaonstobeexecutedatalaterame.

•  EnareserviceoperatesassmartcontractsontheEthereum

blockchain,withnopriviledgedaccessgiventoanyparty.

–  hHp://www.ethereum-alarm-clock.com

75

Page 76: Ethereum 101

EthereumComputaSonMarket•  ThecomputaaonmarketisaserviceforEthereumthatallows

forverifiableoff-chainexecuaonofcomputaaonsthatwould

beotherwiseprohibiavelyexpensivetoexecutewithinthe

EVM.

–  hHp://www.ethereum-computaaon-market.com

76

Page 77: Ethereum 101

zeppelin-solidity•  AFrameworktoBuildSecureSmartContracts

–  CommoncontractsecuritypaHerns

–  IntheSoliditylanguage–  hHps://openzeppelin.org

77

Page 78: Ethereum 101

EthereumDev(1/2)  無開 N N ⽂k享

+   mW MN,   ⾯PN J JF R 9 W UN-   開 全 開 多 KU T.   ⽂k享e RWN/   ED9 U到0   N N 8U TN U N1   F J 9 W J W N N2   AR)   F URMR a  :7 P J RWP

78

Page 79: Ethereum 101

EthereumDev(1/2)•  Track1

1.  IntroducaontoSmartContracts

2.  Se�ngupthedevelopmentenvironmentwithtruffleandtestrpc

3.  Readingdocumentaaonandreferenceresources

4.  WatchingtutorialsonbuildingSmartContracts

5.  Smartcontractsecurityandtesang

•  Track2

1.  Se�ngupadevelopmentenvironmentwithReactJSandFirebase

2.  ReactJSandfirebaseHelloWorld

3.  ResearchonEthereumandDapp

4.  Developmentofanon-trivialSmartContractApplicaaon

5.  Buildinguser-centricinterfaces

6.  ShouldhaveakeeninterestonbuildingbeauafulyetsimpleUI 79

Page 80: Ethereum 101

•  三以 –  hHp://gavwood.com/Paper.pdf

•  可–  hHps://github.com/EtherTW/Taipei-Ethereum-Wiki/wiki/Learning-Resources

•  成過–  hHps://www.youtube.com/channel/UC8CB0ZkvogP7tnCTDR-zV7g/videos

80

Page 81: Ethereum 101

g•  GJR NR N N ANN

–  3(( NN (GJR NR N N ANN (•  <J NK T

–  3(( OJ NK T (P (--,0. )0+-1-0,2(

81

Page 82: Ethereum 101

Q&AThanksforyourlistening!

82