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

詳解 Ethereum Transaction / detail ethereum trans...

yamarkz
March 16, 2018

詳解 Ethereum Transaction / detail ethereum transaction

blockchain.tokyo #6

yamarkz

March 16, 2018
Tweet

More Decks by yamarkz

Other Decks in Technology

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

    Transaction • Message 4 Pattern • Transaction Life Cycle • Transaction for Data Structure • Transaction Pool & Nonce • Transaction Releasing
  4. ※ ίϯτϥΫτ࣮ߦͷΠϝʔδ ※ EtherʹΑΔࢧ෷͍ͷΠϝʔδ ίϯτϥΫτͷ࣮ߦ => τϥϯβΫγϣϯͷૹ৴ ICO΁ͷࢀՃ => τϥϯβΫγϣϯͷૹ৴

    Etherͷૹۚ => τϥϯβΫγϣϯͷૹ৴ ίϯτϥΫτͷ࡞੒ => τϥϯβΫγϣϯͷૹ৴ Ethereumʹ͓͍ͯɺTransaction͸શͯͷ࢝·Γ
  5. 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
  6. 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Λɺ ϚΠφʔ͕બ୒͢Δ
  7. 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
  8. 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෼͚ΒΕΔ
  9. 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Λɺ ϚΠφʔ͕બ୒͢Δ
  10. 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
  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. Transaction Nonce Gas Price Gas Limit To Value v, r,

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

    s Init or data ϢχʔΫͰ͋Δ͜ͱΛࣔ͢ ૹۚ͢ΔEtherͷֹ Contract࣮ߦ࣌ʹফඅ͢ΔGasͷ੍ݶ EVMίʔυ͕ೖΔϑΟʔϧυ Transaction Transaction for Data Structure
  14. 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෼͚ΒΕΔ
  15. Transaction Pool Transaction Pool (ҎԼɺTxPool)ͱ͸ɺϒϩοΫʹऔΓࠐ·ΕΔલͷτϥϯβΫγϣϯ͕Ұ࣌ తʹอଘ͞ΕΔۭؒɻۭؒ͸ϊʔυͷϚγϯϝϞϦ্ʹ࡞ΒΕΔɻ ϚγϯϝϞϦ্ʹ࡞ΒΕΔͨΊɺϚγϯͷిݯ͕མͪΔͱTxPool಺ͷτϥϯβΫγϣϯ΋ফ͑ Δɻ ϊʔυ͸ࣗ਎ͷϝϞϦۭؒʹؚΊΔτϥϯβΫγϣϯΛGasPriceͰબผ͢Δ͜ͱ͕Ͱ͖Δɻ TxPoolͷۭؒ͸2ͭ

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

    or ఻ൖ͞Εͨ͜ͱʹΑΓɺ QueuedͷTx͸nonceͷॱং͕ἧ͏ɻ ἧ͏͜ͱͰϚΠχϯάOKͳTxʹͳΓPendingʹҠಈ͢Δ
  17. 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ͷॱংʹԊͬͯτϥϯβΫγϣϯ͕ϒϩοΫʹऔΓࠐΉϓϩτίϧʹΑΓɺೋॏࢧग़Λ๷ ͍Ͱ͍Δɻ
  18. ɾWhat is Gas? ɾEthereum EVM Illustrated ɾMastering Ethereum ɾEthereum White

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

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

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