SlideShare a Scribd company logo
1 of 34
SMART
CONTRACT
林修平
CONTRACT
• What’s a contract?
• voluntary arrangement between two or more parties
• legally binding agreement
• buying, selling, renting, leasing, insurance, investment, etc.
• actively or inactively perform
“SMART” CONTRACT
• How to perform : self-enforcing , self executing
• preliminary: terms matched
• “SMART”? How?
• Smart Contract in real-life:
• vending machine
• U-bike, on-line gambling
• what’s the difference between smart contract and automated
service?
“SMART” CONTRACT
smart contract on blockchain
• What differences does it make?
• value of Blockchain
• whom to trust?
• a person?
• a company?
https://en.wikipedia.org/wiki/Financial_crisis_of_2007–08
• government?
https://en.wikipedia.org/wiki/Watergate_scandal
• or program and mathematics?
• its totally up to you
• reach an agreement with untrustful party
smart contract on blockchain
• https://www.thenewslens.com/article/11796
• a washing machine that can buy detergent itself if needed
• without blockchain
• cash flow :
• online payment -> companies that sells detergent -> transportation companies
• what’s the cost?
• time, efforts on checking status and verify
• what if something went wrong?
• how long does it take to find out the problem?
• who will find out the problem?
• how long do I have to wait?
smart contract on blockchain
• https://www.thenewslens.com/article/11796
• a washing machine that can buy detergent itself if needed
• with blockchain
• cash flow :
• online payment -> companies that sells detergent -> transportation companies
• what’s the cost?
• transaction fee
• what if something went wrong?
• how long does it take to find out the problem?
• who will find out the problem?
• how long do I have to wait?
smart contract on blockchain
BLOCKCHAIN + IOT
• IOT
• a device connecting to Internet?
• machine to machine
• how does it make sure it is not talking to a malicious node?
• can try
• how to make sure what it says is true?
• share same information
• distributed?
• can an IOT device provide such capability in its storage unit?
• decentralized?
BLOCKCHAIN + IOT?
• main problems in IOT
• Security
• hardware resource
BLOCKCHAIN + IOT?
CHALLENGE
CHALLENGE
• External Information
• Liquidity
• has no control beyond ledgers
• say you start a bet on tomorrow’s game score…
• how do you provide the score to smart contract?
• fetch the source from outside?
• which source to trust?
• can everyone fetch from the same source?
• will it expire? disappear? change from time to time?
• for now, smart contracts on blockchain can not fetch external information itself
• provided by third party
CHALLENGE
• External Information
• Liquidity
• has no control beyond ledgers
• suppose you start an insurance contract with insurance
company, is the money you pay monthly going to stay in there
indefinitely?
• no, like deposit in a bank, the company will make the best
out of the money which means the money will only be
there when something happened…
• then, how can the terms in smart contract be enforced?
CHALLENGE
• External Information
• Liquidity
• has no control beyond ledgers
• How do you enforce in the real world? probably by litigation
• but how is smart contract different from legacy contract?
Ethereum smart contract
Ethereum smart contract
• Turing Complete
• conditional branching
• loop
• ability to change arbitrary amount of memory
Ethereum smart contract
• Bitcoin
• Turing incompleteness
• OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF
• stateless
• stack-based language
• no loop
• made purposely
• prevent costly and infinite computation
Ethereum smart contract
• Turing Complete
• conditional branching
• loop
• ability to change arbitrary amount of memory
• powerful
• how to deal with malicious code, e.g. infinite loop?
• gas
• each operation has a price(gas)
• pay for gas where user decides how much to pay per unit gas
• pay with ether
Ethereum smart contract
• How does it work?
• 1. write your contract
Ethereum smart contract
• How does it work?
• 1. write your contract
• 2. compile it to byte code
Ethereum smart contract
• How does it work?
• 1. write your contract
• 2. compile it to byte
code
• 3. broadcasted and
mined
Ethereum smart contract
• How does it work?
• 1. write your contract
• 2. compile it to byte
code
• 3. broadcasted and
mined
• 4. invoke transaction
Ethereum smart contract
• contract language
• Serpent
• python-like
• Solidity
• javascript-like
Ethereum smart contract
• How does it work?
• 1. write your contract
• 2. compile it to byte code
• 3. broadcasted and mined
• 4. invoke transaction
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?

More Related Content

What's hot

What's hot (20)

Blockchain Basics
Blockchain BasicsBlockchain Basics
Blockchain Basics
 
