develop custom_top_html:no
default debug random = 0 / type = READ / detected = READ

개발을 하다보니 이런저런 인코딩이 많이 있어서

 

이더리움에 있는 RLP인코딩도 어디 뭐 인코딩 가져온 것인줄 알았는데

 

이더리움 데이타 저장을 위해 만든 인코딩이더군요.

 

여튼 개발을 위해 고민을 많이 한 흔적이 보입니다.

 

개발에 관심있는 분은 한 번 읽어보세요.

 

제가 중간중간 번역을 할 수도 있어서 원본을 일단 복사해서 옵니다. 양해 부탁드립니다.

 

위키문서에 추가 설명을 더 붙여놓아서 설명이 잘되어 있습니다.

 

원본링크 : https://medium.com/coinmonks/data-structure-in-ethereum-episode-1-recursive-length-prefix-rlp-encoding-decoding-d1016832f919

 

--------------------------------------------------------

 

Data structure in Ethereum | Episode 1: Recursive Length Prefix (RLP) Encoding/Decoding.

There are literally a lot of papers, blogs which explain how Ethereum organizes its data, but they all seem to be so disconnected and really hard to get an overall picture. In order to help you and confirm my understanding by the way, this series will explain one by one problem of data structure in Ethereum.

I will break out this subject into 5 main episodes and 1 extra espisode (I will call it the 1+ espisode):

  1. Recursive Length Prefix (RLP) Encoding/Decoding. And 1+ for Hex Prefix Encoding.
  2. Trie — Radix and Merkel.
  3. Trie — Patricia.
  4. Examples.
  5. State Tree Pruning.

First of all, we are going to make sense about RLP, so what is the purpose of RLP in Ethereum?

Recursive Length Prefix (RLP)

In computer science, data serialization is necessary for many complex data forms to be stored or transmitted in only one formal format. Because of that, RLP is an encoding/decoding algorithm that helps Ethereum to serialize data and possible to reconstruct them quickly.

RLP Encoding

As Ethereum mentioned, the RLP encoding function takes in an item. An item is defined as follows

  • A string (will be converted to byte array) is an item
  • A list of items is an item

For example, all of objects below are items:

  • “dog”
  • []
  • [“dog”]
  • [[], “dog”, [“cat”], “ ”]

RLD encoding is defined as follow:

  1. If input is a single byte in the [0x00, 0x7f] range, so itself is RLP encoding.
  2. If input is non-value (uint(0), []byte{}, string(“”), empty pointer …), RLP encoding is 0x80. Notice that0x00 value byte is not non-value.
  3. If input is a special byte in [0x80, 0xff] range, RLP encoding will concatenates 0x81 with the byte, [0x81, the_byte].
  4. If input is a string with 2–55 bytes long, RLP encoding consists of a single byte with value 0x80 plus the length of the string in bytes and then array of hex value of string. It’s easy to see that the first byte is in [0x82, 0xb7]range.
    For example: “hello world” = [0x8b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64] , because “hello world” has 11bytes in dec or 0x0b in hex, so the first byte of RLP encoding is 0x80 + 0x0b =0x8b , after that we concatenate the bytes of “hello word”.
  5. If input is a string with more than 55 bytes long, RLP encoding consists of 3 parts from the left to the right. The first part is a single byte with value 0xb7 plus the length in bytes of the second part. The second part is hex value of the length of the string. The last one is the string in bytes. The range of the first byte is [0xb8, 0xbf].
    For example: a string with 1024 “a” characters, so the encoding is “aaa…” = [0xb90x040x00, 0x61, 0x61, …]. As we can see, from the forth element of array 0x61 to the end is the string in bytes and this is the third part. The second part is 0x040x00 and it is the length of the string 0x0400 = 1024. The first part is 0xb9 = 0xb7 + 0x02 with 0x02 being the length of the second part.
  6. If input is an empty array, RLP encoding is a single byte 0xc0.
  7. If input is a list with total payload in 0–55 bytes long, RLP encoding consists of a single byte with value 0xc0 plus the length of the list and then the concatenation of RLP encodings of the items in list. The range of the first byte is [0xc1, 0xf7].
    For example: [“hello”, “world”] = [0xcc, 0x85, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x85, 0x77, 0x6f, 0x72, 0x6c, 0x64]. In this RLP encoding, [0x85, 0x68, 0x65, 0x6c, 0x6c, 0x6f] is RLP encoding of “hello”[0x85, 0x77, 0x6f, 0x72, 0x6c, 0x64] is RLP encoding of “world” and 0xcc = 0xc0 + 0x0c with 0x0c = 0x06 + 0x06 being the length of total payload.
  8. If input is a list with total payload more than 55 bytes long, RLP encoding includes 3 parts. The first one is a single byte with value 0xf7 plus the length in bytes of the second part. The second part is the length of total payload. The last part is the concatenation of RLP encodings of the items in list. The range of the first byte is [0xf8, 0xff] .
  9. One more thing, it is not mentioned in wiki Ethereum but in Golang source code. With boolean type, true = 0x01 and false = 0x80 .

