Ethereum 101

Preview:

Citation preview

g

@ncu

2017.01.20

1

$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

u•  +))1 )

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

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

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

3

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

4

b•  w p 點本 多

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

5

6

s

7

⽂ 博⽂

Secp256k1

)A Sd D

8

Alice Bob

點本 ~u 明學來 eh7UR N

)A Sd D

9

Alice Bob

7UR N ⽂ – 點本8 K

點本 ~u 明學來 eh7UR N

密文

)A Sd D

10

Alice Bob

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

密文

S y

11

Alice Bob

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

y

12

Alice Bob

#12344

#12345

n 本 ⼀pfm 新e

P

13

Alice Bob

#12345

⾼ hgh7UR Ne+ 7UR Nk ⾼

#12345

Alice:100->99

Bob:100->101

Recap•  ⽂

–  本 名–  多eg #

•  新–  沒 本 意

14

ZT•  ⽂

–  本 名–  多eg #

•  新 mlvh果–  沒 本 意

15

果 全 讓 e全和 享 8U JRW#

)A Sd D

16

Alice Bob

#12345

Alice:100->99

Bob:100->101

Double-spending

17

Alice Bob

#12345

#12345

Charlie l 來 全

l Xkk

18

Alice Bob

#12345

#12345

Charlie

~ 作

19

Alice Bob

#12345

#12345

Charlie

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

20

Alice Bob

#12345

#12345

Charlie

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

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

21

Alice

7UR N 有

SybilaHack

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

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

22

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

•  ⽽ #•  意 全 #

23

和 沒 G

2D •  mlv~說 D bbUN#

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

–  ⽅

24

r W45,el ⽣全

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

158c09e82d88955d8a051934d12f74a53ea205743778165d1140a8903686e1ac

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

c72b0720d3302d76cd7b6b3f3dcb554d05f14fee8567cdda3ee8b7ff51e02015

.

.

.

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

005eR2ff3e871185b95bf7c8628e212d15a7d08c42235a381e06caa55856a0c

2D •  ⽽ 博 多 很分

25

Hash(TXs+nonce)<number

00000000000000005b95bf7c8628e212d15a7d08c42235a381e06caa55856a0c

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

158c09e82d88955d8a051934d12f74a53ea205743778165d1140a8903686e1ac

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

c72b0720d3302d76cd7b6b3f3dcb554d05f14fee8567cdda3ee8b7ff51e02015

.

.

.

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

005eR2ff3e871185b95bf7c8628e212d15a7d08c42235a381e06caa55856a0c

2D •  ⽽ 博 多 很分

26

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

a

27

Alice

#12345

#21397

#81345

#22345

28

Block1

...

Block2

...

Block3

...

Block4

...

r和

Hash(Block3|TXs|nonce) o e

區塊

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

Recap•  來意 作

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

•  全 e 間•  y l博 多 全

30

Alice

7UR N 有

Blockchain

•  Demo

31

Ethereum101

32

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.”

cWPEthereum?

34

VitalikButerin

“Theneedforatechnologythatwasmore

expansive,andthatreplicatedthefuncaonalityof

Turing-completeprogramminglanguagesinaway

thatwouldbesopowerfulastodescribeany

blockchainapplicaaon.”

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

Components•  Acryptographictoken•  Anaddresssystem

•  Anetworkofvalidators(miners)

•  Aconsensusalgorithm

•  Ablockchainledger•  TheEthereumVirtualMachine

•  Asetofprograminglanguages

•  Complexeconomicstructures

36

TechnologyStack(1/2)

37

•  Fullnode–  go-ethereum(Golang)

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

–  EthereumJ(Java)

–  pyethereum(Python)

–  ruby-ethereum(Ruby)

TechnologyStack(2/2)

38

•  Smartcontractprogramming

–  Solidity(JavaScript-like)

–  Serpent(Python-like)

–  LLL(Lisp-like)

–  Viper

–  Bamboo

ru t•  Ethereumhasablockchain

•  Ethereumispublicandpermissionless

•  EthereumhasProof-of-Work(PoW)mining

–  Ethash•  Ethereumhasaninbuiltcryptocurrency(Ether)

39

ru t•  Ethereum’sblockameisshorter(15seconds)

•  Ethereumhassmallerblocks

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

•  TheEthereumVirtualMachinecanrunsmartcontracts

•  ETHtokenissuance

40

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

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

  沒 ⽂ /- (,+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

Timeline

44

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

45

hHps://etherscan.io/block/3000000

46

hHps://etherscan.io/block/3000000

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

Ether&Gas•  Ether:token•  Gas:computaaoncost

47

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

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

50

Totalcost=gasUsed*gasPrice

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

51

52

53

韩梅梅 李雷

0.319BTC

Fees0.001BTC

0.32BTC

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

TxFee:0.001BTC

u

BitcoinUnconfirmedTransacaon( )!!!

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

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>

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

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

58

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

59

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

60

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

<pubKey>

61

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

<pubKeyHash>

62

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

<pubKeyHash>

<pubKeyHash>

63

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

<sig>

a7db6ff121871c65a8924b8e40f160d385515ad7

<pubKey>

64

scriptSig:<sig><pubKey>

scriptPubKey:OP_DUPOP_HASH160<pubKeyHash>OP_EQUALVERIFYOP_CHECKSIG

True

a7db6ff121871c65a8924b8e40f160d385515ad7

Turing-complete

programminglanguages

65

cWP•  )

–  (– – 

• 

• 

•  (– – 

66

圖片來自 https://bitsonblocks.net

ir

67

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

BlockchainistheInternet'ssociety,andsmartcontractsareitslaws.

70

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

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

71

•  Fullnode

–  go-ethereum(Golang)

–  Parity(Rust)

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

73

DatacarrierforDApps

74

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

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

• 

EthereumAlarmClock•  Scheduletransacaonstobeexecutedatalaterame.

•  EnareserviceoperatesassmartcontractsontheEthereum

blockchain,withnopriviledgedaccessgiventoanyparty.

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

75

EthereumComputaSonMarket•  ThecomputaaonmarketisaserviceforEthereumthatallows

forverifiableoff-chainexecuaonofcomputaaonsthatwould

beotherwiseprohibiavelyexpensivetoexecutewithinthe

EVM.

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

76

zeppelin-solidity•  AFrameworktoBuildSecureSmartContracts

–  CommoncontractsecuritypaHerns

–  IntheSoliditylanguage–  hHps://openzeppelin.org

77

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

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

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

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

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

80

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

Q&AThanksforyourlistening!

82

Recommended