Blockchain Powerpoint Presentation Slides
Blockchain Powerpoint Presentation SlidesBlockchain Powerpoint Presentation Slides
Blockchain Powerpoint Presentation Slides
 
Introduction to Blockchain
Introduction to Blockchain Introduction to Blockchain
Introduction to Blockchain
 
Ethereum 2.0
Ethereum 2.0Ethereum 2.0
Ethereum 2.0
 
Blockchain Smart Contract v5
Blockchain   Smart Contract v5Blockchain   Smart Contract v5
Blockchain Smart Contract v5
 
Blockchain
BlockchainBlockchain
Blockchain
 
Blockchain and Decentralization
Blockchain and DecentralizationBlockchain and Decentralization
Blockchain and Decentralization
 
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 Technology
Blockchain TechnologyBlockchain Technology
Blockchain Technology
 
Understanding hd wallets design and implementation
Understanding hd wallets  design and implementationUnderstanding hd wallets  design and implementation
Understanding hd wallets design and implementation
 
Types of blockchain
Types of blockchainTypes of blockchain
Types of blockchain
 
Blockchain and Banking
Blockchain and BankingBlockchain and Banking
Blockchain and Banking
 
Blockchain consensus algorithms
Blockchain consensus algorithmsBlockchain consensus algorithms
Blockchain consensus algorithms
 
Developing applications with Hyperledger Fabric SDK
Developing applications with Hyperledger Fabric SDKDeveloping applications with Hyperledger Fabric SDK
Developing applications with Hyperledger Fabric SDK
 
Bitcoin presentation slides
Bitcoin presentation slidesBitcoin presentation slides
Bitcoin presentation slides
 
what is bitcoin, its history and detail
what is bitcoin, its history and detailwhat is bitcoin, its history and detail
what is bitcoin, its history and detail
 
Blockchain Technology Fundamentals
Blockchain Technology FundamentalsBlockchain Technology Fundamentals
Blockchain Technology Fundamentals
 
Everything Blockchain Presentation - Feb 2022
Everything Blockchain Presentation -  Feb 2022Everything Blockchain Presentation -  Feb 2022
Everything Blockchain Presentation - Feb 2022
 
Hyperledger fabric 20180528
Hyperledger fabric 20180528Hyperledger fabric 20180528
Hyperledger fabric 20180528
 
Bitcoin
BitcoinBitcoin
Bitcoin
 

Viewers also liked

Blockchain Smart Contracts - getting from hype to reality
Blockchain Smart Contracts - getting from hype to reality Blockchain Smart Contracts - getting from hype to reality
Blockchain Smart Contracts - getting from hype to reality
Capgemini
 

Viewers also liked (20)

部署並執行以太坊智能合約
部署並執行以太坊智能合約部署並執行以太坊智能合約
部署並執行以太坊智能合約
 
以太坊智能合約撰寫簡單教學
以太坊智能合約撰寫簡單教學以太坊智能合約撰寫簡單教學
以太坊智能合約撰寫簡單教學
 
智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介
 
Solidity Simple Tutorial EN
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial EN
 
Blockchain Smart Contracts - getting from hype to reality
Blockchain Smart Contracts - getting from hype to reality Blockchain Smart Contracts - getting from hype to reality
Blockchain Smart Contracts - getting from hype to reality
 
區塊鏈智能合約應用於點數平台之架構
區塊鏈智能合約應用於點數平台之架構區塊鏈智能合約應用於點數平台之架構
區塊鏈智能合約應用於點數平台之架構
 
CopyRightContractDemo
CopyRightContractDemoCopyRightContractDemo
CopyRightContractDemo
 
Defining Smart Contracts
Defining Smart ContractsDefining Smart Contracts
Defining Smart Contracts
 
以比特幣為例的區塊鏈技術介紹 ( 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)
 
Blockchain, smart contracts - introduction
Blockchain, smart contracts - introductionBlockchain, smart contracts - introduction
Blockchain, smart contracts - introduction
 
Introduction to blockchain and smart contracts
Introduction to blockchain and smart contractsIntroduction to blockchain and smart contracts
Introduction to blockchain and smart contracts
 
從開發人員角度十分鐘理解區塊鏈技術
從開發人員角度十分鐘理解區塊鏈技術從開發人員角度十分鐘理解區塊鏈技術
從開發人員角度十分鐘理解區塊鏈技術
 
Blockchain and Smart Contract Long Term Security (updated)
Blockchain and Smart Contract Long Term Security (updated)Blockchain and Smart Contract Long Term Security (updated)
Blockchain and Smart Contract Long Term Security (updated)
 
