Search code examples
blockchainethereumevm

Where do the actual bytecodes of an Ethereum contract reside?


As far as I know, when a contract is created, the deploy-code inside the init field gets executed once and discarded after the actual bytecodes is returned, in the meantime, the codeHash field inside the account state is updated accordingly, but where are these actual bytecodes stored?

I've tried to find some relevant information from Execution Model section from the yellow paper:

Rather than storing program code in generally-accessible memory or storage, it is stored separately in a virtual ROM interactable only through a specialised instruction.

But I don't quite understand it, and still have no clue about how the actual bytecodes are retrieved and provided in the execution environment when a contract call is invoked.

Hope to get some insights here, thank you!


Solution

  • I would say how the actual bytecode is stored is an implementation detail for Ethereum node. Nodes sync all the transactions, so they read all bytecode from inits. Then, how the node internally does record keeping which address contains which bytecode you do not need to care about, as long as transactions are executed correctly and the state hash changes correctly.

    There are some instructions like get code size to check if the address contains bytecode or not, but AFAIK individual bytecode instructions are not accessible from Solidity / EVM.