I was researching how contract storage works. I know that the world state is a Merkle Patricia Trie, containing all active Ethereum adresses with their storageRoot (and their nonce, balance, and codeHash).

I have gained a better understanding of how a Merkle Patricia Trie works, and the fact that if you store all the key-values in the form of a Merkle Patricia Trie, all you need is the root hash (stored in storageRoot) to verify all the key-values.

I understand that each client has its own implementation. Go Ethereum uses levelDB (Google's key-value database), for instance.

The thing is that if a key-value is modified (because of contract execution), it creates a new node but doesn't delete the old one.

But I guess there are a lot of keys-values unique to each contract. And if every time a state variable is modified, a new node is created, but the old one isn't deleted, that's a crazy waste of space, isn't it? Is there something I'm missing here?

Thanks 🙏

  • Well, there is a reason the chain is now more than one terrabytes ;) Commented Jul 4, 2023 at 12:57
  • I have no idea where you took the idea that you could just simply update any key-value, all you can do with the root hash is verify data Commented May 24 at 18:01

2 Answers 2


After lots of research, here is my understanding:

In general, when information is updated (like the accounts balance, or contracts variable states values), a key/value database (which implements merkle patricia tries) will create a new node for the variable to be updated, update the rest of the tree (since all parent nodes will have a hash that will be updated, as in a Merkle tree), but the old node remains existing (and accessible).

This is useful, on the one hand, to have a state history (if you want to know the value of a variable in a contract in a previous block), but it's not required to keep this information.

So there are clients that allow you to synchronise a blockchain without this "history", but that also give you the possibility of synchronizing everything to have a complete history of everything that's happened.

  • Hi @Hackndo, I am wondering about deletions from trie myself. What makes you think that updated values create new nodes, instead of updating the "storage slot".
    – BipedalJoe
    Commented Dec 13, 2023 at 15:00
  • well, in general, when I cut and move a folder on my laptop. First, it gets copied, the folder moves somewhere else. But the old one still stays in the memory. Commented May 24 at 18:04

The point of Ethereum is that your data stays on-chain.

Going to the computing fundamentals because let's not overcomplicate.

What is Delete? Delete refers to the act of eliminating or removing a file, folder, or piece of information from a computer or electronic device.


You can overwrite the node to its initial state. It was certainly possible with Selfdestruct.

More information: https://www.alchemy.com/overviews/selfdestruct-solidity

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.