There are many cases where the same contract gets deployed many times. Now obviously each contract has its own persistent data storage and everything, but is each contract’s bytecode also taking up space multiple times on Ethereum nodes’ computers? Or is there some mechanism that deduplicates contract code, and instead of saving all the code again and again, can just store it once and then on subsequent identical contract creation can just save something like <same as contract 0xABC...>?


According to my knowledge the bytecode will be stored only once. I came to this conclusion from section 4.1 of the yellowpaper

The account state comprises the following four fields:




codeHash: The hash of the EVM code of this account - this is the code that gets executed should this address receive a message call; it is immutable and thus, unlike all other fields, cannot be changed after construction. All such code fragments are contained in the state database under their corresponding hashes for later retrieval.

If the hash of the bytecode of 2 different contracts is the same then it should be stored in the state database under this hash only once. At least there is no reason not to implement it this way. To be certain we'd need to look into source code of particular implementation.


The node software can handle this however they want. I would assume they only store it once in their database, but the hash of the code will be stored in both locations.

Of course, this doesn't give the ability to save on gas during deployment, since you're still charged 200 gas per byte of contract code that you deploy. A good solution to this is a clone/proxy contract which forwards all calls/returns to another contract address using delegatecalls, meaning it runs the code of another contract in the storage context of the clone contract. We developed a contract that does this in only 96 bytes that can be found here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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