SlideShare a Scribd company logo
1 of 42
Blockchain 2.0 :
Tom Yang
Smart Contract 的美麗與哀愁Smart Contract 的美麗與哀愁
https://bitsonblocks.net/2016/02/01/a-
gentle-introduction-to-smart-contracts/
Blockchain 1.0
• BitCoin 與 數位貨幣
• 分散式帳本
• 去中心化貨幣
• Immutable
https://datafloq.com/read/what-is-the-blockchain-and-why-is-it-so-important/2270
2
Blockchain 1.0
3http://www.the-blockchain.com/2016/12/07/rsk-making-bitcoin-blockchain-like-ethereum-2-0/
Why BitCoin = Blockchain 1.0
• Blockchain橫空出世
• 分散式帳本
• 去中心化
• 數位貨幣的新里程碑
• 各式各樣的數位貨幣開始出現
• 就只是個數位貨幣
• 但區塊鏈的特性應該可以保存更多數位資產
4
Ethereum
5
Wiki :
“以太坊是一個開源的有智慧型合約功能的公共區塊鏈平台。”
“ It provides a decentralized Turing-complete virtual
machine, the Ethereum Virtual Machine (EVM), which can
execute scripts using an international network of public
nodes. “
Ethereum
• EVM是一個建立在區塊鏈上的VM
• 想像你想執行的邏輯、儲存空間甚至運算單元都在區塊鏈上
• 於以太坊上所有動作於圖靈完備的EVM上做操作
• 每種動作(Operation)分別消耗不同的ether(以太幣)
• 手續費只與Operation相關,只與工作量相關
• 有了圖靈完備的EVM,就可以在區塊鏈上做更多的事
• 在區塊鏈上寫程式
• Smart Contract 智能合約
6
Blockchain 2.0
• Smart Contract 智能合約
7
Traditional
Contract
Smart
Contract
Coding Deploy
Smart Contract 智能合約
• Code is Law (Code is Contract)
• 程式碼即法律 (程式碼即合約)
• 程式碼對於合約有相同的理解
• 去中心化
• 智能 非指 人工智能
• 程式碼僅執行複雜的規則和條件,不具學習功能
• 電梯
• 販賣機
• Contract address內與一般Account address一樣,都可放入以太幣
8
https://www.youtube.com/watch?v=uFBu2P1mwFU
Smart Contract on Ethereum : Construction
9
Smart
Contract
Compile
Programming Language :
Solidity (JS-like)
Serpent (Python-like)
…
EVM bytecode
6060604052341561000c57fe5b5b6
0ae8061001b6000396000f3006060
6040526000357c010000000000000
0000000000000000000000000000
000000000000000900463ffffffff16
80633c4308a814603a575bfe5b341
5604157fe5b605e60048080359060
2001909190803590602001909190
50506074565b6040518082815260
200191505060405180910390f35b6
00081830290505b929150505600a
165627a7a72305820c40f61d36a3a
1b7064b58c57c89d5c3d7c73b911
6230f9948806b11836d2960c0029
Deploy
Deploy on Ethereun
=
Transaction on Ethereum
Contract address : 0xabc
Smart Contract on Ethereum
10
https://etherscan.io/address/0x5a2a454675c1b659caa58b5675ee759b992b84b1#code
Smart Contract on Ethereum
11
Smart Contract on Ethereum : Execution
12
Address : 0xabc
Smart Contract on blcokchain
Transaction
Execute :
placeBet()
Output
Return :
“Success”
Smart Contract on Ethereum
• 認識名詞
• Gas : 每個動作都需要耗費燃料的單位
• Gas Price : 每個gas要的ether
• Gas Limit : 執行所有動作的gas消耗上限
• Contract : Deploy在以太坊上的動作集合
13
https://www.cryptocompare.com/coins/guides/what-is-the-gas-in-ethereum/
From Smart Contract to
Decentralized application (DApp)
• Normal application
= Frontend + Backend
• Decentralized application
= Frontend + BlockChain
• DApp on Ethereum
= Frontend + Smart Contracts
14https://ethereum.stackexchange.com/questions/383/what-is-a-dapp
DApp - ICO
• Initial Coin Offerings
• ICO on Ethereum: Publish your own token (for specific purpose)
• Change ether into token
• Rather than create your own BlockChain
• Only thing you need to do is write a contract on the Ethereum
15
去中心化超級電腦去中心化市場預測平台
https://www.bnext.com.tw/article/44959/what-is-ethereum-and-how-ico-become-the-reason-that-ether-exceeds-bitcoin
$5.2 million $8.6 million $35 million
in 30 sec
去中心化透明數位廣告平台
BAT
DApp - ICO
• ERC20 Standard
• Describes the functions and events that an Ethereum token contract
has to implement
16
DApp - ICO
• Pros
• 數位貨幣(代幣)蓬勃發展
• 更多的DApp產生
• Cons
• Lack of supervision
• Fraud
• 大型ICO所造成的塞車現象
17
DApp – MultiSig Wallet
• Multi-Signature Wallet (多簽錢包)
18
傳統錢包
0xaaa
(Account
Address)
Owner (Private key owner)
只需單一owner即可動用位址內的資產
多簽錢包
0xabc
(Smart Contract
Address)
Owner : A, B, C
Multi-Owner
需單一至多位owner做確認
才可動用位址內的資產
DApp – MultiSig Wallet
• 零用錢多簽錢包,owner : 家長, 小孩
19
多簽錢包
Smart Contract
Daily limit : 100
Owner : 家長, 小孩
小孩
Transaction
我要買午餐,領80
傳送80給小孩
沒超過Daily limit家長
DApp – MultiSig Wallet
• 零用錢多簽錢包,owner : 家長, 小孩
20
多簽錢包
Smart Contract
Daily limit : 100
Owner : 家長, 小孩
Transaction
我要繳房租,領1000
須等另一Owner確認
超過Daily limit
Transaction
好的,給領1000
傳送1000給小孩
確認完成
小孩家長
Parity MultiSig Wallet
21https://www.coindesk.com/30-million-ether-reported-stolen-parity-wallet-breach/
• Parity MultiSig Wallet Structure
22
Parity MultiSig Wallet - Vulnerability
User
MultiSig Wallet Smart Contract
Ethereum BlockChain
Local Web Page
Ethereum
Client
23
Wallet的constructor
轉呼叫_walletLibrary.initWallet()
Wallet的fallback function,可直接轉錢
或轉呼叫_walletLibrary的函式
_walletLibrary的contract address
錢包合約被分成兩部分
Wallet contract
與
Library contract
使用者只需deployed
較短的Wallet contract
實作內容已用Library方式
放在區塊鏈上
可節省使用者
deployed的成本
24
initWallet()實作部分
設定daily limit
設定owner
1. Deployed Wallet Contract
2. Wallet constructor called
3. _walletLibrary.initWallet() called
4. _walletLibrary.initDaylimit() and _walletLibrary.initOwner() called
25
Parity MultiSig Wallet - Vulnerability
Parity MultiSig Wallet - Vulnerability
• 問題在於你以為_walletLibrary.initWallet()只會被呼叫一次
• 你以為它只會被constructor呼叫
• 但是Solidity預設所有function若沒有指定,均是public function
• 但wallet contract內沒有initWallet()的進入點啊?
26
27
Hacker :
執行多簽錢包合約0xabc
的initWallet(hacker)
多簽錢包
Smart Contract
0xabc
Owner : A, B
但0xabc內沒有initWallet()
進入到fallback function
delegatecall()進而向
_walletLibrary內找尋有沒有initWallet()
找到initWallet()
成功重新將owner覆蓋
攻擊路徑
多簽錢包
Smart Contract
0xabc
Owner : hacker
Exploit成功
• 補救措施
28
https://github.c
om/paritytech/
parity/pull/6103
/files#diff-
8ea4aa7c2ba715
c683bc764337f5
1585
• Impact
• Over $30 Million lost
• 153K Ether
• Hacker only control 3/596 multisig wallets
• All the Parity multisig wallet are vulnerable
• User need to change their multisig wallet
29
Parity MultiSig Wallet - Vulnerability
DApp - DAO
• Decentralized Autonomous Organization (去中心化自治組織)
30
https://themerkle.com/the-dao-crowdsale-shatters-ethereum-funding-total/
35
DApp – The DAO
假設匯率 Ξ (Ether) : Ð (Dao Token) = 1 : 1
5 Ð 3 Ð 2 Ð
Total : 10 Ξ
立法院DAO
三人都有投票權決定如何使用這10 Ξ
依擁較多的Ð說話比較大聲
三個政黨都有投票權決定如何使用總預算
席次較多較多的說話比較大聲
5 Ð 3 Ð 2 Ð
Total : 10 Ξ ► 5 Ξ
立法院DAO
大家決議花5 Ξ 做投資
最後收益獲得20 Ξ
每個人都有投票權可將收益挹注回總資金中
或是將收益注入獎勵金內(成員可依照比例領回)
Income: 20 Ξ
36
立法院DAO
每個人都可以提案將DAO split出去
以避免多數暴力
提案後需投票
投下贊成票的才可將自己的份額split出去
DApp – The DAO
5 Ð 3 Ð 2 Ð
Total : 10 Ξ
立法院DAO
5 Ð 3 Ð
Total : 8 Ξ
藍色黨
立法院DAO
1 Ð
Total : 2 Ξ
Split
Parent DAO Child DAO
靠,你們
都霸凌我
Ξ : Ð
=
2 : 1
DApp – The DAO
37
2016/05/29 2016/06/17 2016/07/24
ICO : 2016/04/30 ~ 2016/05/28
$1.5 Billion
38
DApp – The DAO
2016/06/17
Hacker stole
over $150 million
from The DAO
(Almost the 1/3 funds)
2016/06/17
Ethereum stopped
all transactions
2016/06/18
Ethereum launched DDoS
to slow down blackhat hacker
And let whitehat hacker
to withdraw the rest of funds
2016/07/24
The Ethereum Classic
was born
2016/07/21
Ethereum launched
the hark fork for Ethereum
The DAO - Vulnerability
• splitDAO()
1. 從parent DAO移動資金到child DAO
2. 將原本在parent DAO中的獎勵做結算,發給想split的成員
3. Split完成,已無DAO token在parent DAO內,全數移轉至child DAO
39
40
The DAO - Vulnerability
從parent DAO移動資金到child DAO
原本在parent DAO中的獎勵做結算,發給想split的成員
Split完成,已無DAO token在parent DAO內,全數移轉至child DAO
41
The DAO - Vulnerability
計算此成員有多少reward
發出reward給該成員
在Ethereum真正發送ether的動作
• 問題出在送ether的function : _recipient.call.value(_amount)()
• 此function為了方便,後面第二個括號
讓contract可以在收到錢的時候,可以自訂去call別的function
例如寫log等等
• 此處沒有帶function name, 預設會呼叫接收者的fallback function
• Fallback function讓hacker有機會再次遞迴呼叫splitDAO()
• 但此時並沒有將帳戶結清
• DAO內還是有錢
• 持續遞迴呼叫,直到gas耗盡,或是達到stack size limit
42
The DAO - Vulnerability
43
The DAO - Vulnerability
從parent DAO移動資金到child DAO
原本在parent DAO中的獎勵做結算,發給想split的成員
Split完成,已無DAO token在parent DAO內,全數移轉至child DAO
• Impact
• Over $150 million lost
• Ethereum hard fork
• The DAO fail
44
The DAO - Vulnerability
Conclusion – 你買單嗎?
• 智能合約成功開啟人們對於區塊鏈的想像
• 但智能合約是個複雜的東西
• 想像一下你連中文合約都看不太懂了(甲方、乙方、民事訴訟法)
• 更何況這個合約用code寫成
• The DAO 與 Parity 內部都有許多經驗豐富的工程師
• 他們都會犯錯了,那一般人呢?
• Blockchain 2.0正式產生,創造區塊鏈更多的未來
45
Thank you for you attention!
46

