SlideShare une entreprise Scribd logo
1  sur  34
智慧合約
SMART CONTRACT
林修平
CONTRACT
• 什麼是合約?
• 雙方或多方基於意思表示而成立的法律行為
• 買賣、租賃、保險、投資等
• 履約方式:主動、被動
“SMART” CONTRACT
• 履約方式:自動執行
• 前提:條件達成
• “SMART”? How?
• 生活中的智慧合約:
• 自動販賣機
• U-bike, 線上投注
• 和自動化服務有什麼不一樣?
“SMART” CONTRACT
smart contract on blockchain
• 有什麼差別?
• 區塊鏈的價值?
• 相信誰?
• 一個人?
• 一家企業?
https://en.wikipedia.org/wiki/Financial_crisis_of_2007–08
• 政府?
https://en.wikipedia.org/wiki/Watergate_scandal
• 或程式碼和數學原理?
• 選擇權在你手上
• 和沒有信任基礎的對象達成共識
smart contract on blockchain
• https://www.thenewslens.com/article/11796
• 會自動購買洗衣粉的洗衣機
• 在沒有區塊鏈的情況下
• 金流:
• 銀行、第三方支付 -> 洗衣粉公司 -> 貨運公司
• 成本:
• 時間和人力檢查、核對金流和物流狀況
• 如果今天其中某一環節出錯了?
• 要花多久的時間發現問題?
• 誰會發現問題?
• 消費者要等多久?
smart contract on blockchain
• https://www.thenewslens.com/article/11796
• 會自動購買洗衣粉的洗衣機
• 在有區塊鏈的情況下
• 金流:
• 銀行、第三方支付 -> 洗衣粉公司 -> 貨運公司
• 成本:
• 物流狀況檢查
• 如果今天其中某一環節出錯了?
• 要花多久的時間發現問題?
• 誰會發現問題?
• 消費者要等多久?
smart contract on blockchain
BLOCKCHAIN + IOT
• IOT
• 連網裝置?
• 裝置互連
• 要怎麼確保連上的是不是惡意的裝置?
• 要怎麼確保裝置所說的話是可信的?
• 有同樣的共識、同樣的資訊
• 分散式?
• 還要考慮裝置的硬體資源
• 多中心?
BLOCKCHAIN + IOT?
• IOT裝置的問題
• 安全
• 硬體資源
BLOCKCHAIN + IOT?
CHALLENGE
CHALLENGE
• 外部資訊
• 資產流動性
• 鏈外的掌控
• 假設你和朋友對賭明天的比賽分數
• 智慧合約要怎麼獲取分數這個資訊?
• 去抓取外部資訊?
• 要相信哪個來源?
• 每個節點都能從同樣一個來源獲得資訊嗎?
• 這個資訊會過期嗎?不見嗎?隨時間改變嗎?
• 目前區塊鏈上的智慧合約不支援主動抓取外部資訊
• 由第三方提供
CHALLENGE
• 外部資訊
• 資產流動性
• 鏈外的掌控
• 如果你向保險公司買了一份保險,你付的保費會一直待在“某個地
方”嗎?
• 像銀行儲蓄一樣,這筆錢會被保險公司或銀行拿去進行投資
等行為,讓效益最大化,直到你需要這筆錢
• 那這樣要怎麼確保智慧合約執行的效力?
CHALLENGE
• 外部資訊
• 資產流動性
• 鏈外的掌控
• 並非所有事情皆可在鏈上完成,那鏈外的行為要怎麼執行?
• 由法律管道?
Ethereum smart contract
Ethereum smart contract
• 圖靈完備
• 條件分支(conditional branching)
• 迴圈
• 改變任意數量的記憶體
Ethereum smart contract
• 比特幣
• 圖靈不完備
• OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF
• 不保存狀態
• stack-based language
• 不支援迴圈
• 有意的設計
• 避免複雜的計算及無窮迴圈的可能性
Ethereum smart contract
• 圖靈完備
• 條件分支(conditional branching)
• 迴圈
• 改變任意數量的記憶體
• 能做到更複雜、更強大的功能
• 怎麼對付無窮迴圈等的惡意攻擊?
• gas
• 每種運算都有相對應的成本(gas)
• 花了多少gas就要付出相對的錢,但使用者可以自己決定每單位gas的價錢
• 用ether支付
Ethereum smart contract
• 要怎麼建立合約?
• 1. 寫合約
Ethereum smart contract
• 要怎麼建立合約?
• 1. 寫合約
• 2. 編譯合約,轉成bytecode
Ethereum smart contract
• 要怎麼建立合約?
• 1. 寫合約
• 2. 編譯合約,轉成
bytecode
• 3. 廣播並等待被放入區
塊中
Ethereum smart contract
• 要怎麼建立合約?
• 1. 寫合約
• 2. 編譯合約,轉成
bytecode
• 3. 廣播並等待被放入區
塊中
• 4. 執行合約
Ethereum smart contract
• 合約語言
• Serpent
• python-like
• Solidity
• javascript-like
Ethereum smart contract
• 要怎麼建立合約?
• 1. 寫合約
• 2. 編譯合約,轉成bytecode
• 3. 廣播並等待被放入區塊中
• 4. 執行合約
https://ethereum.github.io/browser-solidity/
https://github.com/ethereum/go-
ethereum/wiki/Building-Ethereum
https://github.com/ethereum/mist/releases
living example : DAO
living example : DAO
• Decentralized Autonomous Organization
• by slock.it
• crowdfunding
• vote by your share
• profit by your share
• child DAO
• to prevent abuse of majority voting
living example : DAO
• Recursive calling vulnerability
• propose a split -> execute the split -> withdraw
• propose a split -> execute the split -> propose a split ->
execute the split -> withdraw
living example : DAO
• function splitDAO
problem1
problem2
living example : DAO
• function withdrawRewardFor
problem1
living example : DAO
• function payOut
problem1
• address.call.value(amount)
• supply with enough gas
• if address refers to a contract, it triggers fallback function
• do what whatever you want as long as enough gas remaining
• call to splitDAO again in fallback function
living example : DAO
• function splitDAO
problem2
• cleans up his/her balance after sending the money
living example : DAO
• counter measure :
• use address.send(amount)
• 2300 gas
• don’t execute address.call.value(amount) to untrusted code
• limit gas in address.call.value(amount)
• address.call.gas(gas_amount).value(amount)
• cleans up the balance before sending money
• then check if sending succed, if not ,rollback
living example : DAO
• what happens after?
• votes for hard fork
• choose to stay, becomes ETC
• choose to fork, becomes ETH
• Ethereum foundation, token holders, immutability believers
• too much money to fail? lawsuits?
• what do you believe?

