Bytecode and the EVM: what contracts compile into
What a contract actually is on-chain
A smart contract, as users experience it, is an address with functions - but what the chain stores at that address is bytecode: a sequence of low-level operations the virtual machine executes. The human-written source code - the readable program developers write - is compiled into bytecode by a compiler, and the bytecode is what the network runs, stores, and charges gas against. Understanding the compilation gap - from readable source to executed opcodes - explains contract behavior that otherwise looks magical: why gas costs differ between operations that look similar in source, why contracts behave deterministically across thousands of nodes, and why the execution environment's constraints shape what contracts can do at all.
The EVM: a stack machine with rules
- The virtual machine: the Ethereum Virtual Machine is a stack-based execution environment - programs are sequences of operations that push and pop values on a stack - running identically on every node. Determinism is the design goal: the same bytecode, the same input state, and the same transaction produce the same output state on every machine on earth, because every node runs the same instruction set with the same semantics.
- The instruction set: bytecode is a sequence of opcodes - one-byte operation codes - each with defined behavior: arithmetic, comparison, storage access, memory manipulation, control flow, and contract calls. The set is small and fixed, and its semantics are specified precisely so that implementations cannot diverge: the specification is the contract's real contract.
- Gas per opcode: every operation has a gas price - storage writes cost far more than arithmetic, contract calls cost more than comparisons - and the pricing encodes the environment's constraints: expensive operations are the ones that consume shared resources - state growth, propagation time, verification effort. Gas is the EVM's rationing system, and it prices operations by their external cost, not their computational effort.
- The execution envelope: contracts execute inside bounds - call depth limits, memory limits, block gas ceilings - that prevent any single execution from consuming unbounded resources. The envelope is why contracts are Turing-complete in theory but bounded in practice, and the bounds are features: they keep execution verifiable and blocks producible.
What compilation does - and loses
- What is lost in translation: source-level readability - the bytecode carries no names, no types as humans understand them, and no structure beyond the opcode stream - and some semantic guarantees: the compiler enforces type safety at compile time, but the bytecode's execution is unchecked at runtime beyond the EVM's own rules.
- What survives: behavior - the bytecode executes exactly the semantics the source specifies, and the EVM's determinism guarantees the same behavior on every node. The compilation gap is a readability gap, not a behavior gap: users interact with behavior, and behavior survives compilation intact.
- The verification layer: because bytecode is opaque, the ecosystem built verification tools - decompilers, disassemblers, and verification services that map bytecode back to readable source - and the tools matter because contract auditing happens at the bytecode level for deployed contracts: what runs is what gets verified.
Why the architecture matters for users
Reading bytecode claims correctly
The takeaway
Contracts compile from readable source into bytecode - opcode sequences for the EVM, a deterministic stack machine whose identical execution on every node is the trust foundation of the whole system. Gas prices opcodes by their external cost, the execution envelope bounds every run, and the compilation gap costs readability but preserves behavior exactly. Reading the stack correctly means treating bytecode as the real contract, gas bills as opcode invoices, and determinism as the property that makes code enforceable. The EVM is small, fixed, and specified to the letter - and its constraints are the reason contracts can run everywhere at once, produce the same result for everyone, and be charged fairly for what they consume. The bytecode is the contract's body; the source is its biography; and the machine runs the body.