SlideShare a Scribd company logo
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

PDF
Ethereum-Cryptocurrency (All about Ethereum)
PDF
PoW vs. PoS - Key Differences
PDF
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
PDF
An Introduction to Blockchain Technology
PPTX
Blockchain Technology
PDF
Blockchain: The New Technology and Its Applications for Libraries
PPTX
Blockchain Interview Questions And Answers | Blockchain Technology Interview ...
PDF
Blockchain and Decentralization
Ethereum-Cryptocurrency (All about Ethereum)
PoW vs. PoS - Key Differences
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
An Introduction to Blockchain Technology
Blockchain Technology
Blockchain: The New Technology and Its Applications for Libraries
Blockchain Interview Questions And Answers | Blockchain Technology Interview ...
Blockchain and Decentralization

What's hot (20)

PDF
Blockchain Presentation
PPTX
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
PPTX
Blockchain Basics
PDF
Blockchain Technology Fundamentals
PDF
Examples of Smart Contracts
PPTX
A Secure Model of IoT Using Blockchain
PPTX
Blockchain Smart Contract v5
PPTX
Ethereum Smart contract
PPTX
Blockchain 101
PPTX
Blockchain use cases
PPTX
Smart Contract & Ethereum
PDF
How does blockchain work
PDF
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
PPTX
Blockchain ppt
PPTX
IoT and Blockchain Challenges and Risks
PDF
Overview of blockchain technology and architecture
 
PDF
Blockchain
PDF
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
PDF
Blockchain Technology and Its Application in Libraries
PPTX
Blockchain Technology
Blockchain Presentation
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Blockchain Basics
Blockchain Technology Fundamentals
Examples of Smart Contracts
A Secure Model of IoT Using Blockchain
Blockchain Smart Contract v5
Ethereum Smart contract
Blockchain 101
Blockchain use cases
Smart Contract & Ethereum
How does blockchain work
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain ppt
IoT and Blockchain Challenges and Risks
Overview of blockchain technology and architecture
 
Blockchain
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain Technology and Its Application in Libraries
Blockchain Technology
Ad

Viewers also liked (20)

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

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

PDF
All watched over machines of loving grace amsterdam
PPTX
Blockchain for Developers
PDF
Blockchain and smart contracts, what they are and why you should really care ...
PDF
All watched over machines of loving grace
ODP
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
PDF
IRJET- Smart Contracts using Blockchain
PPTX
Chapter 3.pptx
PPTX
Kriptovaluták, hashbányászat és okoscicák
PPTX
Software Modeling of Contracts in Games and Finance, Part 1: 2018-01-10
PPTX
Practical Challenges for Public Blockchains
PPTX
Practical Challenges for Public Blockchains
PDF
OVERVIEW OF SMART CONTRACT IN BLOCKCHAIN TECHNOLOGY
PPTX
Ethereum Block Chain
PPTX
Ethereum Blockchain with Smart contract and ERC20
PDF
Introduction to Blockchain and Smart Contracts
PPTX
Demystifying Smart Contracts
PPTX
Smart Contracts That Learn
PDF
Sarwar sayeed , hector marco gisbert, tom caira ieee
PPTX
Crypto101.pptx
PPTX
Blockchains
All watched over machines of loving grace amsterdam
Blockchain for Developers
Blockchain and smart contracts, what they are and why you should really care ...
All watched over machines of loving grace
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
IRJET- Smart Contracts using Blockchain
Chapter 3.pptx
Kriptovaluták, hashbányászat és okoscicák
Software Modeling of Contracts in Games and Finance, Part 1: 2018-01-10
Practical Challenges for Public Blockchains
Practical Challenges for Public Blockchains
OVERVIEW OF SMART CONTRACT IN BLOCKCHAIN TECHNOLOGY
Ethereum Block Chain
Ethereum Blockchain with Smart contract and ERC20
Introduction to Blockchain and Smart Contracts
Demystifying Smart Contracts
Smart Contracts That Learn
Sarwar sayeed , hector marco gisbert, tom caira ieee
Crypto101.pptx
Blockchains

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
KodekX | Application Modernization Development
PPTX
A Presentation on Artificial Intelligence
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reach Out and Touch Someone: Haptics and Empathic Computing
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
KodekX | Application Modernization Development
A Presentation on Artificial Intelligence
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Monthly Chronicles - July 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Electronic commerce courselecture one. Pdf

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?