Contenu connexe

Tendances

What is tokenization in blockchain?
What is tokenization in blockchain?What is tokenization in blockchain?
What is tokenization in blockchain?Ulf Mattsson
 
QuillAudit Smart contracts audit ppt - https://audits.quillhash.com
QuillAudit Smart contracts audit ppt - https://audits.quillhash.comQuillAudit Smart contracts audit ppt - https://audits.quillhash.com
QuillAudit Smart contracts audit ppt - https://audits.quillhash.comPreetam Rao
 
How To Build A Career In Blockchain
How To Build A Career In BlockchainHow To Build A Career In Blockchain
How To Build A Career In Blockchain101 Blockchains
 
Examples of Smart Contracts
Examples of Smart ContractsExamples of Smart Contracts
Examples of Smart Contracts101 Blockchains
 
Understanding the Basics of Decentralized Applications (dApps)
Understanding the Basics of Decentralized Applications (dApps)Understanding the Basics of Decentralized Applications (dApps)
Understanding the Basics of Decentralized Applications (dApps)Capital Numbers
 
Basics of Bitcoin & Mining
Basics of Bitcoin & MiningBasics of Bitcoin & Mining
Basics of Bitcoin & MiningAkhilesh Arora
 
Introduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxIntroduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxGene Leybzon
 
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.jsFelix Crisan
 
