Apologies in advance if it's a silly question. I'm slowly making my way through the ethereum yellow paper.

Am I correct in saying that the ethereum world state does not contain any EVM code? It only contains hashes of the code, right?

My train of thought is the following:

1) The world state is an aggregate key-value mapping of address --> 4 elements

2) The 4 elements are: nonce, balance, storageRoot and codeHash

3) None of those 4 elements has any code, the closest is codeHash which contains just a hash of the code, but not the code itself

So if the world state database does not contain any contract code, where is the contract code stored? Or otherwise, which one of my statements is incorrect?


2 Answers 2


The code is stored in the state db just like everything else - as a key-value pair. The only reason the codeHash is used instead of the code is that when the nonce, balance, or storageRoot change, you have to rehash the 4 together to get the root of that account. If you used the code instead of the codeHash, you'd have to rehash all that data again, which is much more expensive then just using the codeHash which never changes.

It also allows other optimizations like avoiding storing codeHash -> code multiple times for contracts that have the same code.


It looks like the code is stored the same way as all the tree nodes — in a low-level database of byte array hashes to the byte arrays themselves. It is not stored in the world state (implemented as a higher-level Modified Merkle Patricia Tree), which is exclusively a mapping of account address hashes to the account states.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.