RLP Decoding

RLP decoding is easier when you figure out how RLP encoding works. Actually, RLP decoding just receives encoded input and decodes the type, the length of that data.

  1. According to the first byte of input, RLP decoding analyses data the type, the length of the actual data and offset.
  2. According to the type and the offset of data, decode data correspondingly.
  3. Continue to decode the rest of the input if still possible.
RLP decoding is fully explained in wiki Ethereum and I don’t wanna waste our time on repeating something unnecessarily. I will put the references below.
 

Diving into RLP

Actually, Ethereum wiki has explained RLP extremely easy to understand, so I just reminded them by my writing style and what I expect in this article is about diving into RLP and getting deep understanding. Hmmm, again 
[알림: 이 게시글은 관리자에 의해 '블록체인'에서 '개발'로 이동되었습니다]
6,168

쌍둥아빠님의 서명

댓글 2
default debug random = 0 / type = READ / detected = READ

List of Articles
번호 분류 제목 추천 수 조회 수 글쓴이 날짜
1560 개발 test 거래소 상장 준비중이라 개발중 말한 내용중 보안과 관련이 조금 이라도 있다는 내용을 삭제 중입니다. 양해 바랍니다. 감사합니다. ------------------- 꼬리말 * 게시글 내용 삭제시 레벨 강등... 15 2 3166
Xmessiah
2019.02.03
1559 질문 안녕하세요. 국내 eos, eth, trx dapp관련 큰 커뮤니티 혹시 아시나요?     2019년은 dapp의 해가 될 것 같은데 해당 커뮤니티 아시면   추천부탁드리겠습니다!   행복한 연휴되세요!!   ------------------------------------- 꼬리말 * 게시글 내용 삭제시 레벨 강... 1 0 883
코인코1
2019.02.02
1558 질문 흥미가 생겨서 코인을 만들던중 궁금한게 있어서 남깁니다.   https://etherscan.io/token/0x59f2e9311cc43f731e18bd2b9b573aca42f670c1#readContract     보면 Readcontract 다른 코인들은 다 기입이 되어있는걸 알고있습니다   그래서 저도 보이게 하려... 3 1 1195
빵빵한포도알
2019.02.02
1557 질문 거래소에서 ERC20 코인 지갑생성과 관련되어 질문있습니다. 업비트 거래소에서 ERC20코인 지갑을 생성하고 이더스캔에 생성된 지갑 주소를 검색하면 지갑 타입이 Address가 아닌 Contract형으로 나오는데    굳이 Smart Contract 형의 주소로 발급해야 하... 1 0 1089
나비잠
2019.02.01
1556 질문 이더리움을 개발하는 사람들은 모두 몇명이나 되나요?     이더리움 재단의 비탈릭같은 개발자들이 몇명있나 있는지 문득 궁굼하네요   혹 아시는분 있으시면 부탁드려요                   ------------------------------------- 꼬리말 * 게시글 ... 3 0 1746
신화창조7
2019.01.31
1555 질문 리플 질문입니다~       안녕하세요 리플 공부중입니다 .   포스트맨으로 rpc테스트중인데  {     "method": "wallet_propose",     "params": [         {             "seed": "snoPBrXtMeMyMHUVTgbuqAfg1SUTb",... 4 0 892
피로
2019.01.30
1554 개발 [강좌] 이더소셜 PHP API 서버 만들기 #4. 계정 트랜젝션 개수 확인하기 안녕하세요. 쌩광부입니다.   한동안 ESN 재단 설립 때문에 너무 바빠서 강좌를 못했었는데요. 오늘 ESN 재단 구성원 모집이 완료되어 한시름 놓았습니다. 그리하여... 다시 강좌를 시작하도록 ... 3 13 3274
쌩광부
2019.01.29
1553 질문 메타마스크 문의드립니다. 컴퓨터 밀고 재설치했습니다. 구글 로그인하고 메타마스크 들어가보니 다시 가입하라고 나오더라구요. 가입하면 전에 지갑 다시 나오겠지 했는데... 새로 가입된걸로 되있습니다. 예전 계정으로 ... 4 0 1495
심퉁이
2019.01.29
1552 질문 이걸 이용해서 다른게시판 ..   https://github.com/esoodev/crawler-inven-archeag   자꾸 죄송합니다 ㅠㅠ..이걸 이용해서 오버워치 인벤 제목만 파싱하고싶은데 url만 바꾸면 될까요?                   -----------------... 4 0 765
허니잼
2019.01.28
1551 질문 인벤게시판 파싱을 하고싶은데..     파이썬을 이용해서 게시글 제목을 파싱하고싶은데.. 초보라서 잘이해를 못하겠습니다..ㅜㅜ도움 부탁드립니다..                   ------------------------------------- 꼬리말 * 게시글 ... 5 0 1112
허니잼
2019.01.28
1550 질문 추적60분 kbs token 링크 아시는 분 ?     1시간만에 뚝딱 만들어낸다   는  추적60분 kbs token 그 사이트 링크 아시는 분 ? 계세염?   한~~~ 참~~구글정보바다를 검색해봤는데,,,,와~~따~~~ 찾기 어려움....요                     ... 3 file 0 1974
내가총대멘다
2019.01.26
1549 질문 현재 이더리움 풀노드 데이타 폴더 용량이 얼마인지요? 어떤것은 250기가쯤 되고 어떤것은 460기가가 넘네요.                       ------------------------------------- 꼬리말 * 게시글 내용 삭제시 레벨 강등 * 질문은 각 주제별 게시판에 적어... 2 0 1967
김대박
2019.01.25
1548 질문 블록체인 인포 같은 사이트를 어떤식으로 만들어야되나요?ㅠ       라이트코인 기반으로 알트코인 만들었는데요   블록체인 인포처럼 저의 알트코인에 대한 정보들을 확인 하고 싶습니다.   웹쪽을 다뤄보지 않아서 처음부터 작업 해보려니 뭐 부터 해야될... 2 0 658
김깡
2019.01.25
1547 개발 카카오게임 개발에 관심있는 개발자분이라면 한번 참조해볼만한..   카카오 클레이튼에 올라가는 보라 플랫폼이 해커톤을 진행한다네요.   게임 댑 개발을 주제로 하니까 참가해보면 좋을것 같습니다.   http://www.fnnews.com/news/201901141819407902         ... 1 file 0 1091
코인끝판킹마
2019.01.25
1546 개발 나비 코인 계속 돌려 보며 안정화 시키는데 생각 보다 많이 걸렸습니다 많은 조언 감사하고 기왕 만든거 계속 개선하고 개발하겠습니다... 감사합니다. www.nabi-coin.com           ---------------------... 5 1 2650
Xmessiah
2019.01.24
1545 개발 게임 해커톤 개발 공모전     게임 해커톤 개발 대회 진행하네요. 관심 있으신 분들 첨고하시길   http://www.fnnews.com/news/201901141101354291   블록체인 콘텐츠 플랫폼 '보라' 게임 개발자 대상 해커톤 진행   록체... 0 1197
수영귀신
2019.01.24
1544 질문 완전 생초보 개발자가 읽을만한 서적 추천 부탁드립니다.. *** 답변 댓글이 있을 때 글 내용 삭제시 경고 없이 계정이 정지됩니다. *** *** 개인정보가 포함된 경우 혹은 불법적인 요소의 수정은 가능합니다.*** ---------------------------------------... 2 0 947
김승리
2019.01.24
1543 질문 라이트코인을 포크해서 노드 연결 하려고 하는데 질문좀 드립니다~!! 현재 라이트코인을 포크해서 네트워크 구축 해보려고 하고 있습니다.   일단 네트워크는 구축 되어 있는 상태이고 가상머신으로 두개로 노드간 연결 하려고 하고 있습니다.   접속하려는 노드에 ... 5 0 970
김깡
2019.01.24
1542 질문 자바스크립트로 파이썬의 자동화프로그램을 대부분 구현할수있나요?       초보자다 보니 여러언어들이 어떻게 쓰이나보다가 구글에서 우연히 어떤글을 봤는데  혹시 모르니 링크를 드리겠습니다 https://nanite.tistory.com/74   요약하면 파이썬 별론데 요즘 왜 ... 8 1 3715
5년존버
2019.01.22
1541 개발 쇼핑몰 오피스에 코인지갑을 생성하는 문제에 대한 질문입니다. 꾸벅~   쇼핑몰에서 포인트로 전환하여 쇼핑을 할수 있는 코인을 만들었고 거래소에 상장까지 해둔 상태입니다. 쇼핑몰 마이오피스에 해당코인 지갑을 만들고 해당코인을 주고 받을수 있도록 하려고 하... 7 0 913
timing7
2019.01.22
Board Pagination Prev 1 ... 10 11 12 13 14 15 16 17 18 19 ... 92 Next
/ 92
default debug random = 0 / type = READ / detected = READ