區塊鏈科技趨勢與應用
區塊鏈科技趨勢與應用區塊鏈科技趨勢與應用
區塊鏈科技趨勢與應用
 
Smart contracts
Smart contractsSmart contracts
Smart contracts
 
State Of Smart Contract Platforms from Smart Contract JP
State Of Smart Contract Platforms from Smart Contract JP State Of Smart Contract Platforms from Smart Contract JP
State Of Smart Contract Platforms from Smart Contract JP
 
Writing smart contracts
Writing smart contractsWriting smart contracts
Writing smart contracts
 
BlockChain, Bitcoin and Smart Contracts - Oleg Kudrenko
BlockChain, Bitcoin and Smart Contracts - Oleg KudrenkoBlockChain, Bitcoin and Smart Contracts - Oleg Kudrenko
BlockChain, Bitcoin and Smart Contracts - Oleg Kudrenko
 
Hacking Finance: Crypto & Math based Currencies, Smart contracts and Blockch...
Hacking Finance: Crypto & Math based Currencies, Smart contracts  and Blockch...Hacking Finance: Crypto & Math based Currencies, Smart contracts  and Blockch...
Hacking Finance: Crypto & Math based Currencies, Smart contracts and Blockch...
 
Effacts Academy - Smart Contract Management
Effacts Academy - Smart Contract ManagementEffacts Academy - Smart Contract Management
Effacts Academy - Smart Contract Management
 

Similar to Intro to smart contract on blockchain en

Similar to Intro to smart contract on blockchain en (20)

Smart contractjp smartcontract_about
Smart contractjp smartcontract_aboutSmart contractjp smartcontract_about
Smart contractjp smartcontract_about
 
Privacy Preserving Paradigms of Blockchain Technology
Privacy Preserving Paradigms of Blockchain TechnologyPrivacy Preserving Paradigms of Blockchain Technology
Privacy Preserving Paradigms of Blockchain Technology
 
Blockchain
BlockchainBlockchain
Blockchain
 
Blockchain tutorial for MBA
Blockchain tutorial for MBABlockchain tutorial for MBA
Blockchain tutorial for MBA
 
Practical Challenges for Public Blockchains
Practical Challenges for Public BlockchainsPractical Challenges for Public Blockchains
Practical Challenges for Public Blockchains
 
Practical Challenges for Public Blockchains
Practical Challenges for Public BlockchainsPractical Challenges for Public Blockchains
Practical Challenges for Public Blockchains
 
Blockchain
BlockchainBlockchain
Blockchain
 
blockchain and iot: Opportunities and Challanges
blockchain and iot: Opportunities and Challangesblockchain and iot: Opportunities and Challanges
blockchain and iot: Opportunities and Challanges
 
From 7331 to legal : a selection of blockchain discussion topics
From 7331 to legal : a selection of blockchain discussion topicsFrom 7331 to legal : a selection of blockchain discussion topics
From 7331 to legal : a selection of blockchain discussion topics
 
20190316 - CLBFest - 1337 to legal - Koen Vingerhoets
20190316 - CLBFest - 1337 to legal - Koen Vingerhoets20190316 - CLBFest - 1337 to legal - Koen Vingerhoets
20190316 - CLBFest - 1337 to legal - Koen Vingerhoets
 
Is Blockchain Right for You? The Million Dollar Question
Is Blockchain Right for You? The Million Dollar QuestionIs Blockchain Right for You? The Million Dollar Question
Is Blockchain Right for You? The Million Dollar Question
 
Blockchain
Blockchain Blockchain
Blockchain
 
Demystifying Smart Contracts
Demystifying Smart ContractsDemystifying Smart Contracts
Demystifying Smart Contracts
 
Blockchain Projects - Core Pillars of Shipping Product, Feb 2018
Blockchain Projects - Core Pillars of Shipping Product, Feb 2018Blockchain Projects - Core Pillars of Shipping Product, Feb 2018
Blockchain Projects - Core Pillars of Shipping Product, Feb 2018
 
What is bitcoin?
What is bitcoin?What is bitcoin?
What is bitcoin?
 
Week 4 - DApps, Smart Contracts, and Decentralized Incentive Systems
Week 4 - DApps, Smart Contracts, and Decentralized Incentive SystemsWeek 4 - DApps, Smart Contracts, and Decentralized Incentive Systems
Week 4 - DApps, Smart Contracts, and Decentralized Incentive Systems
 
Block chain
Block chainBlock chain
Block chain
 