More Related Content

Similar to Blockchain 2.0 : Smart Contract 的美麗與哀愁

投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈Yao-Wei Ou
 
智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介Nicholas Lin
 
Ethereum Smart Contract Development
Ethereum Smart Contract DevelopmentEthereum Smart Contract Development
Ethereum Smart Contract DevelopmentTitan gene
 
blockchain course (chinese)
blockchain course (chinese)blockchain course (chinese)
blockchain course (chinese)Moving Up Mobile
 
區塊鏈懂不懂
區塊鏈懂不懂區塊鏈懂不懂
區塊鏈懂不懂Nic Lin
 
20201006 meta_coin 六角學院
20201006 meta_coin 六角學院20201006 meta_coin 六角學院
20201006 meta_coin 六角學院Hu Kenneth
 
Blockchain 101 & 201
Blockchain 101 & 201Blockchain 101 & 201
Blockchain 101 & 201Benson Sun
 
blockchain&cryptocurrency
blockchain&cryptocurrencyblockchain&cryptocurrency
blockchain&cryptocurrencySean Liu
 
20160230联动技术大讲堂xx(刘胜)区块链应用研究1初探v1.2.0305
20160230联动技术大讲堂xx(刘胜)区块链应用研究1初探v1.2.030520160230联动技术大讲堂xx(刘胜)区块链应用研究1初探v1.2.0305
20160230联动技术大讲堂xx(刘胜)区块链应用研究1初探v1.2.0305liu sheng
 