Smart contractjp smartcontract_about
Smart contractjp smartcontract_aboutSmart contractjp smartcontract_about
Smart contractjp smartcontract_aboutTomoaki Sato
 
Learning Solidity
Learning SolidityLearning Solidity
Learning SolidityArnold Pham
 
The Potential of Blockchain Technology
The Potential of Blockchain TechnologyThe Potential of Blockchain Technology
The Potential of Blockchain TechnologyPioneers.io
 
01 - Introduction to Hyperledger : A Blockchain Technology for Business
01 - Introduction to Hyperledger : A Blockchain Technology for Business01 - Introduction to Hyperledger : A Blockchain Technology for Business
01 - Introduction to Hyperledger : A Blockchain Technology for BusinessMerlec Mpyana
 
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...Edureka!
 
Blockchain Training | Blockchain Tutorial for Beginners | Blockchain Technolo...
Blockchain Training | Blockchain Tutorial for Beginners | Blockchain Technolo...Blockchain Training | Blockchain Tutorial for Beginners | Blockchain Technolo...
Blockchain Training | Blockchain Tutorial for Beginners | Blockchain Technolo...Edureka!
 
An Introduction to Blockchain Technology
An Introduction to Blockchain Technology An Introduction to Blockchain Technology
An Introduction to Blockchain Technology Niuversity
 
Blockchain Study(1) - What is Blockchain?
Blockchain Study(1) - What is Blockchain?Blockchain Study(1) - What is Blockchain?
Blockchain Study(1) - What is Blockchain?Fermat Jade
 

Tendances (20)

Erc 721 tokens
Erc 721 tokensErc 721 tokens
Erc 721 tokens
 
What is tokenization in blockchain?
What is tokenization in blockchain?What is tokenization in blockchain?
What is tokenization in blockchain?
 
QuillAudit Smart contracts audit ppt - https://audits.quillhash.com
QuillAudit Smart contracts audit ppt - https://audits.quillhash.comQuillAudit Smart contracts audit ppt - https://audits.quillhash.com
QuillAudit Smart contracts audit ppt - https://audits.quillhash.com
 
What is merkle tree
What is merkle treeWhat is merkle tree
What is merkle tree
 
How To Build A Career In Blockchain
How To Build A Career In BlockchainHow To Build A Career In Blockchain
How To Build A Career In Blockchain
 
Examples of Smart Contracts
Examples of Smart ContractsExamples of Smart Contracts
Examples of Smart Contracts
 
Understanding the Basics of Decentralized Applications (dApps)
Understanding the Basics of Decentralized Applications (dApps)Understanding the Basics of Decentralized Applications (dApps)
Understanding the Basics of Decentralized Applications (dApps)
 
Basics of Bitcoin & Mining
Basics of Bitcoin & MiningBasics of Bitcoin & Mining
Basics of Bitcoin & Mining
 
Smart contract
Smart contractSmart contract
Smart contract
 
Blockchain and Cryptocurrency for Dummies
Blockchain and Cryptocurrency for DummiesBlockchain and Cryptocurrency for Dummies
Blockchain and Cryptocurrency for Dummies
 
Introduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxIntroduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptx
 
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.js
 
Smart contractjp smartcontract_about
Smart contractjp smartcontract_aboutSmart contractjp smartcontract_about
Smart contractjp smartcontract_about
 
Learning Solidity
Learning SolidityLearning Solidity
Learning Solidity
 
The Potential of Blockchain Technology
The Potential of Blockchain TechnologyThe Potential of Blockchain Technology
The Potential of Blockchain Technology
 
