16 votes
Accepted

LevelDB in Geth, key and values

Let's start with having a look at what we get in geth console for block number 40. Now let's consider a Go program. I Explained everything in code comments about how it is constructing keys and ...
Vishal Sharma's user avatar
15 votes
Accepted

Why was RLP chosen as the low level protocol encoding algorithm?

RLP was chosen because of (1) simplicity of implementation, and (2) guaranteed absolute byte-perfect consistency. Source is Ethereum Wiki: RLP is intended to be a highly minimalistic serialization ...
eth's user avatar
  • 85.8k
11 votes
Accepted

Clarification of "256 bit word" semantics

It will be easier to understand if we make these two definitions (note: this might not be fully correct, but is enough for the following explanation): the EVM is the machine executing the ...
axic's user avatar
  • 2,569
9 votes

Clarification of "256 bit word" semantics

The EVM is always 256 bits big-endian. From the Yellow Paper, Appendix H: "When interpreting 256-bit binary values as integers, the representation is big-endian." RLP is different from the Contract ...
eth's user avatar
  • 85.8k
6 votes
Accepted

Ethereum network messaging

I wrote this on the gitter.im channel, so here it is again anyway. Caveat is I have not looked at recent geth code for this, so there may be subtle discrepancies with actuality. A key paragraph is ...
Sentinel's user avatar
  • 1,238
4 votes
Accepted

What does string mean in patricia tree wiki

Different computers store binary data differently. The purpose of the RLP as stated in the referenced document is to The purpose of RLP (Recursive Length Prefix) is to encode arbitrarily nested ...
Thomas Jay Rush's user avatar
4 votes
Accepted

RLP encoding of 0

It appears that encoding the integer 0 no longer equates to \x00 (as the documentation would imply). This can be seen both in your example, and in the fact that it can't be decoded: >>> ...
Richard Horrocks's user avatar
4 votes

Block header format

You can find the block header's structure in the Yellow paper, 4.4 (page 5). I don't have time to go through eveyrthing, but if I do not make any mistake, for example, you could bind the following: ...
Itération 122442's user avatar
4 votes
Accepted

Understanding serialized unsigned raw transaction

Partial answer. Why does the ChainId is 0x1c or 28 ? Given this list it don't understand. The link you point to shows network ID, which isn't the same as chain ID. Further, 28 isn't the chain ID, ...
Richard Horrocks's user avatar
4 votes
Accepted

How to decode the output of an eth_call that returns a Tuple[]

After re-reading https://docs.soliditylang.org/en/latest/abi-spec.html#use-of-dynamic-types with a fresher brain, I understood that the way the bytes are divided is as follows: first 32 bytes: offset ...
pestopasta's user avatar
3 votes

How to RLP-encode messages in Solidity

https://www.npmjs.com/package/solidity-rlp Here is a package I am maintaining to decode rlp bytes in solidity. you can checkout the code and usage instructions here: https://github.com/hamdiallam/...
Hamdi Allam's user avatar
3 votes
Accepted

Does RLP specify integer encoding?

RLP deals only in structures made up of bytes (binary data). It doesn't care whether those bytes represent strings, integers, big integers, floating point numbers or whatever. This is in the sentence ...
benjaminion's user avatar
  • 9,267
3 votes

RLP ethereum decoding

The other answer gives useful information, but to directly answer your question: RLP encoding does not give any information about types. It only encodes strings (byte sequences) and lists of lists/...
user19510's user avatar
  • 28k
3 votes
Accepted

Can I add leading zeroes at will when building an RLP-encoded transaction?

You can't. RLP can't have leading zeros. It is designed to encode values in a shortest way, so redundant leading zeros make RLP not canonical. What's more, transaction's RLP starts with payload ...
debris's user avatar
  • 861
3 votes

block hash from block-header rlp