区块链原理
区块链原理区块链原理
区块链原理Noah Chen
 
Polkadot 治理
Polkadot 治理Polkadot 治理
Polkadot 治理Anson Lau
 
區塊鏈懂不懂 (2020/01/02 快樂學程式)
區塊鏈懂不懂 (2020/01/02 快樂學程式)區塊鏈懂不懂 (2020/01/02 快樂學程式)
區塊鏈懂不懂 (2020/01/02 快樂學程式)Nic Lin
 
AirBit Club Mandarin Presentation
AirBit Club Mandarin Presentation AirBit Club Mandarin Presentation
AirBit Club Mandarin Presentation airbitclub
 
NFT 与数字商品的未来
NFT 与数字商品的未来NFT 与数字商品的未来
NFT 与数字商品的未来Jedi Lu
 
Blockchain introduction for sharing
Blockchain introduction for sharingBlockchain introduction for sharing
Blockchain introduction for sharingLman Chu
 
Introduction of IOTA and MAM
Introduction of IOTA and MAMIntroduction of IOTA and MAM
Introduction of IOTA and MAMYangHao Yuan
 
在 Kotlin/Android 使用 Ethereum Smart Contract
在 Kotlin/Android 使用 Ethereum Smart Contract在 Kotlin/Android 使用 Ethereum Smart Contract
在 Kotlin/Android 使用 Ethereum Smart ContractYenwen Feng
 