01 - Introduction to Hyperledger : A Blockchain Technology for Business
01 - Introduction to Hyperledger : A Blockchain Technology for Business01 - Introduction to Hyperledger : A Blockchain Technology for Business
01 - Introduction to Hyperledger : A Blockchain Technology for Business
 
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
 
Blockchain Training | Blockchain Tutorial for Beginners | Blockchain Technolo...
Blockchain Training | Blockchain Tutorial for Beginners | Blockchain Technolo...Blockchain Training | Blockchain Tutorial for Beginners | Blockchain Technolo...
Blockchain Training | Blockchain Tutorial for Beginners | Blockchain Technolo...
 
An Introduction to Blockchain Technology
An Introduction to Blockchain Technology An Introduction to Blockchain Technology
An Introduction to Blockchain Technology
 
Blockchain Study(1) - What is Blockchain?
Blockchain Study(1) - What is Blockchain?Blockchain Study(1) - What is Blockchain?
Blockchain Study(1) - What is Blockchain?
 

Similaire à 智能合約結合區塊鏈簡介

Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Tom Yang
 
20201006 meta_coin 六角學院
20201006 meta_coin 六角學院20201006 meta_coin 六角學院
20201006 meta_coin 六角學院Hu Kenneth
 
ICO、智能合約與代幣經濟
ICO、智能合約與代幣經濟ICO、智能合約與代幣經濟
ICO、智能合約與代幣經濟InfiniteChain
 
區塊鏈創新基地 - 區塊鏈
區塊鏈創新基地 - 區塊鏈區塊鏈創新基地 - 區塊鏈
區塊鏈創新基地 - 區塊鏈Hu Kenneth
 
A tour of ethereum ecosystem
A tour of ethereum ecosystemA tour of ethereum ecosystem
A tour of ethereum ecosystemChang-Wu Chen
 
[Crypto Course] Blockchain Security
[Crypto Course] Blockchain Security[Crypto Course] Blockchain Security
[Crypto Course] Blockchain SecurityWEI CHIEH CHAO
 
Blockchain Development Presentation part-2
Blockchain Development Presentation part-2Blockchain Development Presentation part-2
Blockchain Development Presentation part-2Clement Hsieh
 
Blockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlokcert
 
在 Kotlin/Android 使用 Ethereum Smart Contract
在 Kotlin/Android 使用 Ethereum Smart Contract在 Kotlin/Android 使用 Ethereum Smart Contract
在 Kotlin/Android 使用 Ethereum Smart ContractYenwen Feng
 
Cn 321 universal de fi derivatives protocol light-whitepaper v1
Cn 321 universal de fi derivatives protocol light-whitepaper v1Cn 321 universal de fi derivatives protocol light-whitepaper v1
Cn 321 universal de fi derivatives protocol light-whitepaper v1ssuser4cb3b1
 
《氪周刊:互联网创业必读》(第43期)
《氪周刊:互联网创业必读》(第43期)《氪周刊:互联网创业必读》(第43期)
《氪周刊:互联网创业必读》(第43期)36Kr.com
 
Using Substrate to Develop a DApp Chain
Using Substrate to Develop a DApp ChainUsing Substrate to Develop a DApp Chain
Using Substrate to Develop a DApp ChainKaichao Sun
 
Smart Contract Automation Test
Smart Contract Automation Test Smart Contract Automation Test
Smart Contract Automation Test Louis Liao
 
數位口碑經濟時代書摘 蕭培元
數位口碑經濟時代書摘 蕭培元數位口碑經濟時代書摘 蕭培元
數位口碑經濟時代書摘 蕭培元培元 蕭
 
Solidity 智能合约开发 - 基础
Solidity 智能合约开发 - 基础Solidity 智能合约开发 - 基础
Solidity 智能合约开发 - 基础YuZHANG198949
 

Similaire à 智能合約結合區塊鏈簡介 (16)

Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁
 
