詳解 Ethereum Transaction / detail ethereum transaction

詳解 Ethereum Transaction / detail ethereum transaction

blockchain.tokyo #6

8f35e0eca3fafcc994d26ad430628985?s=128

Kazuki YAMAGUCHI

March 16, 2018
Tweet

Transcript

  1. 2018/03/16 blockchain.tokyo #6 in Cyber Agent Kazuki Yamaguchi (@yamarkz) Gunosy

    Inc. ৄղ Ethereum Transaction ~Transactionͷ֓ཁ͔Β࢓૊Έ·Ͱ·Δͬͱ঺հ~
  2. Kazuki Yamaguchi / @yamarkz Software Engineer @Gunosy Graduated from Spring

    2017 WebApplication Rails Dapps Solidity Research CryptoCurrency & Blockchain Github & Twitter @yamarkz
  3. Gunosy Blockchain Blog΍ͬͯ·͢ʂ ʮhttp://blockchain.gunosy.ioʯor ʮάϊγʔ ϒϩοΫνΣʔϯʯ

  4. ※τϥϯβΫγϣϯʹ͍ͭͯৄղʹ࿩ͨ͢ΊɺϒϩοΫνΣʔϯɺΞΧ΢ϯτɺϚΠχϯάͳͲɺ पลγεςϜͷ࿩͸୺ંΓ·͢ Agenda • Ethereum & Transaction • 2 Type

    Transaction • Message 4 Pattern • Transaction Life Cycle • Transaction for Data Structure • Transaction Pool & Nonce • Transaction Releasing
  5. Ethereum & Transaction

  6. ※ ίϯτϥΫτ࣮ߦͷΠϝʔδ ※ EtherʹΑΔࢧ෷͍ͷΠϝʔδ ίϯτϥΫτͷ࣮ߦ => τϥϯβΫγϣϯͷૹ৴ ICO΁ͷࢀՃ => τϥϯβΫγϣϯͷૹ৴

    Etherͷૹۚ => τϥϯβΫγϣϯͷૹ৴ ίϯτϥΫτͷ࡞੒ => τϥϯβΫγϣϯͷૹ৴ Ethereumʹ͓͍ͯɺTransaction͸શͯͷ࢝·Γ
  7. EthereumͷTransaction͸େ͖͘2ͭʹ෼͚ΒΕΔ Contract Creation Message (৽ͨͳίϯτϥΫτ࡞੒) (ίϯτϥΫτͷ࣮ߦ or Etherͷૹۚ) New!!! A͞Μ͔ΒB͞Μ΁

    3Ether ૹۚ ίϯτϥΫτͷؔ਺࣮ߦ ৽ͨͳίϯτϥΫτͷσϓϩΠ A B
  8. (৽ͨͳίϯτϥΫτ࡞੒) Contract Creation ৽ͨͳίϯτϥΫτͷσϓϩΠ New!!! ͬͪ͜ΛΑΓਂ͘෼ղͯ͠ΈΔ EthereumͷTransaction͸େ͖͘2ͭʹ෼͚ΒΕΔ A͞Μ͔ΒB͞Μ΁ 3Ether ૹۚ

    A B ίϯτϥΫτͷؔ਺࣮ߦ Message (ίϯτϥΫτͷ࣮ߦ or Etherͷૹۚ)
  9. Message͸4ͭʹ෼ྨ͞ΕΔ Transaction From EOA EVM code From CA To EOA

    To CA EOA EOA Transaction Message EOA CA Message CA EOA Message Code CA Code CA Transaction Message From: Ethereum EVM illustrated
  10. Transaction Life Cycle

  11. 1. Transactionʹॺ໊ 2. TransactionΛϊʔυʹϒϩʔυΩϟετ ϊʔυ Tx ༗ޮͳτϥϯβΫγϣϯ͔όϦσʔγϣϯ ؔ࿈ϊʔυʹ఻ൖ TxPool Metamask

    etc… Queued Pending ɾ఻ൖ࣌ͷTransaction͸ɺSerialize͞ΕΔ ɾGas PriceʹΑͬͯϊʔυ͸อ࣋͢Δ͔൑அͰ͖Δ Tx Tx Tx Tx Block Tx Tx ϚΠχϯά ϒϩοΫνΣʔϯ Txͷঢ়گʹΑͬͯɺ PendingͱQueued෼͚ΒΕΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ START ϚΠφʔϊʔυ ϊʔϚϧϊʔυ ϩʔΧϧϊʔυ A B Pendingͷத͔ΒϚΠχϯά͢ΔTxΛɺ ϚΠφʔ͕બ୒͢Δ
  12. Pendingͷத͔ΒϚΠχϯά͢ΔTxΛɺ ϚΠφʔ͕બ୒͢Δ ؔ࿈ϊʔυʹ఻ൖ TxPool Queued Pending ɾ఻ൖ࣌ͷTransaction͸ɺSerialize͞ΕΔ ɾGas PriceʹΑͬͯϊʔυ͸อ࣋͢Δ͔൑அͰ͖Δ Tx

    Tx Tx Tx Block Tx Tx ϚΠχϯά ϒϩοΫνΣʔϯ Txͷঢ়گʹΑͬͯɺ PendingͱQueued෼͚ΒΕΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ ϚΠφʔϊʔυ ϊʔϚϧϊʔυ B A ϊʔυ Tx ༗ޮͳτϥϯβΫγϣϯ͔όϦσʔγϣϯ ϩʔΧϧϊʔυ 1. Transactionʹॺ໊ 2. TransactionΛϊʔυʹϒϩʔυΩϟετ Metamask etc… START
  13. Pendingͷத͔ΒϚΠχϯά͢ΔTxΛɺ ϚΠφʔ͕બ୒͢Δ 1. Transactionʹॺ໊ 2. TransactionΛϊʔυʹϒϩʔυΩϟετ ϊʔυ Tx ༗ޮͳτϥϯβΫγϣϯ͔όϦσʔγϣϯ Metamask

    etc… Tx Tx Tx Tx Block ϚΠχϯά ϒϩοΫνΣʔϯ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ START ϩʔΧϧϊʔυ A B ؔ࿈ϊʔυʹ఻ൖ ɾ఻ൖ࣌ͷTransaction͸ɺSerialize͞ΕΔ ɾGas PriceʹΑͬͯϊʔυ͸อ࣋͢Δ͔൑அͰ͖Δ Tx ϚΠφʔϊʔυ ϊʔϚϧϊʔυ TxPool Queued Pending Tx Txͷঢ়گʹΑͬͯɺ PendingͱQueued෼͚ΒΕΔ
  14. 1. Transactionʹॺ໊ 2. TransactionΛϊʔυʹϒϩʔυΩϟετ ϊʔυ Tx ༗ޮͳτϥϯβΫγϣϯ͔όϦσʔγϣϯ ؔ࿈ϊʔυʹ఻ൖ Metamask etc…

    ɾ఻ൖ࣌ͷTransaction͸ɺSerialize͞ΕΔ ɾGas PriceʹΑͬͯϊʔυ͸อ࣋͢Δ͔൑அͰ͖Δ Tx ϒϩοΫνΣʔϯ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ START ϊʔϚϧϊʔυ ϩʔΧϧϊʔυ A B Tx Tx Tx Tx Block ϚΠχϯά ϚΠφʔϊʔυ TxPool Queued Pending Tx Txͷঢ়گʹΑͬͯɺ PendingͱQueued෼͚ΒΕΔ Pendingͷத͔ΒϚΠχϯά͢ΔTxΛɺ ϚΠφʔ͕બ୒͢Δ
  15. Pendingͷத͔ΒϚΠχϯά͢ΔTxΛɺ ϚΠφʔ͕બ୒͢Δ 1. Transactionʹॺ໊ 2. TransactionΛϊʔυʹϒϩʔυΩϟετ ϊʔυ Tx ༗ޮͳτϥϯβΫγϣϯ͔όϦσʔγϣϯ ؔ࿈ϊʔυʹ఻ൖ

    TxPool Metamask etc… Queued Pending ɾ఻ൖ࣌ͷTransaction͸ɺSerialize͞ΕΔ ɾGas PriceʹΑͬͯϊʔυ͸อ࣋͢Δ͔൑அͰ͖Δ Tx Tx Tx Tx Block Tx Tx Txͷঢ়گʹΑͬͯɺ PendingͱQueued෼͚ΒΕΔ START ϚΠφʔϊʔυ ϊʔϚϧϊʔυ ϩʔΧϧϊʔυ A ϚΠχϯά ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ B ϒϩοΫνΣʔϯ A
  16. 1. Transactionʹॺ໊ 2. TransactionΛϊʔυʹϒϩʔυΩϟετ ϊʔυ Tx ༗ޮͳτϥϯβΫγϣϯ͔όϦσʔγϣϯ ؔ࿈ϊʔυʹ఻ൖ TxPool Metamask

    etc… Queued Pending ɾ఻ൖ࣌ͷTransaction͸ɺSerialize͞ΕΔ ɾGas PriceʹΑͬͯϊʔυ͸อ࣋͢Δ͔൑அͰ͖Δ Tx Tx Tx Tx Block Tx Tx ϚΠχϯά ϒϩοΫνΣʔϯ Txͷঢ়گʹΑͬͯɺ PendingͱQueued෼͚ΒΕΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ START ϚΠφʔϊʔυ ϊʔϚϧϊʔυ ϩʔΧϧϊʔυ A B Pendingͷத͔ΒϚΠχϯά͢ΔTxΛɺ ϚΠφʔ͕બ୒͢Δ Ұ࿈ͷྲྀΕΛܦͯɺτϥϯβΫγϣϯ͸࠷ऴతʹΞΧ΢ϯτͷঢ়ଶΛมߋ͢Δ
  17. Transaction for Data Structure

  18. Transaction Nonce Gas Price Gas Limit To Value v, r,

    s Init or data CLI্Ͱ֬ೝͰ͖ΔTransactionͷத਎ Transaction for Data Structure
  19. CLI্Ͱ֬ೝͰ͖ΔTransactionͷத਎ Nonce Gas Price Gas Limit To Value v, r,

    s Init or data ϢχʔΫͰ͋Δ͜ͱΛࣔ͢ ૹۚ͢ΔEtherͷֹ Contract࣮ߦ࣌ʹফඅ͢ΔGasͷ੍ݶ EVMίʔυ͕ೖΔϑΟʔϧυ Transaction Transaction for Data Structure
  20. Transaction Pool & Nonce

  21. Pendingͷத͔ΒϚΠχϯά͢ΔTxΛɺ ϚΠφʔ͕બ୒͢Δ 1. Transactionʹॺ໊ 2. TransactionΛϊʔυʹϒϩʔυΩϟετ ϊʔυ Tx ༗ޮͳτϥϯβΫγϣϯ͔όϦσʔγϣϯ ؔ࿈ϊʔυʹ఻ൖ

    Metamask etc… ɾ఻ൖ࣌ͷTransaction͸ɺSerialize͞ΕΔ ɾGas PriceʹΑͬͯϊʔυ͸อ࣋͢Δ͔൑அͰ͖Δ Tx Tx Tx Tx Block Tx ϚΠχϯά ϒϩοΫνΣʔϯ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ ΞΧ΢ϯτͷঢ়ଶ͕มΘΔ START ϚΠφʔϊʔυ ϊʔϚϧϊʔυ ϩʔΧϧϊʔυ A B TxPool Queued Pending Tx ͜͜ͷ࿩ Txͷঢ়گʹΑͬͯɺ PendingͱQueued෼͚ΒΕΔ
  22. Transaction Pool Transaction Pool (ҎԼɺTxPool)ͱ͸ɺϒϩοΫʹऔΓࠐ·ΕΔલͷτϥϯβΫγϣϯ͕Ұ࣌ తʹอଘ͞ΕΔۭؒɻۭؒ͸ϊʔυͷϚγϯϝϞϦ্ʹ࡞ΒΕΔɻ ϚγϯϝϞϦ্ʹ࡞ΒΕΔͨΊɺϚγϯͷిݯ͕མͪΔͱTxPool಺ͷτϥϯβΫγϣϯ΋ফ͑ Δɻ ϊʔυ͸ࣗ਎ͷϝϞϦۭؒʹؚΊΔτϥϯβΫγϣϯΛGasPriceͰબผ͢Δ͜ͱ͕Ͱ͖Δɻ TxPoolͷۭؒ͸2ͭ

    Pending • ϒϩοΫʹऔΓࠐ·ΕͯOKͳτϥϯβΫγϣϯ͕อଘ͞ΕΔ Queued • ϒϩοΫʹऔΓࠐ·ΕͯNGͳτϥϯβΫγϣϯ͕อଘ͞ΕΔ • τϥϯβΫγϣϯͷNonceʹΪϟοϓ͕ଘࡏ͢Δ৔߹ɺPendingͰ͸ͳ͘ɺ Queuedʹอଘ͞ΕΔɻQueuedͷ໾ׂ͸ɺωοτϫʔΫ͔Β౸ணͨ͠ॱং֎τϥ ϯβΫγϣϯΛΧόʔ͢Δ͜ͱɻ(τϥϯβΫγϣϯͷॱংΛकΔ͜ͱ)
  23. Transaction Pool & Nonce TxPool ͷPendingͱQueuedͷڍಈ Nonce 37ͷTx͕଍Γͳ͍ঢ়گ Nonce 37͕TxPoolʹϒϩʔυΩϟετ

    or ఻ൖ͞Εͨ͜ͱʹΑΓɺ QueuedͷTx͸nonceͷॱং͕ἧ͏ɻ ἧ͏͜ͱͰϚΠχϯάOKͳTxʹͳΓPendingʹҠಈ͢Δ
  24. Transaction Nonce From: Mastering Ethereum Nonce͸ಉҰΞΧ΢ϯτ͔ΒͷTransaction Orderͷূ໌Ͱ͋Γɺ τϥϯβΫγϣϯͷೋॏࢧग़໰୊Λղܾ͢Δɻ Nonce͸Transactionʹ͓͍ͯ࠷΋ॏཁͳίϯϙʔωϯτͰ͋Γɺ ࠷΋ཧղ͞Ε͍ͯͳ͍ՕॴͰ΋͋Δɻ

    Tx Nonce 1 Tx Nonce 2 Tx Nonce 3 Tx Nonce 4 ಉҰΞΧ΢ϯτ͔ΒͷτϥϯβΫγϣϯ͸NonceͷॱংʹԊͬͯɺϒϩοΫʹऔΓࠐ·ΕΔɻ Nonce1ͱNonce2ͷτϥϯβΫγϣϯ͕ಉҰΞΧ΢ϯτA͔Β࡞ΒΕͨ৔߹ɺNonce2ͷτϥϯ βΫγϣϯ͸Nonce1ͷτϥϯβΫγϣϯ͕ϚΠχϯά͞Εͳ͍ݶΓɺϚΠχϯά͞Εͳ͍ɻ NonceͷॱংʹԊͬͯτϥϯβΫγϣϯ͕ϒϩοΫʹऔΓࠐΉϓϩτίϧʹΑΓɺೋॏࢧग़Λ๷ ͍Ͱ͍Δɻ
  25. Transaction Releasing

  26. Transaction Releasing ϒϩʔυΩϟετͨ͠τϥϯβΫγϣϯΛͳ͔ͬͨ͜ͱʹ͍ͨ͠ or τϥϯβΫγϣϯ͕ͳ͔ͳ͔ϚΠχϯά͞Εͳ͍ͷͰGas PriceΛ্͛௚͍ͨ͠ Ethereumʹ͸ϒϩʔυΩϟετͨ͠τϥϯβΫγϣϯΛ࡟আ͢Δ࢓૊Έ͕ͳ͍ ͔͠͠ɺ ະঝೝτϥϯβΫγϣϯΛ ߋ৽

    ͢Δ͜ͱ͕Մೳ ~έʔεελσΟ~
  27. Transaction Releasing ະঝೝτϥϯβΫγϣϯͷߋ৽ (Releasing) ߋ৽͍ͨ͠τϥϯβΫγϣϯʹৼΒΕ͍ͯΔNonceͱಉ͡NonceΛࢦఆͨ͠τϥϯβΫγϣϯ Λ࡞੒͠ɺϒϩʔυΩϟετ͢Δ͜ͱͰະঝೝτϥϯβΫγϣϯΛߋ৽͢Δ͜ͱ͕Ͱ͖Δɻ ߋ৽Ͱ͸஋ͷमਖ਼͕ՄೳͳͷͰɺ3Etherͷૹ৴͢ΔͷΛͳ͔ͬͨ͜ͱʹ͢ΔͨΊʹɺ0Etherͷ τϥϯβΫγϣϯΛૹ৴͠ͳ͓ͤ͹ɺະঝೝτϥϯβΫγϣϯ͸ߋ৽͞ΕΔͷͰɺͳ͔ͬͨ͜ ͱʹͳΔɻ(※ख਺ྉͰ͋ΔGas୅͸ඞཁ) ߋ৽Ͱ͸Ŋߋ৽ઌτϥϯβΫγϣϯ͕࣋ͭGasPriceͷ10%Ҏ্ߴ͍

    GasPriceͷߋ৽τϥϯβΫ γϣϯΛ࡞੒͠ͳ͚Ε͹͍͚ͳ͍ Tx A͞Μ͔ΒB͞Μ΁ 3Etherͷૹۚ Tx A͞Μ͔ΒB͞Μ΁ 0Etherͷૹۚ ߋ৽ઌ ߋ৽ݩ ߋ৽ʂʂ ϒϩʔυΩϟετ Tx A͞Μ͔ΒB͞Μ΁ 0Etherͷૹۚ TxPool
  28. Transaction Releasing Transaction Releasingͷڍಈ Nonce 41ͷະঝೝτϥϯβΫγϣϯ ಉ͡Nonce Ͱ͔ͭɺ10%Ҏ্ߴ͍GasPriceͷTxΛϒϩʔυΩϟετ͢Δ͜ͱͰߋ৽ ߋ৽TxʹΑΓɺ3Etherͷૹ͕ۚ0EtherʹͳΓɺ࣮࣭ͷૹۚ͸औΓফ͢͜ͱ͕Ͱ͖͍ͯΔ

  29. Transactionʹ͸2ͭͷେ͖ͳ෼ྨͱ4ͭͷϝοηʔδύλʔϯ͕͋Δ Ethereum͸ΞΧ΢ϯτ΍ίϯτϥΫτͱ͍͏֓೦͕͋ΔͨΊɺ
 τϥϯβΫγϣϯͷ࢓૊Έ΍ߏ଄΋ෳࡶ Nonceͷ࢓૊Έ͕Life CycleΛཧղ͢Δ্Ͱॏཁͳ伴ͱͳΔ Contract։ൃΛਐΊΔ্ͰTransactionͷ࢓૊ΈΛཧղ͢Δͷ͸ॏཁ ·ͱΊ

  30. ɾWhat is Gas? ɾEthereum EVM Illustrated ɾMastering Ethereum ɾEthereum White

    Paper ɾEthereum Yellow Paper ɾEthereum Wiki ɾLife Cycle of an Ethereum Transaction ࢀߟࢿྉ
  31. Q&A 1 Q. τϥϯβΫγϣϯͷૹۚݩ͸Ͳ͏΍ͬͯ൑அ͢Δͷʁ A. τϥϯβΫγϣϯʹؚ·ΕΔॺ໊͸ૹ৴ݩͷΞΧ΢ϯτͷൿີ伴͔Β͔͠࡞ΒΕͳ͍ͨΊɺͦͷॺ ໊Ͱ൑அ͢Δ Q.τϥϯβΫγϣϯΛ࡞੒ͨ͠΋ͷͷɺΞΧ΢ϯτεςʔτͷߋ৽ͷॱংͰૹۚऀ͕े෼ͳEtherΛ ͍࣋ͬͯͳ͔ͬͨ৔߹τϥϯβΫγϣϯ͸Ͳ͏ͳΔͷʁ A.

    τϥϯβΫγϣϯ͸ૹۚ͸ࣦഊͱͳΔ΋ͷͷɺτϥϯβΫγϣϯࣗମ͸ϚΠχϯά͞Εɺख਺ྉͷ Έ͕ϚΠφʔʹࢧ෷ΘΕΔ Q.ΞΧ΢ϯτ͕࣋ͭNonceΑΓ΋௿͍஋Λ߱ͬͨτϥϯβΫγϣϯΛϒϩʔυΩϟετ͢ΔͱͲ͏ͳΔ ͷʁ A. ϒϩʔυΩϟετઌͷϩʔΧϧϊʔυͷόϦσʔγϣϯͰ஄͔ΕTxPoolʹೖΒͣɺτϥϯβΫγϣ ϯ͸ഁغ͞Εɺૹ৴ݩʹ͸Τϥʔ͕ฦΔ Q.τϥϯβΫγϣϯʹઃఆͰ͖ΔGas Limitͷ஋͸࠷ߴ͍ͭ͘ʁ A. ཧ࿦্͸ϒϩοΫͷGas Limitͱಉ͡
  32. Q&A 2 Q. ϒϩʔυΩϟετͨ͠τϥϯβΫγϣϯΛ࡟আ͍ͨ͠৔߹Ͳ͏͢Ε͹ྑ͍ͷʁ A. EthereumͰ͸ϒϩʔυΩϟετͨ͠τϥϯβΫγϣϯͷ࡟আػೳ͸͋Γ·ͤΜɻԾʹɺτϥϯβΫ γϣϯΛͳ͔ͬͨ͜ͱʹ͍ͨ͠ (ૹۚΛऔΓফ͍ͨ͠) ৔߹͸ɺಉ͡NonceͰValue஋Λ0ʹ͠Gas PriceΛߴ͍΋ͷʹ࡞੒ͯ͠ϒϩʔυΩϟετ͢Δ

    Q. ૹۚͷΈͰར༻ͨ͠৔߹ͷख਺ྉͬͯͲ͏ͳΔͷʁ A. GasPrice × τϥϯβΫγϣϯͷόΠτ௕ ͷ஋͕ख਺ྉʹͳΔ Q. TxPoolͷ྆ʑ͕ᷓΕΔ΄ͲτϥϯβΫγϣϯ͕ཷ·ͬͨ৔߹ɺᷓΕͨτϥϯβΫγϣϯ͸Ͳ͏ͳΔ ͷʁ A. τϥϯβΫγϣϯͷGasPrice͕௿͍΋ͷ͔ΒPool͔Β௥͍ग़͞Ε͍ͯ͘ Q. NonceͷॱংͰɺઌʹߴ͍NonceͷτϥϯβΫγϣϯΛϚΠφʔ͕ϚΠχϯά͠ɺϚΠχϯάʹ੒ޭ ͨ͠৔߹ɺϒϩοΫ͸Ͳ͏ͳΔͷʁ A. ԾʹɺϚΠχϯάʹ੒ޭͨ͠ͱͯ͠΋ɺNonceͷॱংΛक͍ͬͯͳ͍τϥϯβΫγϣϯΛؚΜͩϒ ϩοΫ͸ແޮͱͳΓɺνΣʔϯʹܨ͕Εͳ͍
  33. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ✨