2011年10月创业投资与并购报告 资本实验室
2011年10月创业投资与并购报告 资本实验室2011年10月创业投资与并购报告 资本实验室
2011年10月创业投资与并购报告 资本实验室coinsay
 

Similar to Blockchain 2.0 : Smart Contract 的美麗與哀愁 (20)

投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈
 
智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介
 
Ethereum Smart Contract Development
Ethereum Smart Contract DevelopmentEthereum Smart Contract Development
Ethereum Smart Contract Development
 
blockchain course (chinese)
blockchain course (chinese)blockchain course (chinese)
blockchain course (chinese)
 
區塊鏈懂不懂
區塊鏈懂不懂區塊鏈懂不懂
區塊鏈懂不懂
 
20201006 meta_coin 六角學院
20201006 meta_coin 六角學院20201006 meta_coin 六角學院
20201006 meta_coin 六角學院
 
Blockchain 101 & 201
Blockchain 101 & 201Blockchain 101 & 201
Blockchain 101 & 201
 
blockchain&cryptocurrency
blockchain&cryptocurrencyblockchain&cryptocurrency
blockchain&cryptocurrency
 
20160230联动技术大讲堂xx(刘胜)区块链应用研究1初探v1.2.0305
20160230联动技术大讲堂xx(刘胜)区块链应用研究1初探v1.2.030520160230联动技术大讲堂xx(刘胜)区块链应用研究1初探v1.2.0305
20160230联动技术大讲堂xx(刘胜)区块链应用研究1初探v1.2.0305
 
区块链原理
区块链原理区块链原理
区块链原理
 
区块链游
区块链游区块链游
区块链游
 
Polkadot 治理
Polkadot 治理Polkadot 治理
Polkadot 治理
 
區塊鏈懂不懂 (2020/01/02 快樂學程式)
區塊鏈懂不懂 (2020/01/02 快樂學程式)區塊鏈懂不懂 (2020/01/02 快樂學程式)
區塊鏈懂不懂 (2020/01/02 快樂學程式)
 
AirBit Club Mandarin Presentation
AirBit Club Mandarin Presentation AirBit Club Mandarin Presentation
AirBit Club Mandarin Presentation
 
Blockchain
BlockchainBlockchain
Blockchain
 
NFT 与数字商品的未来
NFT 与数字商品的未来NFT 与数字商品的未来
NFT 与数字商品的未来
 
Blockchain introduction for sharing
Blockchain introduction for sharingBlockchain introduction for sharing
Blockchain introduction for sharing
 
Introduction of IOTA and MAM
Introduction of IOTA and MAMIntroduction of IOTA and MAM
Introduction of IOTA and MAM
 