Below are the steps to calculate blockHash, given a blockNumber: Step1. eth.getBlock(400000) Output:{ difficulty: '6022643743806', extraData: '0xd583010202844765746885676f312e35856c696e7578', ...
AnuragP's user avatar
  • 431
3 votes
Accepted

How are Ethereum 2 block hashes computed?

According to EIP-3675, with the transition to Proof of Stake: Each block field listed in the table below MUST be replaced with the corresponding constant value Field Constant value Comment ...
eth's user avatar
  • 85.8k
2 votes

RLP encoding of 0

RLP is defined in Ethereum Yellow Paper (Appendix A, page 16). There are few interesting quotes: We define the RLP function as RLP through two sub-functions, the first handling the instance when the ...
tmp's user avatar
  • 121
2 votes
Accepted

Confusion over RLP encoding for byte array > 55 bytes

It is just once the length of the byte array - the wiki describes it a bit confusing. Better look at the yellowpaper PDF (appendix RLP): https://ethereum.github.io/yellowpaper/paper.pdf Or an ...
ligi's user avatar
  • 1,183
2 votes

LevelDB in Geth, key and values

I think keys are needed to organize tree - to know how to move nodes in trie without knowledge of stored information, read about Patricia-Tree. In examples, they use keys to organize trie.
Gudsaf's user avatar
  • 317
2 votes
Accepted

How Merkle Tree obtain root node hash (example from 'Understanding the ethereum trie')?

I read code bad: when we got key = pack_nibbles(with_terminator('\x01\x01\x02') value = rlp.encode(['hello']) which is tantamount to: key = '\x01\x01\x02' value = '\xc6\x85hello' this value ...
Gudsaf's user avatar
  • 317
2 votes
Accepted

RLP Rationale Question

It says that RLP is simple unambiguous It's simpler than other algorithms because it doesn't define any data types other than bytes and arrays. It's unambiguous because the same input data is ...
medvedev1088's user avatar
2 votes
Accepted

geth inter-node communication (devp2p/rlpx) encryption

Does someone know if there is any documentation on encryption in the inter-node protocol? You might have already found these, but here are few sources I've used in the past: https://github.com/...
Richard Horrocks's user avatar
2 votes
Accepted

RLP decoding for a list

131 can't be encoded as just 0x83. From https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP: For a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding. 0x83 ...
user19510's user avatar
  • 28k
2 votes

Understanding serialized unsigned raw transaction

The byte 0xe6 was simply following the 3rd rule describing an rlp list serialized. tx = new ethTx({}); console.log('RLP-Encoded Tx: 0x' + tx.serialize().toString('hex')) Gives: 0x c9 ...
onepix's user avatar
  • 283
2 votes
Accepted

How to encode empty transaction fields?

All of these field have to be provided and should not be nil. There are generally 2 different types when encoding a transaction with RLP: 256-bit Number and a Bytes. So if we have an empty data we ...
Richard's user avatar
  • 4,954
2 votes
Accepted

How is the FROM address known for historic transactions?

The encoded transaction when decoded has properties v, r and s. { "nonce": "0x0", "maxFeePerGas": "0x1234", "maxPriorityFeePerGas": "0x1234&...
Sanjay S B's user avatar
  • 1,339
2 votes

How to decode the output of an eth_call that returns a Tuple[]

If you look at the source code of the contract, the return type of the function getAllReserveTokens is TokenData[] memory which is an array of a custom struct defined in the storage of the contract. ...
0xOsiris's user avatar
  • 149
2 votes
Accepted

Manually RLP-encoding an ETH tx gives an incorrect result

You need to convert tx["to"] to bytes before encoding. You also have tx["yParity"] where tx["v"] should be, per your syntax guide. from rlp import encode from web3.types ...
pacrob's user avatar
  • 181
1 vote

what type of encoding is used by the abi specification in solidity

May be I don’t fully understand your question, but I can say that it should be taken into account that ABI is not the internal coding for the contract, but the description of the interface in a human ...
Rick Park's user avatar
  • 3,194
1 vote
Accepted

How to RLP-encode messages in Solidity

I don't know if there is any native library available in Solidity, but there are node-js libraries available will help you do that. I also found this solidity code when doing a search on RLP, have a ...
drao's user avatar
  • 311

Only top scored, non community-wiki answers of a minimum length are eligible