Internal memory format
The tries are stored in kernel memory, specifically in the
Segment:TrieData
segment. Each node type is stored as
-
An empty node is encoded as .
-
A branch node is encoded as , where each is a pointer to a child node, and is a pointer to a value. If a branch node has no associated value, then , i.e. the null pointer.
-
An extension node is encoded as , represents the part of the key associated with this extension, and is encoded as a 2-tuple . is a pointer to a child node.
-
A leaf node is encoded as , where is a 2-tuple as above, and is a pointer to a value.
-
A digest node is encoded as , where is a Keccak256 digest.
On the other hand the values or payloads are represented differently depending on the particular trie.
State trie
The state trie payload contains the account data. Each account is stored in 4 contiguous memory addresses containing
-
the nonce,
-
the balance,
-
a pointer to the account's storage trie,
-
a hash of the account's code.
The storage trie payload in turn is a single word.
Transaction Trie
The transaction trie nodes contain the length of the RLP encoded transaction, followed by the bytes of the RLP encoding of the transaction.
Receipt Trie
The payload of the receipts trie is a receipt. Each receipt is stored as
-
the length in words of the payload,
-
the status,
-
the cumulative gas used,
-
the bloom filter, stored as 256 words.
-
the number of topics,
-
the topics
-
the data length,
-
the data.