在 Kotlin/Android 使用 Ethereum Smart Contract
在 Kotlin/Android 使用 Ethereum Smart Contract在 Kotlin/Android 使用 Ethereum Smart Contract
在 Kotlin/Android 使用 Ethereum Smart Contract
 
2011年10月创业投资与并购报告 资本实验室
2011年10月创业投资与并购报告 资本实验室2011年10月创业投资与并购报告 资本实验室
2011年10月创业投资与并购报告 资本实验室
 

Blockchain 2.0 : Smart Contract 的美麗與哀愁

  • 1. Blockchain 2.0 : Tom Yang Smart Contract 的美麗與哀愁Smart Contract 的美麗與哀愁 https://bitsonblocks.net/2016/02/01/a- gentle-introduction-to-smart-contracts/
  • 2. Blockchain 1.0 • BitCoin 與 數位貨幣 • 分散式帳本 • 去中心化貨幣 • Immutable https://datafloq.com/read/what-is-the-blockchain-and-why-is-it-so-important/2270 2
  • 4. Why BitCoin = Blockchain 1.0 • Blockchain橫空出世 • 分散式帳本 • 去中心化 • 數位貨幣的新里程碑 • 各式各樣的數位貨幣開始出現 • 就只是個數位貨幣 • 但區塊鏈的特性應該可以保存更多數位資產 4
  • 5. Ethereum 5 Wiki : “以太坊是一個開源的有智慧型合約功能的公共區塊鏈平台。” “ It provides a decentralized Turing-complete virtual machine, the Ethereum Virtual Machine (EVM), which can execute scripts using an international network of public nodes. “
  • 6. Ethereum • EVM是一個建立在區塊鏈上的VM • 想像你想執行的邏輯、儲存空間甚至運算單元都在區塊鏈上 • 於以太坊上所有動作於圖靈完備的EVM上做操作 • 每種動作(Operation)分別消耗不同的ether(以太幣) • 手續費只與Operation相關,只與工作量相關 • 有了圖靈完備的EVM,就可以在區塊鏈上做更多的事 • 在區塊鏈上寫程式 • Smart Contract 智能合約 6
  • 7. Blockchain 2.0 • Smart Contract 智能合約 7 Traditional Contract Smart Contract Coding Deploy
  • 8. Smart Contract 智能合約 • Code is Law (Code is Contract) • 程式碼即法律 (程式碼即合約) • 程式碼對於合約有相同的理解 • 去中心化 • 智能 非指 人工智能 • 程式碼僅執行複雜的規則和條件,不具學習功能 • 電梯 • 販賣機 • Contract address內與一般Account address一樣,都可放入以太幣 8 https://www.youtube.com/watch?v=uFBu2P1mwFU
  • 9. Smart Contract on Ethereum : Construction 9 Smart Contract Compile Programming Language : Solidity (JS-like) Serpent (Python-like) … EVM bytecode 6060604052341561000c57fe5b5b6 0ae8061001b6000396000f3006060 6040526000357c010000000000000 0000000000000000000000000000 000000000000000900463ffffffff16 80633c4308a814603a575bfe5b341 5604157fe5b605e60048080359060 2001909190803590602001909190 50506074565b6040518082815260 200191505060405180910390f35b6 00081830290505b929150505600a 165627a7a72305820c40f61d36a3a 1b7064b58c57c89d5c3d7c73b911 6230f9948806b11836d2960c0029 Deploy Deploy on Ethereun = Transaction on Ethereum Contract address : 0xabc
  • 10. Smart Contract on Ethereum 10 https://etherscan.io/address/0x5a2a454675c1b659caa58b5675ee759b992b84b1#code
  • 11. Smart Contract on Ethereum 11
  • 12. Smart Contract on Ethereum : Execution 12 Address : 0xabc Smart Contract on blcokchain Transaction Execute : placeBet() Output Return : “Success”
  • 13. Smart Contract on Ethereum • 認識名詞 • Gas : 每個動作都需要耗費燃料的單位 • Gas Price : 每個gas要的ether • Gas Limit : 執行所有動作的gas消耗上限 • Contract : Deploy在以太坊上的動作集合 13 https://www.cryptocompare.com/coins/guides/what-is-the-gas-in-ethereum/
  • 14. From Smart Contract to Decentralized application (DApp) • Normal application = Frontend + Backend • Decentralized application = Frontend + BlockChain • DApp on Ethereum = Frontend + Smart Contracts 14https://ethereum.stackexchange.com/questions/383/what-is-a-dapp
  • 15. DApp - ICO • Initial Coin Offerings • ICO on Ethereum: Publish your own token (for specific purpose) • Change ether into token • Rather than create your own BlockChain • Only thing you need to do is write a contract on the Ethereum 15 去中心化超級電腦去中心化市場預測平台 https://www.bnext.com.tw/article/44959/what-is-ethereum-and-how-ico-become-the-reason-that-ether-exceeds-bitcoin $5.2 million $8.6 million $35 million in 30 sec 去中心化透明數位廣告平台 BAT
  • 16. DApp - ICO • ERC20 Standard • Describes the functions and events that an Ethereum token contract has to implement 16
  • 17. DApp - ICO • Pros • 數位貨幣(代幣)蓬勃發展 • 更多的DApp產生 • Cons • Lack of supervision • Fraud • 大型ICO所造成的塞車現象 17
  • 18. DApp – MultiSig Wallet • Multi-Signature Wallet (多簽錢包) 18 傳統錢包 0xaaa (Account Address) Owner (Private key owner) 只需單一owner即可動用位址內的資產 多簽錢包 0xabc (Smart Contract Address) Owner : A, B, C Multi-Owner 需單一至多位owner做確認 才可動用位址內的資產
  • 19. DApp – MultiSig Wallet • 零用錢多簽錢包,owner : 家長, 小孩 19 多簽錢包 Smart Contract Daily limit : 100 Owner : 家長, 小孩 小孩 Transaction 我要買午餐,領80 傳送80給小孩 沒超過Daily limit家長
  • 20. DApp – MultiSig Wallet • 零用錢多簽錢包,owner : 家長, 小孩 20 多簽錢包 Smart Contract Daily limit : 100 Owner : 家長, 小孩 Transaction 我要繳房租,領1000 須等另一Owner確認 超過Daily limit Transaction 好的,給領1000 傳送1000給小孩 確認完成 小孩家長
  • 22. • Parity MultiSig Wallet Structure 22 Parity MultiSig Wallet - Vulnerability User MultiSig Wallet Smart Contract Ethereum BlockChain Local Web Page Ethereum Client
  • 23. 23 Wallet的constructor 轉呼叫_walletLibrary.initWallet() Wallet的fallback function,可直接轉錢 或轉呼叫_walletLibrary的函式 _walletLibrary的contract address 錢包合約被分成兩部分 Wallet contract 與 Library contract 使用者只需deployed 較短的Wallet contract 實作內容已用Library方式 放在區塊鏈上 可節省使用者 deployed的成本
  • 25. 1. Deployed Wallet Contract 2. Wallet constructor called 3. _walletLibrary.initWallet() called 4. _walletLibrary.initDaylimit() and _walletLibrary.initOwner() called 25 Parity MultiSig Wallet - Vulnerability
  • 26. Parity MultiSig Wallet - Vulnerability • 問題在於你以為_walletLibrary.initWallet()只會被呼叫一次 • 你以為它只會被constructor呼叫 • 但是Solidity預設所有function若沒有指定,均是public function • 但wallet contract內沒有initWallet()的進入點啊? 26
  • 27. 27 Hacker : 執行多簽錢包合約0xabc 的initWallet(hacker) 多簽錢包 Smart Contract 0xabc Owner : A, B 但0xabc內沒有initWallet() 進入到fallback function delegatecall()進而向 _walletLibrary內找尋有沒有initWallet() 找到initWallet() 成功重新將owner覆蓋 攻擊路徑 多簽錢包 Smart Contract 0xabc Owner : hacker Exploit成功
  • 29. • Impact • Over $30 Million lost • 153K Ether • Hacker only control 3/596 multisig wallets • All the Parity multisig wallet are vulnerable • User need to change their multisig wallet 29 Parity MultiSig Wallet - Vulnerability
  • 30. DApp - DAO • Decentralized Autonomous Organization (去中心化自治組織) 30 https://themerkle.com/the-dao-crowdsale-shatters-ethereum-funding-total/
  • 31. 35 DApp – The DAO 假設匯率 Ξ (Ether) : Ð (Dao Token) = 1 : 1 5 Ð 3 Ð 2 Ð Total : 10 Ξ 立法院DAO 三人都有投票權決定如何使用這10 Ξ 依擁較多的Ð說話比較大聲 三個政黨都有投票權決定如何使用總預算 席次較多較多的說話比較大聲 5 Ð 3 Ð 2 Ð Total : 10 Ξ ► 5 Ξ 立法院DAO 大家決議花5 Ξ 做投資 最後收益獲得20 Ξ 每個人都有投票權可將收益挹注回總資金中 或是將收益注入獎勵金內(成員可依照比例領回) Income: 20 Ξ
  • 32. 36 立法院DAO 每個人都可以提案將DAO split出去 以避免多數暴力 提案後需投票 投下贊成票的才可將自己的份額split出去 DApp – The DAO 5 Ð 3 Ð 2 Ð Total : 10 Ξ 立法院DAO 5 Ð 3 Ð Total : 8 Ξ 藍色黨 立法院DAO 1 Ð Total : 2 Ξ Split Parent DAO Child DAO 靠,你們 都霸凌我 Ξ : Ð = 2 : 1
  • 33. DApp – The DAO 37 2016/05/29 2016/06/17 2016/07/24 ICO : 2016/04/30 ~ 2016/05/28 $1.5 Billion
  • 34. 38 DApp – The DAO 2016/06/17 Hacker stole over $150 million from The DAO (Almost the 1/3 funds) 2016/06/17 Ethereum stopped all transactions 2016/06/18 Ethereum launched DDoS to slow down blackhat hacker And let whitehat hacker to withdraw the rest of funds 2016/07/24 The Ethereum Classic was born 2016/07/21 Ethereum launched the hark fork for Ethereum
  • 35. The DAO - Vulnerability • splitDAO() 1. 從parent DAO移動資金到child DAO 2. 將原本在parent DAO中的獎勵做結算,發給想split的成員 3. Split完成,已無DAO token在parent DAO內,全數移轉至child DAO 39
  • 36. 40 The DAO - Vulnerability 從parent DAO移動資金到child DAO 原本在parent DAO中的獎勵做結算,發給想split的成員 Split完成,已無DAO token在parent DAO內,全數移轉至child DAO
  • 37. 41 The DAO - Vulnerability 計算此成員有多少reward 發出reward給該成員 在Ethereum真正發送ether的動作
  • 38. • 問題出在送ether的function : _recipient.call.value(_amount)() • 此function為了方便,後面第二個括號 讓contract可以在收到錢的時候,可以自訂去call別的function 例如寫log等等 • 此處沒有帶function name, 預設會呼叫接收者的fallback function • Fallback function讓hacker有機會再次遞迴呼叫splitDAO() • 但此時並沒有將帳戶結清 • DAO內還是有錢 • 持續遞迴呼叫,直到gas耗盡,或是達到stack size limit 42 The DAO - Vulnerability
  • 39. 43 The DAO - Vulnerability 從parent DAO移動資金到child DAO 原本在parent DAO中的獎勵做結算,發給想split的成員 Split完成,已無DAO token在parent DAO內,全數移轉至child DAO
  • 40. • Impact • Over $150 million lost • Ethereum hard fork • The DAO fail 44 The DAO - Vulnerability
  • 41. Conclusion – 你買單嗎? • 智能合約成功開啟人們對於區塊鏈的想像 • 但智能合約是個複雜的東西 • 想像一下你連中文合約都看不太懂了(甲方、乙方、民事訴訟法) • 更何況這個合約用code寫成 • The DAO 與 Parity 內部都有許多經驗豐富的工程師 • 他們都會犯錯了,那一般人呢? • Blockchain 2.0正式產生,創造區塊鏈更多的未來 45
  • 42. Thank you for you attention! 46

