SlideShare ist ein Scribd-Unternehmen logo
1 von 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?

Weitere ähnliche Inhalte

Was ist angesagt?

Privado ii unidad 13
Privado ii   unidad 13Privado ii   unidad 13
Privado ii unidad 13vglibota
 
Blockchain and DeFi: Overview
Blockchain and DeFi: OverviewBlockchain and DeFi: Overview
Blockchain and DeFi: OverviewSvetlin Nakov
 
1 antecedentes contratos
1 antecedentes contratos1 antecedentes contratos
1 antecedentes contratosTodoAqui
 
Scaling Ethereum using Zero-Knowledge Proofs
Scaling Ethereum using Zero-Knowledge ProofsScaling Ethereum using Zero-Knowledge Proofs
Scaling Ethereum using Zero-Knowledge ProofsHyojun Kim
 
ENJ-400 Ley de Sociedades Comerciales y Empresas Individuales de Responsabili...
ENJ-400 Ley de Sociedades Comerciales y Empresas Individuales de Responsabili...ENJ-400 Ley de Sociedades Comerciales y Empresas Individuales de Responsabili...
ENJ-400 Ley de Sociedades Comerciales y Empresas Individuales de Responsabili...ENJ
 
Formación del contrato electrónico
Formación del contrato electrónicoFormación del contrato electrónico
Formación del contrato electrónicoJony Ccanto Valle
 
Stable Coins: Currency for a Digitized World
Stable Coins: Currency for a Digitized WorldStable Coins: Currency for a Digitized World
Stable Coins: Currency for a Digitized WorldIonixx Technologies Inc.
 
Sucesión testamentaria y clasificación de los testamentos
Sucesión testamentaria y clasificación de los testamentosSucesión testamentaria y clasificación de los testamentos
Sucesión testamentaria y clasificación de los testamentosFabii Arraez
 
Blockchain Interview Questions and Answers | Blockchain Technology | Blockcha...
Blockchain Interview Questions and Answers | Blockchain Technology | Blockcha...Blockchain Interview Questions and Answers | Blockchain Technology | Blockcha...
Blockchain Interview Questions and Answers | Blockchain Technology | Blockcha...Edureka!
 
Shariah prohibitions and maqasid relating to the islamic capital market
Shariah prohibitions and maqasid relating to the islamic capital marketShariah prohibitions and maqasid relating to the islamic capital market
Shariah prohibitions and maqasid relating to the islamic capital marketSami Uddin
 
HyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfHyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfwonyong hwang
 
Contrato de Deposito
Contrato de DepositoContrato de Deposito
Contrato de DepositoLuis Vargas
 
List of Top 50 Companies Using Blockchain Technology
List of Top 50 Companies Using Blockchain TechnologyList of Top 50 Companies Using Blockchain Technology
List of Top 50 Companies Using Blockchain Technology101 Blockchains
 

Was ist angesagt? (20)

Privado ii unidad 13
Privado ii   unidad 13Privado ii   unidad 13
Privado ii unidad 13
 
La permuta
La permutaLa permuta
La permuta
 
Blockchain and DeFi: Overview
Blockchain and DeFi: OverviewBlockchain and DeFi: Overview
Blockchain and DeFi: Overview
 
1 antecedentes contratos
1 antecedentes contratos1 antecedentes contratos
1 antecedentes contratos
 
Solidity
SoliditySolidity
Solidity
 
Scaling Ethereum using Zero-Knowledge Proofs
Scaling Ethereum using Zero-Knowledge ProofsScaling Ethereum using Zero-Knowledge Proofs
Scaling Ethereum using Zero-Knowledge Proofs
 
ENJ-400 Ley de Sociedades Comerciales y Empresas Individuales de Responsabili...
ENJ-400 Ley de Sociedades Comerciales y Empresas Individuales de Responsabili...ENJ-400 Ley de Sociedades Comerciales y Empresas Individuales de Responsabili...
ENJ-400 Ley de Sociedades Comerciales y Empresas Individuales de Responsabili...
 
Formación del contrato electrónico
Formación del contrato electrónicoFormación del contrato electrónico
Formación del contrato electrónico
 
Stable Coins: Currency for a Digitized World
Stable Coins: Currency for a Digitized WorldStable Coins: Currency for a Digitized World
Stable Coins: Currency for a Digitized World
 
Fondo de Comercio - Derecho Empresario
Fondo de Comercio - Derecho Empresario Fondo de Comercio - Derecho Empresario
Fondo de Comercio - Derecho Empresario
 
Bitcoin & Bitcoin Mining
Bitcoin & Bitcoin MiningBitcoin & Bitcoin Mining
Bitcoin & Bitcoin Mining
 
Layer 2 Scaling Solutions
Layer 2 Scaling SolutionsLayer 2 Scaling Solutions
Layer 2 Scaling Solutions
 
Derecho mercantil
Derecho mercantilDerecho mercantil
Derecho mercantil
 
Sucesión testamentaria y clasificación de los testamentos
Sucesión testamentaria y clasificación de los testamentosSucesión testamentaria y clasificación de los testamentos
Sucesión testamentaria y clasificación de los testamentos
 
Blockchain Interview Questions and Answers | Blockchain Technology | Blockcha...
Blockchain Interview Questions and Answers | Blockchain Technology | Blockcha...Blockchain Interview Questions and Answers | Blockchain Technology | Blockcha...
Blockchain Interview Questions and Answers | Blockchain Technology | Blockcha...
 
Shariah prohibitions and maqasid relating to the islamic capital market
Shariah prohibitions and maqasid relating to the islamic capital marketShariah prohibitions and maqasid relating to the islamic capital market
Shariah prohibitions and maqasid relating to the islamic capital market
 
Erc 721 tokens
Erc 721 tokensErc 721 tokens
Erc 721 tokens
 
HyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfHyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdf
 
Contrato de Deposito
Contrato de DepositoContrato de Deposito
Contrato de Deposito
 
List of Top 50 Companies Using Blockchain Technology
List of Top 50 Companies Using Blockchain TechnologyList of Top 50 Companies Using Blockchain Technology
List of Top 50 Companies Using Blockchain Technology
 

Ähnlich wie 智能合約結合區塊鏈簡介

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
 

Ähnlich wie 智能合約結合區塊鏈簡介 (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 智能合约开发 - 基础
 

Mehr von 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
 
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
 
CopyRightContractDemo
CopyRightContractDemoCopyRightContractDemo
CopyRightContractDemoNicholas Lin
 

Mehr von Nicholas Lin (6)

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
 
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?