20201006 meta_coin 六角學院
20201006 meta_coin 六角學院20201006 meta_coin 六角學院
20201006 meta_coin 六角學院
 
ICO、智能合約與代幣經濟
ICO、智能合約與代幣經濟ICO、智能合約與代幣經濟
ICO、智能合約與代幣經濟
 
區塊鏈創新基地 - 區塊鏈
區塊鏈創新基地 - 區塊鏈區塊鏈創新基地 - 區塊鏈
區塊鏈創新基地 - 區塊鏈
 
A tour of ethereum ecosystem
A tour of ethereum ecosystemA tour of ethereum ecosystem
A tour of ethereum ecosystem
 
[Crypto Course] Blockchain Security
[Crypto Course] Blockchain Security[Crypto Course] Blockchain Security
[Crypto Course] Blockchain Security
 
Blockchain Development Presentation part-2
Blockchain Development Presentation part-2Blockchain Development Presentation part-2
Blockchain Development Presentation part-2
 
Blockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlockchain Tutorial for Lawyers
Blockchain Tutorial for Lawyers
 
Blockchain in Action
Blockchain in ActionBlockchain in Action
Blockchain in Action
 
在 Kotlin/Android 使用 Ethereum Smart Contract
在 Kotlin/Android 使用 Ethereum Smart Contract在 Kotlin/Android 使用 Ethereum Smart Contract
在 Kotlin/Android 使用 Ethereum Smart Contract
 
Cn 321 universal de fi derivatives protocol light-whitepaper v1
Cn 321 universal de fi derivatives protocol light-whitepaper v1Cn 321 universal de fi derivatives protocol light-whitepaper v1
Cn 321 universal de fi derivatives protocol light-whitepaper v1
 
《氪周刊:互联网创业必读》(第43期)
《氪周刊:互联网创业必读》(第43期)《氪周刊:互联网创业必读》(第43期)
《氪周刊:互联网创业必读》(第43期)
 
Using Substrate to Develop a DApp Chain
Using Substrate to Develop a DApp ChainUsing Substrate to Develop a DApp Chain
Using Substrate to Develop a DApp Chain
 
Smart Contract Automation Test
Smart Contract Automation Test Smart Contract Automation Test
Smart Contract Automation Test
 
數位口碑經濟時代書摘 蕭培元
數位口碑經濟時代書摘 蕭培元數位口碑經濟時代書摘 蕭培元
數位口碑經濟時代書摘 蕭培元
 
Solidity 智能合约开发 - 基础
Solidity 智能合约开发 - 基础Solidity 智能合约开发 - 基础
Solidity 智能合约开发 - 基础
 

Plus de Nicholas Lin

Ethereum wallet Intro 以太坊錢包介紹
Ethereum wallet Intro 以太坊錢包介紹Ethereum wallet Intro 以太坊錢包介紹
Ethereum wallet Intro 以太坊錢包介紹Nicholas Lin
 
區塊鏈智能合約應用於點數平台之架構
區塊鏈智能合約應用於點數平台之架構區塊鏈智能合約應用於點數平台之架構
區塊鏈智能合約應用於點數平台之架構Nicholas Lin
 
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)Nicholas Lin
 
部署並執行以太坊智能合約
部署並執行以太坊智能合約部署並執行以太坊智能合約
部署並執行以太坊智能合約Nicholas Lin
 
以太坊智能合約撰寫簡單教學
以太坊智能合約撰寫簡單教學以太坊智能合約撰寫簡單教學
以太坊智能合約撰寫簡單教學Nicholas Lin
 
Intro to smart contract on blockchain en
Intro to smart contract on blockchain enIntro to smart contract on blockchain en
Intro to smart contract on blockchain enNicholas Lin
 
Solidity Simple Tutorial EN
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial ENNicholas Lin
 
CopyRightContractDemo
CopyRightContractDemoCopyRightContractDemo
CopyRightContractDemoNicholas Lin
 