Blockchain in enterprise - Challenges, Considerations and Designs
Blockchain in enterprise - Challenges, Considerations and DesignsBlockchain in enterprise - Challenges, Considerations and Designs
Blockchain in enterprise - Challenges, Considerations and Designs
 
How to not Destroy Millions in Smart Contracts
How to not Destroy Millions in Smart ContractsHow to not Destroy Millions in Smart Contracts
How to not Destroy Millions in Smart Contracts
 
Smart Contract & Ethereum
Smart Contract & EthereumSmart Contract & Ethereum
Smart Contract & Ethereum
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Intro to smart contract on blockchain en

  • 2. CONTRACT • What’s a contract? • voluntary arrangement between two or more parties • legally binding agreement • buying, selling, renting, leasing, insurance, investment, etc. • actively or inactively perform
  • 4. • How to perform : self-enforcing , self executing • preliminary: terms matched • “SMART”? How? • Smart Contract in real-life: • vending machine • U-bike, on-line gambling • what’s the difference between smart contract and automated service? “SMART” CONTRACT
  • 5. smart contract on blockchain
  • 6. • What differences does it make? • value of Blockchain • whom to trust? • a person? • a company? https://en.wikipedia.org/wiki/Financial_crisis_of_2007–08 • government? https://en.wikipedia.org/wiki/Watergate_scandal • or program and mathematics? • its totally up to you • reach an agreement with untrustful party smart contract on blockchain
  • 7. • https://www.thenewslens.com/article/11796 • a washing machine that can buy detergent itself if needed • without blockchain • cash flow : • online payment -> companies that sells detergent -> transportation companies • what’s the cost? • time, efforts on checking status and verify • what if something went wrong? • how long does it take to find out the problem? • who will find out the problem? • how long do I have to wait? smart contract on blockchain
  • 8. • https://www.thenewslens.com/article/11796 • a washing machine that can buy detergent itself if needed • with blockchain • cash flow : • online payment -> companies that sells detergent -> transportation companies • what’s the cost? • transaction fee • what if something went wrong? • how long does it take to find out the problem? • who will find out the problem? • how long do I have to wait? smart contract on blockchain
  • 10. • IOT • a device connecting to Internet? • machine to machine • how does it make sure it is not talking to a malicious node? • can try • how to make sure what it says is true? • share same information • distributed? • can an IOT device provide such capability in its storage unit? • decentralized? BLOCKCHAIN + IOT?
  • 11. • main problems in IOT • Security • hardware resource BLOCKCHAIN + IOT?
  • 13. CHALLENGE • External Information • Liquidity • has no control beyond ledgers • say you start a bet on tomorrow’s game score… • how do you provide the score to smart contract? • fetch the source from outside? • which source to trust? • can everyone fetch from the same source? • will it expire? disappear? change from time to time? • for now, smart contracts on blockchain can not fetch external information itself • provided by third party
  • 14. CHALLENGE • External Information • Liquidity • has no control beyond ledgers • suppose you start an insurance contract with insurance company, is the money you pay monthly going to stay in there indefinitely? • no, like deposit in a bank, the company will make the best out of the money which means the money will only be there when something happened… • then, how can the terms in smart contract be enforced?
  • 15. CHALLENGE • External Information • Liquidity • has no control beyond ledgers • How do you enforce in the real world? probably by litigation • but how is smart contract different from legacy contract?
  • 17. Ethereum smart contract • Turing Complete • conditional branching • loop • ability to change arbitrary amount of memory
  • 18. Ethereum smart contract • Bitcoin • Turing incompleteness • OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF • stateless • stack-based language • no loop • made purposely • prevent costly and infinite computation
  • 19. Ethereum smart contract • Turing Complete • conditional branching • loop • ability to change arbitrary amount of memory • powerful • how to deal with malicious code, e.g. infinite loop? • gas • each operation has a price(gas) • pay for gas where user decides how much to pay per unit gas • pay with ether
  • 20. Ethereum smart contract • How does it work? • 1. write your contract
  • 21. Ethereum smart contract • How does it work? • 1. write your contract • 2. compile it to byte code
  • 22. Ethereum smart contract • How does it work? • 1. write your contract • 2. compile it to byte code • 3. broadcasted and mined
  • 23. Ethereum smart contract • How does it work? • 1. write your contract • 2. compile it to byte code • 3. broadcasted and mined • 4. invoke transaction
  • 24. Ethereum smart contract • contract language • Serpent • python-like • Solidity • javascript-like
  • 25. Ethereum smart contract • How does it work? • 1. write your contract • 2. compile it to byte code • 3. broadcasted and mined • 4. invoke transaction 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?