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

スマートコントラクトと分散ファイナンス / Smart Contracts and Decen...

スマートコントラクトと分散ファイナンス / Smart Contracts and Decentralized Finance

早稲田大学大学院経営管理研究科「フィンテック ─ 金融革新とインターネット」2023 夏クォーターの第7-8回で使用したスライドです。

Kenji Saito

June 26, 2023
Tweet

More Decks by Kenji Saito

Other Decks in Technology

Transcript

  1. Financial technology on the street. Generated by Stable Diffusion XL

    Beta — 2023 7-8 (WBS) — 2023 7-8 — 2023-06-26 – p.1/78
  2. ( ) 1 6 5 (1) • 2 6 5

    (2) • 3 6 12 Web3 (1) • 4 6 12 Web3 (2) • 5 6 19 (1) • 6 6 19 (2) • 7 6 26 (1) • 8 6 26 (2) • 9 7 3 (1) 10 7 3 (2) 11 7 10 (1) 12 7 10 (2) 13 7 24 (1) 14 7 24 (2) 12 — 2023 7-8 — 2023-06-26 – p.3/78
  3. ( 20 ) 1 2 3 4 (TCP/IP ) 5

    6 7 8 9 10 World Wide Web 11 Web API 12 13 git GitHub 14 (6/19 ) / (2 ) OK / — 2023 7-8 — 2023-06-26 – p.4/78
  4. ( ) Web3 (1) — Web3 (2) — — 2023

    7-8 — 2023-06-26 – p.5/78
  5. ( ) Ethereum Ethereum ← (DeFi) ( ) — 2023

    7-8 — 2023-06-26 – p.6/78
  6. Bitcoin ϏοτίΠϯωοτϫʔΫ ɾ ճͷʮ࠾۷ʯྔ͸໿  ೥ຖʹ൒ݮ ɾ߹ܭ໿   ສ

    #5$ ·Ͱ औҾͷొ࿥ ख਺ྉ ख਺ྉ औҾͷঝೝ ϚΠχϯά࣌ ϚΠχϯά ࠾۷ ͸ ֬཰తաఔ ฏۉ  ෼͓͖ʹ੒ޭ ૹۚࢦࣔ͸֤͕ࣗ΋ͭ ϓϥΠϕʔτΩʔͰ ແͨ͘͠Β࠶ൃߦෆՄ ϚΠφʔ ࠾۷ऀ ࢧ෷͍ɾ྆ସ ͳͲͷܦࡁ׆ಈ ར༻ऀ ϒϩοΫνΣʔϯ ݩா Πϯλʔωοτ্ͷԾ૝ωοτϫʔΫ ʜ ˞#5$ϏοτίΠϯͷ୯Ґ #5$ ରԠ ϒϩοΫ ϒϩοΫ ϒϩοΫ औҾ ૹۚ औҾͷه࿥ ΞυϨε Ѽઌ ϓϥΠϕʔτΩʔ ຊਓͷূ໌ — 2023 7-8 — 2023-06-26 – p.8/78
  7. (Bitcoin ) ϒϩοΫ൪߸O ϒϩοΫ൪߸O  ϒϩοΫ൪߸O  ϒϩοΫ൪߸O  ϒϩοΫ൪߸O

     ϒϩοΫ൪߸O  ϒϩοΫ൪߸O  ϒϩοΫ൪߸O  ͍ͪ͹Μه࿥ɾॻ͖׵͑ͷίετ͕ߴ͍ྺ࢙ ࠷΋վ͟Μ͠ʹ͍͘ྺ࢙ ͕༗ޮ ͻͱͭखલͷϒϩοΫͷ ʮμΠδΣετʯ σδλϧॺ໊͞Εͨ ʮτϥϯβΫγϣϯ औҾ ʯ ϒϩοΫΛ࡞ΔͨΊʹ͸ɺͦͷʮμΠδΣετʯ͕͋Δ਺ҎԼͱ͍͏৚݅Λຬͨͨ͠Γ 1SPPGPG8PSL Ծ૝௨՟ͷ࣋ͪ෼ʹԠͨ͡ݖརΛ࢖ͬͨ౤ථͰউͬͨΓ 1SPPGPG4UBLF ͢Δඞཁ͕͋Δ ίετ͕͔͔Δ ϒϩοΫΛ࡞Δਓ͸ͦͷதʹࣗ෼ʹѼͯͨ Ծ૝௨՟ͰͷใुΛॻ͖ࠐΉ͜ͱ͕Ͱ͖ɺ ͦͷϒϩοΫ͕༗ޮͳྺ࢙ͷதʹ͋Δ৔߹ʹ ݶΓใु΋༗ޮͱͳΔ τϥϯβΫγϣϯͷଘࡏΛ֬ೝ͢Δ ͨΊͷޮ཰తͳํ๏͕ఏڙ͞ΕΔ ਖ਼౰ੑ ଘࡏੑ །Ұੑ Proof of Work ( ) (Proof of Stake ) . . . → — 2023 7-8 — 2023-06-26 – p.10/78
  8. ∼ UTXO (= ) → UTXO : (= ); Unspent

    TX(Transaction) Output — 2023 7-8 — 2023-06-26 – p.11/78
  9. ∼ ϖʔδ൪߸O ϖʔδ൪߸O  ϖʔδ൪߸O  ϖʔδ൪߸O  ϖʔδ൪߸O 

    ϖʔδ൪߸O  ϖʔδ൪߸O  ϖʔδ൪߸O  ͬͪ͜ͷྺ࢙͕༗ޮ ( (= ) ) — 2023 7-8 — 2023-06-26 – p.13/78
  10. 0 and/or Bitcoin “The Times 03/Jan/2009 Chancellor on brink of

    second bailout for banks” 2009 1 3 2 https://www.blockchain.com/explorer 0 BTC Block “Hex to ASCII Text Converter” — 2023 7-8 — 2023-06-26 – p.14/78
  11. : ( ( ) ) ( ) — 2023 7-8

    — 2023-06-26 – p.15/78
  12. (Hyperledger (Linux Foundation) ) ( ) ( ) ( )

    ( ) IoT / / ( , ) — 2023 7-8 — 2023-06-26 – p.16/78
  13. : Bitcoin . . . : Proof of Existence, Everledger,

    . . . ( ) ( ) / × = ( ) NFT (Non Fungible Token) — 2023 7-8 — 2023-06-26 – p.17/78
  14. ( ) จ ॻ  จ ॻ  จ ॻ

     จ ॻ  จ ॻ O μΠδΣετ μΠδΣετ μΠδΣετ μΠδΣετ μΠδΣετ μΠδΣετ μΠδΣετ ح਺ͷ৔߹͸ ෳ੡͢Δ ɾจॻ ΛಘͨΫϥΠΞϯτ͸ɺಉ࣌ʹূ໌ཁૉͱͯ͠ɺϒϧʔͰࣔ͞ΕΔμΠδΣετͱ֤ʑ͕ࠨӈͷͲͪΒʹҐஔ͢Δ͔Λड͚औΔɻ ɾΫϥΠΞϯτ͸จॻ  ͷμΠδΣετ͔Β࢝Ίͯɺ࿈݁͢΂͖Ұ࿈ͷμΠδΣετΛ஌Δ͜ͱʹͳΔͷͰɺϚʔΫϧϧʔτʹࢸΔ·Ͱͷ ɹܭࢉΛ࠶ݱͰ͖ɺಘΒΕͨϚʔΫϧϧʔτ͕ϒϩοΫνΣʔϯʹه࿥͞Ε͍ͯΔ஋ͱҰக͢Δ͜ͱΛ֬ೝͰ͖Δɻ ɾͦͷܭࢉ͸ݪཧͷཧղͱඞཁͳ৘ใ͕͋Ε͹୭Ͱ΋࠶ݱͰ͖Δ  จॻ  ͷଘࡏͱͦͷ಺༰͸ূ໌͞ΕΔɻ ˞μΠδΣετ͸ݩͷσʔλ͕ ɹϏοτͰ΋ҟͳΔͱશ͘ҟͳΔ ɹ஋ͱͳΓɺ·ͨɺμΠδΣετ ɹ͔ΒݩͷσʔλΛਪଌ͢Δ͜ͱ͸ ɹͰ͖ͳ͍ɻ ˞਺ઍɾ਺ສͷจॻΛϚʔΫϧ໦ʹͯ͠΋ ɹͦͷ໦ͷߴ͞͸ߴʑʙ ఔ౓ ه࿥͢Δ ಡΈग़ͤΔ ূ໌Λ ඞཁͱ͢Δऀʹ ։ࣔ͞ΕΔ৘ใ ެ։͞ΕΔ৘ใ ϚʔΫϧϧʔτ Ϛ ồ Ϋ ϧ ໦  γ ε ς Ϝ ͕ อ ؅ ͠ ֤ Ϣ ồ β ʹ ෦ ෼ త ʹ ఻ ͑ Δ ʜʜ ʜʜ ʜʜ ʜʜ ʜʜ μΠδΣετ μΠδΣετ μΠδΣετ μΠδΣετ μΠδΣετ μΠδΣετ ϒϩοΫνΣʔϯ ʜ ʜ — 2023 7-8 — 2023-06-26 – p.18/78
  15. : ⇒ LINE → → ( ) ( ) ⇒

    ( ) → → → . . . — 2023 7-8 — 2023-06-26 – p.19/78
  16. (2009 1 ∼2023 6 ) 2 → 2 2 →

    → — 2023 7-8 — 2023-06-26 – p.21/78
  17. 10 ATM 1 ATM 1 : http://www.slideshare.net/yamaz2/ss-58813038 ⇒ ( (

    ) ) — 2023 7-8 — 2023-06-26 – p.22/78
  18. The DAO ( ) Ethereum The DAO Split ( )

    360 ETH (50∼60 ) (2016/6/17) ( ) ( ; ) (2016/7/20 ) — 2023 7-8 — 2023-06-26 – p.24/78
  19. ( ) ( ) ( vs. ) ( ) (

    ) ( ) ⇒ ( : BBc-1, BBc-2) : : — 2023 7-8 — 2023-06-26 – p.25/78
  20. 3. SF Web3 2023 6 22 ( ) 23:59 JST

    ( ) Waseda Moodle — 2023 7-8 — 2023-06-26 – p.27/78
  21. . . . . . . 37 30 (6/24( )

    ) ( ) SF ( ) (17) / (4) / (4) / ( ) (2) / (2) / (1) ( ) (19) / (5) / (3) / (1) / (1) / (1) — 2023 7-8 — 2023-06-26 – p.28/78
  22. Y : EduContract 1 : EduContract Proof of Learning 2

    : 3 3 : EduContract 4 : AI EduContract — 2023 7-8 — 2023-06-26 – p.29/78
  23. Y — 5 : 6 : EduContract : : ⇒

    = — 2023 7-8 — 2023-06-26 – p.30/78
  24. T 1 gas ID ⇒ gas ETH gas ( (

    ) + ( )) gas ETH ETH ETH — 2023 7-8 — 2023-06-26 – p.34/78
  25. C ChatGPT ⇒ ( ) GPT-4 : OpenAI. 2023. “GPT-4

    Technical Report”. Available at: https://doi.org/10.48550/arXiv.2303.08774. p.8 Figure 5 — 2023 7-8 — 2023-06-26 – p.35/78
  26. C NFT Gas Price gwei JPY USD ⇒ https://www.cryps.info/ja/Gwei_ _JPY/

    1 Gwei 0.00027071 JPY NFT 1,834,415 gas https://etherscan.io/gastracker gas 15 Gwei 1,834,415 (gas) × 15 (Gwei/gas) × 0.00027071 (JPY/Gwei) ≃ 7,449 JPY — 2023 7-8 — 2023-06-26 – p.36/78
  27. K ⇒ ( ) ( ) ( ; ) —

    2023 7-8 — 2023-06-26 – p.38/78
  28. Ethereum · → · → · → — 2023 7-8

    — 2023-06-26 – p.41/78
  29. (by ) 1. 2. ( ) ( ) . .

    . cf. by McLuhan cf. by McLuhan → — 2023 7-8 — 2023-06-26 – p.43/78
  30. by SNS AI AI ⇒ ( ) ⇒ — 2023

    7-8 — 2023-06-26 – p.45/78
  31. Ethereum Vitalik Buterin, “Ethereum White Paper: A NEXT GENERATION SMART

    CONTRACT & DECENTRALIZED APPLICATION PLATFORM” (Dec. 2013∼) 12 ( ) (= ) = = ( ) CPU ⇒ DApps DApps = / — 2023 7-8 — 2023-06-26 – p.47/78
  32. = ( ) run = → — 2023 7-8 —

    2023-06-26 – p.48/78
  33. [Lamport 1984][Schneider 1990] ( ) (1) 0 ( ) (2)

    (3) (4) ( ) ← — 2023 7-8 — 2023-06-26 – p.49/78
  34. Ether (ETH) Ethereum EOA : Externally-Owned Account ( ) (

    ) ( ) ( ) ← Ether ( ) EVM EVM = Ethereum = — 2023 7-8 — 2023-06-26 – p.50/78
  35. EVM : Ethereum Virtual Machine ঢ়ଶ ֎෦ΞΫλʔ ΞΧ΢ϯτ &7. ίʔυ

    &UIFSˠ(BT ىಈ ίϯτϥΫτ ϝοηʔδ͔ɺ৽͍ࣗ͠ಈΦϒδΣΫτ ΞΧ΢ϯτؒͰ΍ΓऔΓ͞ΕΔσʔλ΍&UIFS ετϨʔδ ঢ়ଶ` τϥϯβΫγϣϯ ηοτ σδλϧॺ໊ &7. ਓؒͱ͔ ࣗಈ ΦϒδΣΫτ ( ) Gas ( EVM = ( burn)) — 2023 7-8 — 2023-06-26 – p.51/78
  36. / / (1) Ethereum Bitcoin ( OK) 1 — 2023

    7-8 — 2023-06-26 – p.52/78
  37. / / (2) 3 ( ) · ( ) (

    ) 1 — 2023 7-8 — 2023-06-26 – p.53/78
  38. / / (3) ( ) ( ) 1 ( )

    1,500 3,000 Ethereum 2022 9 — 2023 7-8 — 2023-06-26 – p.54/78
  39. / / (4) Gwei Gwei ETH 32 ETH ( )

    ETH ETH · 32 ETH ( OK) · 16 ETH ( ) 12 ( ) ( ) 1 — 2023 7-8 — 2023-06-26 – p.55/78
  40. / / (5) 32 1 (384 ) ( ) (

    ) 2 3 ( ) 256 512 — 2023 7-8 — 2023-06-26 – p.56/78
  41. / / (6) ( ) 5 2 3 (36 )

    — 2023 7-8 — 2023-06-26 – p.57/78
  42. / / (7) ( ) ( ) DAO (RANDAO) 1

    — 2023 7-8 — 2023-06-26 – p.58/78
  43. Ethereum        ߹ҙ͞Εͨཤྺ ϩʔΧϧʹෳ੡Λҡ࣋

    ϒϩοΫ εϩοτ  ඵִؒ  εϩοτͰ  ΤϙοΫ ҉߸ֶతμΠδΣετ ϒϩοΫνΣʔϯͷҡ࣋ࢀՃऀ͕ϩʔΧϧʹ؅ཧ͢Δσʔλۭؒ ࣌ؒ ΑΓ৽͍͠ه࿥ ΦϒδΣΫτ τʔΫϯγεςϜ౳ͷεϚʔτίϯτϥΫτ ֤Ϣʔβͷ ࢒ߴ౳ͷঢ়ଶ ঢ়ଶ` ঢ়ଶ`` τϥϯβΫγϣϯ ΦϒδΣΫτͷੜ੒ ·ͨ͸ঢ়ଶભҠͷࢦࣔ ແޮͳཤྺ ω ỽ τ ϫ ồ Ϋ Λ ௨ ͠ ͯ ૹ ड ৴ ͞ Ε Δ ϩ ồ Χ ϧ ʹ ࣋ ͭ ܨ͙ͨΊʹ͸&5) Ͱͷσϙδοτͱ σϙδοτ૯ֹͷ ♤ ૬౰ͷϢʔβʹΑΔ ΤϙοΫ΁ͷূݴ͕ඞཁ શΦϒδΣΫτͷભҠޙͷঢ়ଶ ͕ϋογϡ໦˞ʹू໿͞Ε ͦͷ ϧʔτ஋͕ϒϩοΫʹॻ͔ΕΔ ঢ়ଶભҠ ˞ϋογϡ໦σʔλ܈ͷ҉߸ֶతμΠδΣετ ϋογϡ ɹΛ໦ߏ଄ʹදݱͨ͠΋ͷͰ ෆ੔߹ͷݕग़ʹ༻͍ΒΕΔ ETH ( ) ⇒ ETH = Ethereum Virtual Machine (EVM) 2 3 ETH ⇒ ETH — 2023 7-8 — 2023-06-26 – p.59/78
  44. Ethereum (ex. ) (ex. ) ⇒ → — 2023 7-8

    — 2023-06-26 – p.60/78
  45. ERC-20 ERC (Ethereum Request for Comments) 20 https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md (EIP: Ethereum

    Improvement Proposal) ← EIP ( ) contract ERC20 { function totalSupply() constant returns (uint totalSupply); function balanceOf(address _owner) constant returns (uint balance); function transfer(address _to, uint _value) returns (bool success); function transferFrom(address _from, address _to, uint _value) returns (bool success); function approve(address _spender, uint _value) returns (bool success); function allowance(address _owner, address _spender) constant returns (uint remaining); event Transfer(address indexed _from, address indexed _to, uint _value); event Approval(address indexed _owner, address indexed _spender, uint _value); } name/ , symbol/ , decimals/ approve allowance ERC-777 ( ) — 2023 7-8 — 2023-06-26 – p.62/78
  46. ERC-20 ERC-20 ← ( ) ( ) ⇒ ERC-20 (

    ERC-20 ) ERC-20 ⇒ — 2023 7-8 — 2023-06-26 – p.63/78
  47. (fungible) ERC-20 → ERC-223 (draft) or ERC-777 ( )( )

    (non-fungible) ERC-721 ( ) ( ) ERC-1155 ( ) ERC-3525 (SLOT ) — 2023 7-8 — 2023-06-26 – p.64/78
  48. — τʔΫϯ ୅ସ՟ฎ εϚʔτίϯτϥΫτ ݕূՄೳͳঢ়ଶϚγϯ ϓϩϏφϯε དྷྺূ໌  ୅ସՄೳ ঈؐෆೳ

    ୅ସՄೳ ঈؐՄೳ ୅ସෆೳ ঈؐՄೳ ୅ସෆೳ ঈؐෆೳ ূ໌͢Δ ಉఆ͢Δ ࢧ෷͍౳ ࠷ॳͷԠ༻ *%Χʔυ౳ ηΩϡϦςΟ τʔΫϯ ূ݊ ౳ ηϯαʔ౳ ෺ྲྀɾ Ҩݴॻ౳ อݥਃ੥౳ ௥੻͢Δ ײ஌͢Δ தԝۜߦ σδλϧ௨՟౳ ҭ੒ήʔϜ౳ ൿີ伴Λ࢖͑Δ͔Βຊਓʁ ෛ࠴  Ξηοτͷ ਺஋දݱΛҠసͰ͖Δʁ ొ࿥͞Εͨίʔυͱ ͦͷ࣮ߦϩάͱ݁Ռͷ ਅਖ਼ੑΛ୲อͰ͖Δʁ ݖҖ͕  Կ͔ͷ಺༰Λূ໌͢Δʁ ࣋ଓ͢Δଘࡏʹ͍ͭͯ ه࿥ΛΞοϓσʔτՄʁ ओମ͕͍ͳ͘ͳͬͯ΋ աڈͷσʔλ͸༗ޮʁ /'5 Ұൠతͳ ೝࣝ ػೳͷ ෼ੳ݁Ռ — 2023 7-8 — 2023-06-26 – p.65/78
  49. ( ( )) ( ) / / — 2023 7-8

    — 2023-06-26 – p.68/78
  50. — 1. ( ) 2. ( ) 3. ( )

    — 2023 7-8 — 2023-06-26 – p.69/78
  51. token (ERC-20 ) $ brownie bake token GitHub git clone

    $ git clone https://github.com/ks91/sample-smart-contracts.git sample-smart-contracts contracts, scripts tests token Token — 2023 7-8 — 2023-06-26 – p.70/78
  52. OneTimeEscrow settle() function settle() public returns (bool) { require(_token_.balanceOf(address(this)) >=

    _price_); /* this */ require(_asset_.getOwner() == address(this)); _token_.transfer(_seller_ , _price_); _asset_.transfer(_buyer_); emit Settled(); /* */ return true; } settle() transfer $ brownie compile — 2023 7-8 — 2023-06-26 – p.71/78
  53. (1) from brownie import * import pytest seller = accounts[0]

    buyer = accounts[1] def test_deploy_and_settle(Token, IndivisibleAsset, OneTimeEscrow): asset = accounts[0].deploy(IndivisibleAsset, "5322 Endo", "mˆ2", 300) token = accounts[0].deploy(Token, "Test Token", "TEST", 18, "1000 ether") — 2023 7-8 — 2023-06-26 – p.72/78
  54. (2) token.transfer(buyer, 300, {’from’: accounts[0]}) escrow = accounts[0].deploy(OneTimeEscrow, token, buyer,

    asset, seller, 300) accounts[0]/seller accounts[1]/buyer 300 300 TX buyer seller 300 bake Token 300 ETH wei — 2023 7-8 — 2023-06-26 – p.73/78
  55. (3) token.transfer(escrow, 300, {’from’: buyer}) asset.transfer(escrow, {’from’: seller}) assert token.balanceOf(seller)

    == 999999999999999999700 assert token.balanceOf(buyer) == 0 assert token.balanceOf(escrow) == 300 assert asset.getOwner() == escrow buyer ( ) 300 seller ( ) — 2023 7-8 — 2023-06-26 – p.74/78
  56. (4) escrow.settle({’from’: seller}) assert token.balanceOf(seller) == 1000000000000000000000 assert token.balanceOf(buyer) ==

    0 assert token.balanceOf(escrow) == 0 assert asset.getOwner() == buyer settle() seller OK — 2023 7-8 — 2023-06-26 – p.75/78
  57. 4. × OK Web3 2023 6 30 ( ) 23:59

    JST ( ) Waseda Moodle — 2023 7-8 — 2023-06-26 – p.77/78