Plus de Nicholas Lin (8)

Ethereum wallet Intro 以太坊錢包介紹
Ethereum wallet Intro 以太坊錢包介紹Ethereum wallet Intro 以太坊錢包介紹
Ethereum wallet Intro 以太坊錢包介紹
 
區塊鏈智能合約應用於點數平台之架構
區塊鏈智能合約應用於點數平台之架構區塊鏈智能合約應用於點數平台之架構
區塊鏈智能合約應用於點數平台之架構
 
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
 
部署並執行以太坊智能合約
部署並執行以太坊智能合約部署並執行以太坊智能合約
部署並執行以太坊智能合約
 
以太坊智能合約撰寫簡單教學
以太坊智能合約撰寫簡單教學以太坊智能合約撰寫簡單教學
以太坊智能合約撰寫簡單教學
 
Intro to smart contract on blockchain en
Intro to smart contract on blockchain enIntro to smart contract on blockchain en
Intro to smart contract on blockchain en
 
Solidity Simple Tutorial EN
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial EN
 
CopyRightContractDemo
CopyRightContractDemoCopyRightContractDemo
CopyRightContractDemo
 

智能合約結合區塊鏈簡介

  • 2. CONTRACT • 什麼是合約? • 雙方或多方基於意思表示而成立的法律行為 • 買賣、租賃、保險、投資等 • 履約方式:主動、被動
  • 4. • 履約方式:自動執行 • 前提:條件達成 • “SMART”? How? • 生活中的智慧合約: • 自動販賣機 • U-bike, 線上投注 • 和自動化服務有什麼不一樣? “SMART” CONTRACT
  • 5. smart contract on blockchain
  • 6. • 有什麼差別? • 區塊鏈的價值? • 相信誰? • 一個人? • 一家企業? https://en.wikipedia.org/wiki/Financial_crisis_of_2007–08 • 政府? https://en.wikipedia.org/wiki/Watergate_scandal • 或程式碼和數學原理? • 選擇權在你手上 • 和沒有信任基礎的對象達成共識 smart contract on blockchain
  • 7. • https://www.thenewslens.com/article/11796 • 會自動購買洗衣粉的洗衣機 • 在沒有區塊鏈的情況下 • 金流: • 銀行、第三方支付 -> 洗衣粉公司 -> 貨運公司 • 成本: • 時間和人力檢查、核對金流和物流狀況 • 如果今天其中某一環節出錯了? • 要花多久的時間發現問題? • 誰會發現問題? • 消費者要等多久? smart contract on blockchain
  • 8. • https://www.thenewslens.com/article/11796 • 會自動購買洗衣粉的洗衣機 • 在有區塊鏈的情況下 • 金流: • 銀行、第三方支付 -> 洗衣粉公司 -> 貨運公司 • 成本: • 物流狀況檢查 • 如果今天其中某一環節出錯了? • 要花多久的時間發現問題? • 誰會發現問題? • 消費者要等多久? smart contract on blockchain
  • 10. • IOT • 連網裝置? • 裝置互連 • 要怎麼確保連上的是不是惡意的裝置? • 要怎麼確保裝置所說的話是可信的? • 有同樣的共識、同樣的資訊 • 分散式? • 還要考慮裝置的硬體資源 • 多中心? BLOCKCHAIN + IOT?
  • 11. • IOT裝置的問題 • 安全 • 硬體資源 BLOCKCHAIN + IOT?
  • 13. CHALLENGE • 外部資訊 • 資產流動性 • 鏈外的掌控 • 假設你和朋友對賭明天的比賽分數 • 智慧合約要怎麼獲取分數這個資訊? • 去抓取外部資訊? • 要相信哪個來源? • 每個節點都能從同樣一個來源獲得資訊嗎? • 這個資訊會過期嗎?不見嗎?隨時間改變嗎? • 目前區塊鏈上的智慧合約不支援主動抓取外部資訊 • 由第三方提供
  • 14. CHALLENGE • 外部資訊 • 資產流動性 • 鏈外的掌控 • 如果你向保險公司買了一份保險,你付的保費會一直待在“某個地 方”嗎? • 像銀行儲蓄一樣,這筆錢會被保險公司或銀行拿去進行投資 等行為,讓效益最大化,直到你需要這筆錢 • 那這樣要怎麼確保智慧合約執行的效力?
  • 15. CHALLENGE • 外部資訊 • 資產流動性 • 鏈外的掌控 • 並非所有事情皆可在鏈上完成,那鏈外的行為要怎麼執行? • 由法律管道?
  • 17. Ethereum smart contract • 圖靈完備 • 條件分支(conditional branching) • 迴圈 • 改變任意數量的記憶體
  • 18. Ethereum smart contract • 比特幣 • 圖靈不完備 • OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF • 不保存狀態 • stack-based language • 不支援迴圈 • 有意的設計 • 避免複雜的計算及無窮迴圈的可能性
  • 19. Ethereum smart contract • 圖靈完備 • 條件分支(conditional branching) • 迴圈 • 改變任意數量的記憶體 • 能做到更複雜、更強大的功能 • 怎麼對付無窮迴圈等的惡意攻擊? • gas • 每種運算都有相對應的成本(gas) • 花了多少gas就要付出相對的錢,但使用者可以自己決定每單位gas的價錢 • 用ether支付
  • 20. Ethereum smart contract • 要怎麼建立合約? • 1. 寫合約
  • 21. Ethereum smart contract • 要怎麼建立合約? • 1. 寫合約 • 2. 編譯合約,轉成bytecode
  • 22. Ethereum smart contract • 要怎麼建立合約? • 1. 寫合約 • 2. 編譯合約,轉成 bytecode • 3. 廣播並等待被放入區 塊中
  • 23. Ethereum smart contract • 要怎麼建立合約? • 1. 寫合約 • 2. 編譯合約,轉成 bytecode • 3. 廣播並等待被放入區 塊中 • 4. 執行合約
  • 24. Ethereum smart contract • 合約語言 • Serpent • python-like • Solidity • javascript-like
  • 25. Ethereum smart contract • 要怎麼建立合約? • 1. 寫合約 • 2. 編譯合約,轉成bytecode • 3. 廣播並等待被放入區塊中 • 4. 執行合約 https://ethereum.github.io/browser-solidity/ https://github.com/ethereum/go- ethereum/wiki/Building-Ethereum https://github.com/ethereum/mist/releases
  • 27. living example : DAO • Decentralized Autonomous Organization • by slock.it • crowdfunding • vote by your share • profit by your share • child DAO • to prevent abuse of majority voting
  • 28. living example : DAO • Recursive calling vulnerability • propose a split -> execute the split -> withdraw • propose a split -> execute the split -> propose a split -> execute the split -> withdraw
  • 29. living example : DAO • function splitDAO problem1 problem2
  • 30. living example : DAO • function withdrawRewardFor problem1
  • 31. living example : DAO • function payOut problem1 • address.call.value(amount) • supply with enough gas • if address refers to a contract, it triggers fallback function • do what whatever you want as long as enough gas remaining • call to splitDAO again in fallback function
  • 32. living example : DAO • function splitDAO problem2 • cleans up his/her balance after sending the money
  • 33. living example : DAO • counter measure : • use address.send(amount) • 2300 gas • don’t execute address.call.value(amount) to untrusted code • limit gas in address.call.value(amount) • address.call.gas(gas_amount).value(amount) • cleans up the balance before sending money • then check if sending succed, if not ,rollback
  • 34. living example : DAO • what happens after? • votes for hard fork • choose to stay, becomes ETC • choose to fork, becomes ETH • Ethereum foundation, token holders, immutability believers • too much money to fail? lawsuits? • what do you believe?