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

イーサリアムのデータ構造

 イーサリアムのデータ構造

イーサリアムのデータ構造を「状態」の観点から掘り下げます
- Merkle Patricia Trie
- RLP Encoding
- State Trie / Storage Trieを実際に見てみる

More Decks by Masashi Salvador Mitsuzawa

Other Decks in Technology

Transcript

  1. The world state (state), is a mapping between addresses (160-bit

    identifiers) and account states (a data structure serialised as RLP,..) [Ethereum Yellow Paper Chapter 4] XPSMETUBUF͸ΞυϨεͱঢ়ଶͷϚοϐϯάͰද͞ΕΔ  ΞυϨε͕Ωʔ  ঢ়ଶ͕஋  3-1Τϯίʔυ͞Ε͍ͯΔ  ࢒ߴ  /PODF  $PEFIBTI  4UBUF3PPU Y%%"&#G&#$$#'EBD% YCEDCCDEECD YFDEFDBEFGBDFG     )"4) 4UPSBHF5SJF3PPU  )"4) lz < )"4) ʜ  )"4) lz > YGEʜʜCCGBEEB
  2. Though not stored on the blockchain, it is assumed that

    the implementation will maintain this mapping in a modified Merkle Patricia tree [Ethereum Yellow Paper Chapter 4] Ϛοϐϯά͸ϚʔΫϧύτϦγΞ໦ͱͯ͠อଘ͞ΕΔ  LFZWBMVFͰঢ়ଶΛอଘ͢ΔͨΊͷσʔλߏ଄  ޮ཰తͳΩʔ୳ࡧ  CJUDPJOͰ΋͓ͳ͡ΈͷϚʔΫϧπϦʔ  .FSLMF5SFF.FSLMF1SPPG %& %&" '$    YCB Y'' Y$$ <          " # $ % & '> %& <          " # $ % & '> YCB Y'' Y$$ $ 3PPU
  3. Though not stored on the blockchain, it is assumed that

    the implementation will maintain this mapping in a modified Merkle Patricia tree [Ethereum Yellow Paper Chapter 4] Ϛοϐϯά͸ϚʔΫϧύτϦγΞ໦ͱͯ͠อଘ͞ΕΔ  LFZWBMVFͰঢ়ଶΛอଘ͢ΔͨΊͷσʔλߏ଄  ޮ཰తͳΩʔ୳ࡧ  CJUDPJOͰ΋͓ͳ͡ΈͷϚʔΫϧπϦʔ  .FSLMF5SFF.FSLMF1SPPG W W W W I W I W I W I W I I W  I W I I W  I W I ʜ / W W W I W I W I W I O I I O  I W I I W  I W I ʜ @OFX ϦʔϑϊʔυͷϋογϡΛ఻೻ͤࠜ͞ϊʔυͷϋογϡΛ࡞Δ ༿ͷ஋Λมߋ͢Δͱࠜϊʔυͷϋογϡ͕มΘΔ ໦શମΛ஌Βͳͯ͘΋༿ͷ஋ͷଘࡏΛ͔֬ΊΒΕΔ
  4. Though not stored on the blockchain, it is assumed that

    the implementation will maintain this mapping in a modified Merkle Patricia tree [Ethereum Yellow Paper Chapter 4] Ϛοϐϯά͸ϚʔΫϧύτϦγΞ໦ͱͯ͠อଘ͞ΕΔ  LFZWBMVFͰঢ়ଶΛอଘ͢ΔͨΊͷσʔλߏ଄  ޮ཰తͳΩʔ୳ࡧ  CJUDPJOͰ΋͓ͳ͡ΈͷϚʔΫϧπϦʔ  .FSLMF5SFF.FSLMF1SPPG W W W W I W I W I W I W I I W  I W I I W  I W I ʜ / W W W I W I W I W I O I I O  I W I I W  I W I ʜ @OFX ϦʔϑϊʔυͷϋογϡΛ఻೻ͤࠜ͞ϊʔυͷϋογϡΛ࡞Δ ༿ͷ஋Λมߋ͢Δͱࠜϊʔυͷϋογϡ͕มΘΔ ໦શମΛ஌Βͳͯ͘΋༿ͷ஋ͷଘࡏΛ͔֬ΊΒΕΔ
  5. ΠʔαϦΞϜͷXPSMETUBUFͷભҠશମ૾4UBUFͱ4UPSBHF 4UBUF5SJF "DDPVOU4UPSBHF PVUPG&7. ,FZ LFZ CJU WBMVF CJU ,FZ

    ,FZ    7BMVF 7BMVF 7BMVF ,FZ LFZ CJU WBMVF CJU ,FZ ,FZ    7BMVF 7BMVF 7BMVF ,FZ LFZ CJU WBMVF CJU ,FZ ,FZ    7BMVF 7BMVF 7BMVF )BTI ʜ
  6. ΠʔαϦΞϜͷσʔλߏ଄ͷཁॴ  .FSLMF1BUSJDJB5SFF  )1&ODPEJOH  3-1&ODPEJOH  σʔλछผ͝ͱʹ໦͕͋Δ 

    ֊૚ߏ଄͕͋Δ Y%%"&#G&#$$#'EBD% YCEDCCDEECD    )"4) 4UPSBHF5SJF3PPU  )"4) lz < )"4) ʜ  )"4) lz > *NQMFNFOUFEJO"1BUSJDJB5SJF
  7. 1BUSJDJB5SJF5SJF τϥΠ໦ʣ  3FUSJFWBM ૝ىʣ͕ޠݯ  lEPHz  lEPHFz 

    lEPOF  lDBUz  lDBQz  จࣈྻݕࡧʹద͍ͯ͠Δ  จࣈྻ௕NɺσʔλαΠζ/ʹର͠  0 N  WTೋ෼୳ࡧ໦0 MPH/ จࣈྻू߹ τϥΠ໦Ͱͷදݱ  ͭͷϊʔυ͸֤จࣈΛද͢  ϊʔυ͸֤จࣈͷ෼͚ͩࢠϊʔυ΁ͷϙΠϯλΛ࣋ͭ  ࢠϊʔυ͕ͳ͍৔߹͸/6--΁ͷϙΠϯλΛ࣋ͭ  ಛ௃ ϝϞϦ࢖༻ྔ͕ଟ͍Lจࣈ࢖༻͢Δͱͯ͠ ʙ Ωʔͷ௕͕͞ҰఆͳΒ͹0   E D P H F O F B U Q Lจࣈ࢖༻͢Δͱ͖NMPH@L/  ୯७ൺֱͰ͖ͳ͍
  8. &UIFSFVNʹ͓͚ΔA.PEJpFEA.FSLMF1BUSJDJB5SJF  छྨͷϊʔυ EP DB HF OF U Q ύτϦγΞ໦

    EP DB HF OF U Q ʹ CSBODI FYUFOTJPO MFBG  /6--  -FBG  &YUFOTJPO  #SBODI
  9. LFZʹର͢ΔWBMVFͷγϦΞϥΠζํࣜ3-1&ODPEJOH The purpose of RLP is to encode arbitrarily nested

    arrays of binary data, and RLP is the main encoding method used to serialize objects in Ethereum. [Ethereum Wiki]  ܕΛѻΘͳ͍γϯϓϧͳγϦΞϥΠζख๏  Ϧετߏ଄ΛऔΓѻ͑Δ  LFZWBMVFͷϚοϓ͸αϙʔτ͍ͯ͠ͳ͍  ఆٛ  ΤϯίʔυͰ͖Δ΋ͷΞΠςϜ  จࣈྻ͸ΞΠςϜ  ΞΠςϜͷϦετ͸ΞΠςϜ όΠτྻΛѻ͏ lEPHz <lEPHz lXPMGz> < > <lEPHz lXPMGz> < > lXPMGz lz <lEPHz lXPMGz lz> < > lz <<lEPHz lXPMGz> lDBUz> < > lDBUz < > < <>
  10. σίʔυ๏จࣈྻ Y YD Y⒎ ࢒ΓͷCJU ಡΈࠐΜͩઌ಄ͷόΠτ͕ͷ࢒ΓͷCJUͷ͏ͪઌ಄CJUͩͬͨ৔߹͸ɺจࣈྻ͕Τϯίʔυ͞Ε͍ͯΔ จࣈྻΛද͢ YC YC จࣈҎԼͷจࣈྻ

    จࣈҎ্ YCG Y͔ΒYCޙଓΛYYόΠτ෼ɺจࣈͱͯ͠σίʔυ ઌ಄ͷόΠτ͕ ྫ G ઌ಄YYόΠτ෼ͷจࣈྻY YG Y Y UP4USJOHGPVS
  11. σίʔυ๏௕͍จࣈྻ Y YD Y⒎ ಡΈࠐΜͩ࠷ॳͷόΠτ͕ͷ࢒ΓͷCJUͷ͏ͪઌ಄CJUͩͬͨ৔߹͸ɺจࣈྻ͕Τϯίʔυ͞Ε͍ͯΔ  จࣈྻΛද͢ YC YC จࣈҎԼͷจࣈྻ

    จࣈҎ্ YCG ࠷ॳͷόΠτ͕ YC͔ΒYCGޙଓ͕จࣈྻ௕ͷ YYC ͷ௕͞ͷόΠτදݱ จࣈྻͱͯ͠σίʔυ ྫͱͯ͠ڥ໨ΛݟΔ
  12. σίʔυ๏̑௕͍Ϧετ YD Y⒎ ϦετΛද͢ QBZMPBE༰ྔόΠτҎԼͷϦετ 0UIFSXJTF YD͔ΒYGޙଓ͸ YG YG ࠷ॳͷόΠτ͕

    ಡΈࠐΜͩ࠷ॳͷόΠτ͕࢒ΓͷCJUͩͬͨ৔߹͸ɺϦετ͕Τϯίʔυ͞Ε͍ͯΔ  Ϧετͷ༰ྔͷόΠτදݱͷ௕͞ Ϧετ಺༰ͱͯ͠σίʔυ ྫYGYY Y ʜ YGYGYGYϦετ༰ྔ͸όΠτͰදͤΔ YϦετ༰ྔ͸όΠτ
  13. 3-1Τϯίʔυ͞Εͨঢ়ଶΛ೷͖ݟΔ  LFZWBMVFσʔλϕʔεͷࡏΓॲ  -FWFM%#  HFUIͷ৔߹EBUBEJSͰࢦఆͨ͠σΟϨΫτϦʹ֨ೲ͞Ε͍ͯΔ  (6*ϥΠϒϥϦ୭͔஌Γ·ͤΜ͔ʜ 

    (6*ϥΠϒϥϦ͕͋Ε͹΋ͬͱָʹ৭ʑʮ೷͚Δʯ͸ͣ  AOQNTUBSUͱ͸A  ֤छϥΠϒϥϦ  MFWFM%#  +BWB4DSJQUMFWFMVQMFWFMEPXO  1ZUIPOQZMWFM  3-1  FUIFSFVNKTSFQ  FUIFSFVNQZSMQ ඍົ͔΋ʁʣ ɹύτϦγΞ໦ +BWB4DSJQUFUIFSFVNKTNFSLMFQBUSJDJBUSFF