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

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

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

Transcript

  1. 4.
  2. 5.
  3. 6.

    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
  4. 7.

    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
  5. 8.

    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 ϦʔϑϊʔυͷϋογϡΛ఻೻ͤࠜ͞ϊʔυͷϋογϡΛ࡞Δ ༿ͷ஋Λมߋ͢Δͱࠜϊʔυͷϋογϡ͕มΘΔ ໦શମΛ஌Βͳͯ͘΋༿ͷ஋ͷଘࡏΛ͔֬ΊΒΕΔ
  6. 9.

    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 ϦʔϑϊʔυͷϋογϡΛ఻೻ͤࠜ͞ϊʔυͷϋογϡΛ࡞Δ ༿ͷ஋Λมߋ͢Δͱࠜϊʔυͷϋογϡ͕มΘΔ ໦શମΛ஌Βͳͯ͘΋༿ͷ஋ͷଘࡏΛ͔֬ΊΒΕΔ
  7. 11.

    ΠʔαϦΞϜͷ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 ʜ
  8. 12.

    ΠʔαϦΞϜͷσʔλߏ଄ͷཁॴ  .FSLMF1BUSJDJB5SFF  )1&ODPEJOH  3-1&ODPEJOH  σʔλछผ͝ͱʹ໦͕͋Δ 

    ֊૚ߏ଄͕͋Δ Y%%"&#G&#$$#'EBD% YCEDCCDEECD    )"4) 4UPSBHF5SJF3PPU  )"4) lz < )"4) ʜ  )"4) lz > *NQMFNFOUFEJO"1BUSJDJB5SJF
  9. 13.

    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/  ୯७ൺֱͰ͖ͳ͍
  10. 15.

    &UIFSFVNʹ͓͚ΔA.PEJpFEA.FSLMF1BUSJDJB5SJF  छྨͷϊʔυ EP DB HF OF U Q ύτϦγΞ໦

    EP DB HF OF U Q ʹ CSBODI FYUFOTJPO MFBG  /6--  -FBG  &YUFOTJPO  #SBODI
  11. 21.

    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 < > < <>
  12. 23.

    σίʔυ๏จࣈྻ Y YD Y⒎ ࢒ΓͷCJU ಡΈࠐΜͩઌ಄ͷόΠτ͕ͷ࢒ΓͷCJUͷ͏ͪઌ಄CJUͩͬͨ৔߹͸ɺจࣈྻ͕Τϯίʔυ͞Ε͍ͯΔ จࣈྻΛද͢ YC YC จࣈҎԼͷจࣈྻ

    จࣈҎ্ YCG Y͔ΒYCޙଓΛYYόΠτ෼ɺจࣈͱͯ͠σίʔυ ઌ಄ͷόΠτ͕ ྫ G ઌ಄YYόΠτ෼ͷจࣈྻY YG Y Y UP4USJOHGPVS
  13. 24.

    σίʔυ๏௕͍จࣈྻ Y YD Y⒎ ಡΈࠐΜͩ࠷ॳͷόΠτ͕ͷ࢒ΓͷCJUͷ͏ͪઌ಄CJUͩͬͨ৔߹͸ɺจࣈྻ͕Τϯίʔυ͞Ε͍ͯΔ  จࣈྻΛද͢ YC YC จࣈҎԼͷจࣈྻ

    จࣈҎ্ YCG ࠷ॳͷόΠτ͕ YC͔ΒYCGޙଓ͕จࣈྻ௕ͷ YYC ͷ௕͞ͷόΠτදݱ จࣈྻͱͯ͠σίʔυ ྫͱͯ͠ڥ໨ΛݟΔ
  14. 26.

    σίʔυ๏̑௕͍Ϧετ YD Y⒎ ϦετΛද͢ QBZMPBE༰ྔόΠτҎԼͷϦετ 0UIFSXJTF YD͔ΒYGޙଓ͸ YG YG ࠷ॳͷόΠτ͕

    ಡΈࠐΜͩ࠷ॳͷόΠτ͕࢒ΓͷCJUͩͬͨ৔߹͸ɺϦετ͕Τϯίʔυ͞Ε͍ͯΔ  Ϧετͷ༰ྔͷόΠτදݱͷ௕͞ Ϧετ಺༰ͱͯ͠σίʔυ ྫYGYY Y ʜ YGYGYGYϦετ༰ྔ͸όΠτͰදͤΔ YϦετ༰ྔ͸όΠτ
  15. 28.

    3-1Τϯίʔυ͞Εͨঢ়ଶΛ೷͖ݟΔ  LFZWBMVFσʔλϕʔεͷࡏΓॲ  -FWFM%#  HFUIͷ৔߹EBUBEJSͰࢦఆͨ͠σΟϨΫτϦʹ֨ೲ͞Ε͍ͯΔ  (6*ϥΠϒϥϦ୭͔஌Γ·ͤΜ͔ʜ 

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