Editor's Notes

  1. 衍伸出的公司行號與組織
  2. Ethereum was proposed in late 2013 by Vitalik Buterin, a cryptocurrency researcher and programmer. Development was funded by an online crowdsale that took place between July and August 2014.[6] The system went live on 30 July 2015, with 11.9 million coins "premined" for the crowdsale.[7] This accounts for about 13 percent of the total circulating supply. BornJanuary 31, 1994 Kolomna, Russia 簡單的理解就是,如果一個語言是圖靈完備的,需要該語言支援迴圈語句,支援分支語句,支援迴圈和遞迴,理論上可以解決任何演算法,但也有可能進入死迴圈而導致系統崩潰。 比特幣指令碼不是圖靈完備的,因為它沒有條件判斷語句,不能執行迴圈,也不會產生遞迴。
  3. 重複轉五次錢的差別 那為什麼有 Ether 還要有 gasPrice? 因為如果不把兩個參數解藕, 當 Ether 大漲的時候, 手續費會變得不合理 Transaction Fees交易費用 = 實際用到Gas Limit * Gas Price https://cryptonews.com.hk/2017/11/20/ethereum以太坊-gas-price-vs-gas-limit-小知識/
  4. A與B規定事項 寫在區塊鏈上 租房子合約 每個月固定匯錢給房東 如果沒匯錢 房東就來換鎖 寫成智能合約 每個月戶定要有錢收到 否則門鎖密碼會被AU 一樣有礦工幫我把我的東西包進區塊鏈
  5. 有限的Immutable
  6. 到底怎麼放上區塊鏈? High level programming language
  7. Lotthereum https://etherscan.io/address/0x5a2a454675c1b659caa58b5675ee759b992b84b1#code
  8. Lotthereum https://etherscan.io/address/0x5a2a454675c1b659caa58b5675ee759b992b84b1#code
  9. https://etherscan.io/tx/0xe0f53995aebedfc301b98e17978d7683739978aaffda8c531dd0f81d53a9742f 裡面和約會寫明如何開獎
  10. gas price可自訂
  11. Smart contract 給人更多想像 去中心化應用程式 介紹三個
  12. http://blockcast.it/2017/06/19/ico-knowledge-and-participate-methods-basics/ 用你的ether換token Initial Public Offerings IPO 首次公開發行股票 https://www.sohu.com/a/161769416_114778 https://www.cryptocompare.com/coins/guides/how-does-an-ico-work/ Golem Golem想要用網路上閒置的算力,打造全球最大的去中心化超級電腦,讓全世界更有效地利用被浪費的電腦能源,目標是做成「Airbnb for Computers」,ICO募集了860萬美元。 Augurˈôgər Augur想要做成區塊鏈預測市場平台,集眾人之力得到更精準的結果,可以提出任何問題做市場的預測,任何人可以買賣對結果的預期,換句話說就是一個超大賭場而且沒有特定莊家,所以不用怕會賭場會倒莊不認帳跑路。 Basic Attention Token(BAT)則是基於以太坊的去中心化透明數位廣告平台,用區塊鏈技術來賦予注意力有價的系統,沒有一個中心公司像是Google或Facebook這樣的公司來蒐集你的數據,隱私數據不會被洩露,用戶若對廣告花費注意力會獲得BAT代幣獎勵,內容商吸引到用戶的注意力能夠獲得大部分的廣告收入BAT代幣,而廣告商付出的錢能夠大幅提高數位廣告的投放效率。
  13. 2015/11乙太坊基金會推出 基本上你只要定義好在你的生態圈中要怎樣使用你的代幣 要怎麼換你的代幣等等就可以了 https://medium.com/myethacademy/到底什麼是erc-20-49d052e8d290 https://ethereum.org/token
  14. https://www.ptt.cc/bbs/DigiCurrency/M.1498120094.A.39A.html
  15. 讓這個錢包有更多不同的操作空間與想像 例如 第三方支付
  16. 2017/07/19 So far, 150,000 ethers, worth $30 million, have been reported by the company as stolen, data confirmed by Etherscan.io. As reported by the startup, the issue is the result of a bug in a specific multi-signature contract known as wallet.sol. Data suggests the issue was mitigated, however, as 377,000 ethers that were potentially vulnerable to the issue were recovered by white hat hackers.
  17. 也就是說 當你建立一個多簽錢包的同時 其實是產生一個智能合約在以太坊上
  18. 假定wallet就只有這幾個含式 Constructor 存錢 領錢 還有一個withdraw沒寫 很方便的fallback function 如果function在contract內找不到 就會進入 讓你做特別的處理
  19. 很方便 因為早就鋪好路了 但也很不方便 因為其他人已經把合約上上區塊鏈了 只好請大家把錢移出來
  20. 知名的以太坊(Ethereum)客戶端軟體Parity上周三(7/19)證實其以太幣錢包(Parity Wallet)含有一安全漏洞,讓駭客從3個以太幣錢包中盜走了逾15.3萬個以太幣(Ether),折合市值超過3000萬美元。
  21. 去中心化自治組織
  22. 去中心化自治組織 持續發展共生
  23. 去中心化自治組織
  24. 去中心化自治組織
  25. 去中心化自治組織
  26. 柯文哲 蔡英文 馬英九
  27. https://coinmarketcap.com/assets/the-dao/
  28. withdrawRewardFor內是允許讓駭客做外部執行 也就是說讓駭客可以重新呼叫splitDAO