Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FinTech Lecture 10 : Smart Contracts

Kenji Saito
December 03, 2021

FinTech Lecture 10 : Smart Contracts

Slides I used for Lecture 10 of FinTech - Financial Innovation and the Internet 2021 Fall at Graduate School of Business and Finance, Waseda University on December 3, 2021.

Kenji Saito

December 03, 2021
Tweet

More Decks by Kenji Saito

Other Decks in Technology

Transcript

  1. Changes in the economy and labor. FinTech — Financial Innovation

    and the Internet 2021 Fall Lecture 10 : Smart Contracts Kenji Saito, Graduate School of Business and Finance, Waseda University Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.1/52
  2. This class is recorded Camera ON is recommended, but not

    required Zoom names : change your names to whatever you want to be called Please link your Zoon names to your real names in your reports Zoom names are important, because if you choose to be called by your real names, still I don’t know whether I should call you by your given or family names You do need to speak often (we are going to have a lot of dialogues) We will use breakout rooms a lot, but those won’t be recorded unless you do it yourselves (need to be allowed) ↑ Well, not so much so far . . . because we are familiarizing ourselves with new concepts first Later on, hopefully we will move to a stage with a lot more dialogues Keep your Zoom client updated! We might use latest features Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.2/52
  3. The lecture slides can be found at : https://speakerdeck.com/ks91 Recording

    and chat text will be posted at Moodle and Discord Trial automatic transcription will be posted at Discord Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.3/52
  4. Schedule (provisional) Lecture 1 9/24 Overview of FinTech (1) •

    Lecture 2 10/1 Overview of FinTech (2) • Lecture 3 10/8 Internet Technology and Governance (1) • Lecture 4 10/15 Internet Technology and Governance (2) • Lecture 5 10/22 Internet Governance and the World of Apps • Lecture 6 10/29 The World of Apps - continued • Lecture 7 11/12 Basics of Cryptography and Blockchain • Lecture 8 11/19 Blockchain • Lecture 9 11/26 Blockchain and Smart Contracts • Lecture 10 12/3 Smart Contracts • Lecture 11 12/10 Further Smart Contracts Lecture 12 12/17 Cyber-Physical Society and Future of Finance Lecture 13 1/7 FinTech Ideathon (1) Lecture 14 1/14 FinTech Ideathon (2) Lecture 15 1/21 Presentations and Conclusions Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.4/52
  5. Last Week, We Did. . . Understanding Blockchain (revisited) Validity/Existence/Uniqueness

    layers Applicability of Blockchain Impossibility and Challenges of Blockchain Up to scaling out, which blockchain doesn’t Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.5/52
  6. Today’s Topics Impossibility and Challenges of Blockchain Continued from the

    last week Brief Introduction to Upgrading and Governance of Blockchain Assignment Review — Science Fiction Prototyping Smart Contracts and Ethereum Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.6/52
  7. Impossibility and Challenges of Blockchain Transitional technology, in the process

    of trial and error In fact, a lot of new designs are being tested If we do not have governance for (or if we do not know how to accommodate) technological changes, we cannot use it in society Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.7/52
  8. Hash Rate Transitions (Jan. 2009 - Nov. 2021) If malicious

    participants gain half of the hash rate, blockchain cannot be guaranteed to work correctly Risky in principle if the hashrate is doubled quickly → It has happened On the other hand, what if it doesn’t double rapidly? → Dilemma of providing room for malicious participants What if it suddenly halves? → Very risky in principle, and it also happened Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.8/52
  9. Reality vs. Blockchain A thought experiment You want to start

    a new business on the beach: If a customer pays in bitcoin, a drone flying overhead will drop them a can of juice When should the drone drop the can? Reality that goes in real-time and blockchain’s behavior are very different But as a business decision, a risk taker can drop the canned juice the moment they detect a payment As long as they are in a position to use social infrastructure, they can act disruptively Not because it is a perfect technology But because it is a fairly cheap platform (cost is paid by the miners) Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.9/52
  10. The DAO Incident (uncovered governance challenges) The DAO, an autonomous

    decentralized investment fund built on Ethereum Split (fund split) was recursively called, and 360,000 ETH (5 to 6 billion yen) was stolen (2016/6/17) Choices Do nothing Soft fork (maintains compatibility → freezes the address of the thief) Funds are not returned Hard fork (No compatibility → rewrites history; who controls the present controls the past) Worst occurrence of “Oneness Trap” (described later) in a sense Community chose “hard fork” ! (executed on 2016/7/20) “Most interesting. Gravity’s silhouette remains, but the star and all its planets have disappeared. How can this be?” “Because someone erased it from the archive memory.” — from Star Wars: Episode II – Attack of the Clones So the incident never happened Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.10/52
  11. Scaling Out Question There is one ATM that always has

    10 people in line Sorry if you are in an advanced environment, and you don’t know what we are talking about (or even wonder what an ATM is) ;) What happens to the number of people in the queue if we add one ATM? Other conditions remain the same cf. Daisuke Yamazaki, “Rethinking Scaling Out” (in Japanese) http://www.slideshare.net/yamaz2/ss-58813038 Performance problems can be solved by adding a server ⇒ The system scales out Blockchain does not scale out in its bare form (because everyone makes and maintains a replica) Improvement is possible if you see it as a KVS (Key-Value Store) Because of the distributed KVS technology But you might lose autonomy Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.11/52
  12. Scaling Out and Blockchain 7PMVNFPG%BUBUP1SPDFTT -PBEQFS/PEF #MPDLDIBJO 1SPQFSMZEFTJHOFEEJTUSJCVUFETZTUFN In blockchain,

    the cost of maintaining data structures rises linearly as transactions increase It does not scale out Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.12/52
  13. Blockchain’s “Oneness Trap” It does not scale out Adding more

    nodes does not solve or mitigate performance challenges Must be “the world is one” to work System does not work correctly if the network is partitioned by a large-scale disasters or political change Difficulty of governance to advance technology You cannot “try something different partially, and if it works, apply it to the whole” Impossibility of governance : Agreement by the “whole” must be maintained, but the “whole” cannot be defined ⇒ Powered few changes the technology instead ⇒ Those are disadvantages of non-decentralized nature of blockchain Conversely, there are great expectations and potential for truly decentralized “record fixation device in the air” Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.13/52
  14. Incentive Mismatch Ethereum cannot survive as an application platform if

    ETH as a currency crashes and declines Supported by miners’ motivation to get ETH When the value of ETH drops, miners withdraw Can people who want to run apps (smart contracts) buy ETH to maintain the price? If ETH’s market participants are primarily app users, may be . . . (but they aren’t) The design of the raw Bitcoin is goal-consistent, but. . . In other words, “Bitcoin cannot survive if BTC declines” would be fine But as proof applications such as Proof of Existence advance, similar problems arise Either way, the future of the system depends on the interests of the miners ⇒ Need to separate application platforms from currency systems That is where the recent ledger technology is going, hopefully (because many still aren’t) Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.14/52
  15. What is the True Worth of Blockchain? Roughly speaking, what’s

    the thing you can never do without blockchain? Ex1 : Digitizing the last will and testament (in a thought-experiment sense) After the death of the person, the private key used for the digital signature may no longer be a secret Can’t believe a notary saying, “it is as signed before the death” (possible collusion with malicious heir) Ex2 : Online banking passbook data as proof (for the liabilities of banks) If you download it as a CSV file, the data anyone can create is not considered as evidence Even with the digital signature of the bank, once the private key is leaked, the data can be created by anyone Prove “data digitally signed at cetain past date has not been tampered with” (instead of believing those who insist so) “The Last Will Test” is to ask them if they can do that with their blockchain A test to see if something that someone has been pitching as “it’s a blockchain” really makes sense An idea (hash-chain with proof of work) that may satisfy this true worth, combined with existing technologies around the idea is the Bitcoin blockchain Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.15/52
  16. How Well Is It Realized Today? Is there a technology

    that can pass the “last will test”? Public blockchain may pass the test while the market value of the native currency is high Defense such that it would cost a lot to tamper with When the price of the native currency drops or crashes it becomes unreliable Private ledger systems in general only insist, so they do not pass the test Mostly, “blockchain made and operated by XXX Inc.” is meaningless ← please be careful We are building new technology to make it pass the test BBc-1 (Beyond Blockchain One; https://github.com/beyond-blockchain) (just an example) There is an inherent challenge of linkage between records and entities Includes areas that cannot be solved by engineering alone (does the public key really belong to the person?) Including the openness of the source code, it is roughly the problem of. . . “How can we trust automated mechanisms?” Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.16/52
  17. Brief Introduction to Upgrading and Governance of Blockchain Weaknesses are

    not left untouched, but continue to be improved But governance issues remain Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.17/52
  18. Enhancements to Bitcoin Blockchain Virtualization – Open Assets Protocol (no

    fork) Interpret transaction data in a specific way so that quantities independent from BTC can be defined and used Bug fix – Segregated Witness (SegWit) (soft fork) Signatures are separated from the transaction body Better privacy and conciseness – Taproot (and Schnorr signatures) (soft fork) Scripts can be partially disclosed by expressing them in Merklized Abstract Syntax Trees (kind of Merkle trees) Scripts? → Yes, Bitcoin transactions are somewhat programmable, using a stack calculator (see Lecture 6) Quickness – Payment channels (no fork) Only write to the blockchain when the channel is opened and closed, and in between you can make fast payments Conceptually, connected payment channels form a Lightning Network How do we upgrade? Soft fork : miners vote by setting a bit in a block header Wait, voting? Is it an Internet way? Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.18/52
  19. Payment Channel (Bitcoin’s case) "MJDF " #PC # #MPDLDIBJO 

    UP"#  UP#  UP"  UP" MPDLUJNF QBZUSBOTBDUJPOGFFUPNJOFS PQFODIBOOFM pOBMQBZNFOUDMPTFDIBOOFM QBZ QBZ QBZUSBOTBDUJPOGFFUPNJOFS  UP#  UP"   UP#  UP"        MPDLUJNF Alice pays fast by sending Bob transactions to pay, which are cut out of the deposit addressed to Alice and Bob Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.19/52
  20. Science Fiction Prototyping What about it? Lecture 10 : Smart

    Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.20/52
  21. Why Science Fiction Prototyping? What is Science Fiction? Fantasy based

    on or disguised as the thoughts and ideas of science and technology The world with existing science and technology is the real world Ex1 : Medical drama Ex2 : Economic novels The world with science and technology unknown to the real world → Fiction Ex1 : Medical drama with nano-machines Ex2 : Drama with digital currency that depreciates (my book “NEO in Wonderland”) Designing new media and putting it into society = living science fiction To work out plans for that = to write science fiction Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.21/52
  22. Science Fiction Prototyping “WIRED vol.25 The Power of Blockchain —

    Blockchains change the world” (2016) “Oh, Great Decentralization: 5 Perspectives of Near Blockchain Future” Organized by editors based on my interview The story of “Family” from it You want to get married. You realized this feeling, so you and your partner records the words of your oath (contract) in the air “If you don’t want to be with me, you can break this contract. With the key that only you can use” OK, what if she loses the key? Till death do them part ;) Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.22/52
  23. Assignment Review Lecture 10 : Smart Contracts — FinTech —

    Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.23/52
  24. Assignment 4. “Smart Contracts” Please think freely with the image

    of the word “smart contract” to fantasize a specific application example, and state the application briefly That is, go ahead and write a very short science fiction Deadline and how to submit November 23, 2021 at 17:59 JST From Moodle (mandatory) — this time, we are using a Q&A forum So that your classmates can read your report, refer to it, and comment on it Optionally, you can also post to #assignments channel at Discord So that anyone in our Discord can read your report, refer to it, and comment on it Just plain text, and be concise, please You may want to apply Kent Beck style for abstracts (4 sentences) (problem) (why it is a problem) (startling sentence) (consequences) of a story Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.24/52
  25. Trends and Measures Trends . . . of your reports

    Measures . . . how to improve the class 23 out of 29+α students submitted (always better late than never) Your fictions : shopping / trading / tickets / democracy / government / equity market / biological blockchain / flight delay insurance / surveillance / organ transplants / last will / The Real Pie (boss promises rewards) / augmented reality / health care / recruitment / against credit card fraud / (game) crowdfunding / lending everything / travel planner / insurance / no show situation at restaurants / bookmaker / property rights / parking Had a lot of fun to read! Many of you have set the story in the distant future If you use this assignment for a new business idea, the near future is better, but sometimes putting it in the far future can reveal underlying problems of a new idea (as in R-san’s story’s case) If we were to make them look more like the current smart contracts. . . Use the contracts (programs on blockchain) where a proof is needed (like the last will) Conditions to run the code need to be checked outside the contracts Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.25/52
  26. S-san’s Story Redefining Democracy – Smart Contract in the Democratic

    Systems Modern democracy is ill with a huge deviation between politicians’ empty promises during elections rallies and the actual deliveries once elected This is a problem since politicians will compete to “cheat” the voters and further erode the creditability, efficiency, and legitimacy of the democratic system Smart Contract would evaluate the deviation between politicians’ “promises” and “actions” with big data and AI technologies — If a politician has significantly deviated from the “promises,” the person would be removed from office immediately As a result, we would end the problem of “empty promises” and have a much healthier, effective, and trustworthy democratic system ⇒ Kent Beck Abstract style!! Today’s smart contracts cannot use big data and AI from inside their code But if we can find part that require proofs, smart contracts may be useful Like training data set for deep learning to determine the trustworthiness of politicians Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.26/52
  27. H-san’s Story In 2075, John passes away due to a

    lung cancer When his signs of life no longer exist, the hospital renews the physical conditions of his “personal overall account” automatically which enforces the Smart Contract simultaneously With the help of this application, John’s assets are used to repay loans happening during his lifetime initially Then, the assets are deducted by taxes automatically as well Ultimately, his bequests are distributed in terms of the order he set when signing contract (suppose that the order is not against the local Civil Law) As a matter of fact, the application not only is convenient but also further saves various expenses including (but not limited to) legal costs and any kinds of entrust costs ⇒ Sounds like the last will test in action There are many interesting issues related to trust Is the ECG or another sensor real? Is the doctor real? How do we give the hospital the right to update his account? Is the hospital real? Can it be trusted? etc. Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.27/52
  28. F-san’s Story This problem [of bosses making empty promises] can

    be effectively solved by using a smart contract application “The Real Pie” With this application, a smart contract is created between the worker and the boss when the boss makes his/her promise The terms (including targets and rewards) would be finalized with computer languages so that very little room is left for ambiguity This contract would be transparent in the sense that everyone else using this application would be able to see it and verify it Once the target is met, the smart contract would automatically trigger the execution of the reward so that the boss would not be able to break the promises ⇒ Sounds great! As long as the oracle, or the mechanism to detect and tell if the targe is met, is properly operated by a trusted third party Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.28/52
  29. B-san and R-san’s Understanding A “smart contact” referred to a

    simple line of code that would execute once the predetermined conditions are met Smart contracts can be defined as programs stored on a blockchain that run if predetermined conditions are met ⇒ That’s not true for most smart contract platforms today Because validators (miners) run the code when they check the validity of transactions (to store them in a block / stored in a received block) The condition must be checked by an external system to ensure that it is met (and passed to the contract in a message as a kind of oracle) Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.29/52
  30. Smart Contracts and Ethereum What is Smart Contract? Ethereum Lecture

    10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.30/52
  31. What is Smart Contract? Speak in a narrow sense Speak

    in a broad sense Smart contracts and vending machines What is a contract? Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.31/52
  32. Speak in a Narrow Sense A smart contract is, A

    system for automatically transferring and transitioning digitally represented assets according to predetermined rules Or more mechanically, To write program code and data to a blockchain, Or to a ledger that can pass the last will test (censorship-resistent in a broad sense) And run the program blockchain-wise to update data Run when miners verify transactions They do not agree with the feeling of the word But there is a meaning to this narrow sense Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.32/52
  33. Speak in a Broad Sense A smart contract is, Mechanisms

    for implementing contracts mechanically Or, contracts implemented as such ↑ Definition in future dictionaries A vending machine is a primitive form of smart contracts Vending machine. . . do you remember “Reality vs. Blockchain”? Reality that goes in real-time and blockchain’s behavior are very different Suggesting that smart contracts in a broad sense cannot be really implemented by blockchain today Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.33/52
  34. What is a Contract Anyway? Contracts (by Oxford Dictionary) A

    written or spoken agreement, especially one concerning employment, sales, or tenancy, that is intended to be enforceable by law Essential requirement for its establishment Coherence of manifestation of intention between the parties And the medium for that, Oral, handshake, carving/baking on clay tablets and breaking them, paper (handwriting), paper (print) What can a machine do? cf. “The medium is the message.” by McLuhan cf. “Gutenberg Galaxy” by McLuhan Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.34/52
  35. Gutenberg Galaxy (typography) (revisited) Birth of the concept of “authors”

    (meaningless concept unless texts are copied word for word without difference) Scientific methodology (publish papers and have results tested) Nationalism (one standard language, one country) Prepared “movies” (series of photos from one viewpoint) Clear distinction between finished and unfinished “products” (printed copies are the products, handwritten manuscripts are not) Individualism (can carry knowledge personally) Unification of popular culture (massive copies) . . . ⇒ Prepared the industrial society Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.35/52
  36. Reversed Gutenberg Galaxy (digital media) (revisited) Destruction of the concept

    of “authors” (social media time lines are like mosaic media) Overturned scientific methodology (automated hypothesis-testing loops for discoveries) Global perspective (connected across borders) Everyone becomes a moviemaker (YouTubers, TikTokers) Obscured finished and unfinished products ⇒ open design Promotion of collaboration (sharing by default) Diversification of cultural events (long tail) . . . ⇒ Preparing for the next society Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.36/52
  37. Overview of Ethereum Blockchain and State Transition EVM (Ethereum Virtual

    Machine) Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.37/52
  38. What is Ethereum? Vitalik Buterin, “Ethereum White Paper: A NEXT

    GENERATION SMART CONTRACT & DECENTRALIZED APPLICATION PLATFORM” Applying blockchain technology Targeted average block interval : 15 seconds Put a programming language on it Turing complete = can emulate a universal Turing machine (roughly speaking, a computer) (well that’s almost a definition of a programming language) Foundation for DApps (applications that automate the center) An attempt to make the current financial and monetary system obsolete That’s what smart contracts are all about Automate digital asset transfers and their state transitions Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.38/52
  39. Blockchain and State Transitions TUBUF FYUFSOBMBDUPST BDDPVOU &7.DPEF &UIFSˠHBT JOWPLF

    DPOUSBDUDPEF NFTTBHFPSBOFXBVUPOPNPVTPCKFDU EBUBFYDIBOHFEBNPOHBDDPVOUTPS&UIFS TUPSBHF TUBUF` TFUPG USBOTBDUJPOT EJHJUBMTJHOBUVSF &7. IVNBO GPSFYBNQMF Blockchain = Run of a state machine (state transition system) = Operation of a computer Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.39/52
  40. Glossary Ether (ETH) Native currency of Ethereum (compensation for mining)

    External Actor A real person/entity who can digitally sign, having an account EOA : Externally-Owned Account Autonomous Object (internal actor) Operates autonomously within the system, and has an account That said, if you don’t send a message, it won’t work (and miners run them) Account Has an Ether balance, and can have storage (state) and EVM code EVM Code Smart contract program Smart contract = application program on Ethereum = intelligent contract Authenticity is ensured by being written in blockchain Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.40/52
  41. EVM : Ethereum Virtual Machine TUBUF FYUFSOBMBDUPST BDDPVOU &7.DPEF &UIFSˠHBT

    JOWPLF DPOUSBDUDPEF NFTTBHFPSBOFXBVUPOPNPVTPCKFDU EBUBFYDIBOHFEBNPOHBDDPVOUTPS&UIFS TUPSBHF TUBUF` TFUPG USBOTBDUJPOT EJHJUBMTJHOBUVSF &7. IVNBO GPSFYBNQMF BVUPOPNPVT PCKFDU Triggered when an autonomous object receives a message, performs a contract, and changes state Gas must be supplied for each execution step (to avoid an infinite loop and to compensate the miner) (partially burnt) Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.41/52
  42. Demonstration Using Brownie, a Python-based development and testing framework for

    smart contracts on EVM, https://eth-brownie.readthedocs.io/en/stable/ Today, we will use the Python interpreter environment it provides And infura.io that provides accesses to Ethereum (main and test) networks, https://infura.io Let’s demonstrate sending some fractions of Ether between accounts Both on memory (simulated network) and on a test network Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.42/52
  43. Technical Challenges of Blockchain Non real-time (probabilistic behavior) Difficulty of

    secrecy (guarantee of verifiability to all) Oneness (distribution vs. replication) Not scalable (do not scale if replicated to all participants) Harder governance of evolution (can’t change if everyone needs to be united) Incentive mismatch (discrepancy of motivations for participation in infrastructure and applications) Supported by the value of the native currency (crash would stop all applications) ⇒ Can be solved by redesigning it zero-base Actually in progress (ex. BBc -1) Problem with many ledgers is that they are not redesigned zero-base ex. Hash-chains without proof of work can be tampered with ex. Talking about “newspaper model”, you can’t prove anything by publishing articles in company newsletters Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.43/52
  44. Ethereum’s Approach (solutions blockchain-way) Non real-time (probabilistic behavior) ⇒ Towards

    transaction finalization mechanism (Casper) Difficulty of secrecy (guarantee of verifiability to all) ⇒ ZoE (Zcash on Ethereum) Oneness (distribution vs. replication) Not scalable (do not scale if replicated to all participants) ⇒ Sharding, Plasma (multi-layered) Harder governance of evolution (can’t change if everyone needs to be united) ⇒ Benevolent Dictator For Life (BDFL) (with bitter smile ;) ) Incentive mismatch (discrepancy of motivations for participation in infrastructure and applications) Supported by the value of the native currency (crash would stop all applications) ⇒ Will people who want to run the apps buy Ether and support? Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.44/52
  45. BBc-1’s Approach (solutions non-blockchain-way) Non real-time (probabilistic behavior) ⇒ No

    probabilistic behavior before transaction commits Difficulty of secrecy (guarantee of verifiability to all) ⇒ Transaction content is kept secret outside the domain, and can be encrypted inside Oneness (distribution vs. replication) Not scalable (do not scale if replicated to all participants) ⇒ Scale-out on a domain-by-domain basis, intra-domain DHT in the future Harder governance of evolution (can’t change if everyone needs to be united) ⇒ Autonomy by domain (don’t care about intra-domain protocols) Incentive mismatch (discrepancy of motivations for participation in infrastructure and applications) Supported by the value of the native currency (crash would stop all applications) ⇒ No native currency, proof of context work by mutual aid Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.45/52
  46. Smart Contract Programming Programming language Characteristics and challenges Lecture 10

    : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.46/52
  47. Programming Language EVM interprets bytecode (instruction set for virtual machines

    or interpreters) Programmers don’t usually program in bytecode or machine languages — although some do ;) Requires compilers for other, high-level languages High-level language : human-readable/writable language On the other hand, languages close to machines are called low-level languages . . . We may be scolded by artificial intelligence in the near future ;) Examples : Solidity — JavaScript-like language Current primary language Vyper — Python-like language LLL — Lisp-like language Fe — Rust-like features with reference to Vyper? ← NEW! Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.47/52
  48. Solidity Sample Code (this is a high-level language!) pragma solidity

    >=0.4.18 <0.6.0; contract IndivisibleAsset { /* transfer ownership of non-divisible assets */ string public _name; string public _symbol; uint256 public _quantity; address public _owner; constructor(string name, string symbol, uint256 quantity) public { _name = name; _symbol = symbol; _quantity = quantity; _owner = msg.sender; } function transfer(address to) public returns (bool) { require (_owner == msg.sender); _owner = to; return true; } } Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.48/52
  49. Another Solidity Sample Code (snippet) . . . function transfer(address

    to, uint256 value) public returns (bool) { balances[msg.sender] = balances[msg.sender] - value; balances[to] = balances[to] + value; return true; } . . . This can be the core of a (not-so-secure) token contract Without considering overflow/underflow A token contract typically manages the balances of all users Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.49/52
  50. Features of Programming Language Solidity JavaScript-like Object-oriented Describe a contract

    as a template (type or class) Constructor is called during deployment Deploy here means to deploy the contract to the blockchain Decides what parameters to pass to the constructor upon deployment Conforms to Ethereum programming model Deployed contract is a specific entity (instance) Has an account (identified by the address, just like a human user) Has storage and ETH balance Can send messages to other contracts Model where deployed contracts are manipulated by sending messages On the assumption that the authenticity of the code that responds to the message is guaranteed Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.50/52
  51. Characteristics and Challenges Characteristics Execute the program during the block

    validation process, and reflect the results in the “world state” Redundant verifiers Closed within the state of blockchain (maintained by the verifiers) This design is consistent in the Ethereum system Challenges I/O commands cannot be issued from within the program Not affected by the outside world other than external actors who send signed messages ⇒ ex. Data from sensors cannot be read directly Not able to directly affect the outside world ⇒ ex. Cannot send commands to the motor to turn it on/off Lecture 10 : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.51/52
  52. See You Next Week! Have a nice weekend! Lecture 10

    : Smart Contracts — FinTech — Financial Innovation and the Internet 2021 Fall — 2021-12-03 – p.52/52