The Ethereum Virtual Machine

EVM bytecode

Bytecode is the compiled, machine-level form of a smart contract: a flat string of bytes that is nothing but opcodes and their inline data, ready for the EVM to execute. You write a contract in a high-level language like Solidity, the compiler translates it, and what actually lives on-chain is this raw byte string — for example 0x6080604052... — which humans rarely read directly but every node runs verbatim.

A subtle but essential distinction is between creation bytecode and runtime bytecode. When you deploy a contract you send the creation (init) bytecode in the transaction. The EVM executes that init code once — it runs the constructor, sets up initial storage, and then returns the runtime bytecode, which the protocol stores permanently at the new contract's address. Every later call to the contract executes only this stored runtime code; the constructor logic is gone and cannot be invoked again.

Runtime bytecode almost always begins with a dispatcher: a short prologue that reads the first four bytes of calldata (the function selector), compares it against the selectors of each public function, and jumps to the matching code. Solidity also appends a CBOR-encoded metadata trailer to deployed bytecode, containing a hash of the source/metadata (often an IPFS or Swarm hash) and the compiler version, which is what lets explorers verify that published source matches on-chain code.

Once stored, runtime bytecode is immutable — there is no opcode to overwrite a contract's own code. Upgradeability is therefore faked by indirection: a proxy holds storage and delegatecalls into a separate implementation contract whose address can be changed. Genuine code replacement only ever happened via SELFDESTRUCT followed by CREATE2 redeployment, a 'metamorphic' trick now largely neutralized as SELFDESTRUCT has been deprecated.

The 24,576-byte (EIP-170) cap is on runtime bytecode, not creation bytecode, which is why large constructors are fine but oversized deployed contracts must be split (e.g. via the diamond pattern).