Subscribe to ETH Daily News

Get new posts delivered straight to your inbox.

ethereum -

Ethereum Opcodes: The Instructions Behind Smart Contracts

Opcodes are the low-level instructions the EVM executes to read data, change state, and calculate gas for smart-contract transactions.

Ethereum smart contracts run as sequences of low-level instructions called opcodes. Each opcode performs a defined operation, and the Ethereum Virtual Machine (EVM) executes those instructions across network nodes to produce the same state changes.

From source code to instructions

Developers usually write contracts in languages such as Solidity. A compiler turns that source code into bytecode, the instruction sequence stored on the blockchain. When a transaction calls a contract, an EVM processes the bytecode one instruction at a time. An opcode is the operation itself; its operands, often values or memory locations, determine what it acts on.

The EVM is a stack machine. It keeps intermediate values on a stack of 256-bit words, with a maximum depth of 1,024 items. For example, ADD takes two values from the stack and pushes their sum. Other instructions read or write temporary memory, access persistent contract storage, compare values, or direct execution to another location in the bytecode.

Common opcode groups

Arithmetic and comparison instructions include ADD, MUL, EQ and LT. Stack instructions such as PUSH, POP and DUP place values or rearrange them. Memory instructions such as MLOAD and MSTORE read and write temporary data during a transaction, while SLOAD and SSTORE access persistent contract storage. Environment instructions expose transaction or block data, including CALLER, CALLVALUE and NUMBER. Control-flow instructions such as JUMP and JUMPI change which instruction runs next, and CALL invokes another contract.

The names are short, but their behavior is precisely specified. The [Ethereum opcode reference](https://ethereum.org/developers/docs/evm/opcodes/) lists each instruction and its stack effects. [evm.codes](https://www.evm.codes/) provides an interactive reference for inspecting them.

Why opcodes matter

Every transaction consumes gas as the EVM executes instructions. Opcodes have gas costs, and some operations also incur costs that depend on factors such as memory expansion or storage access. The transaction's total gas use therefore reflects the work performed, not simply the number of lines in the original Solidity code. If execution runs out of gas or hits an invalid instruction, it stops; state changes from a reverted transaction do not persist, though the sender still pays for the gas used.

For developers, reading opcodes helps explain gas estimates, compiler output, and contract behavior during debugging or security review. For users, the same instructions sit beneath actions such as a token transfer or contract call, and their execution contributes to the transaction fee. Developers normally rely on higher-level languages, but the EVM ultimately processes bytecode.

A proposal for transaction assertions

Draft EIP-7906 proposes three opcodes that would let a transaction check what it did before its effects are finalized. TXTRACE would enumerate the transaction's net changes to balances, storage, deployed contracts and emitted events. TXDIFF would look up a particular balance, storage value, code hash or change record, while EVENTDATACOPY would copy an event's data for inspection.

The proposal depends on EIP-8141 and adds a read-only POST_TX frame at the end of a frame transaction. A wallet or application could use that frame to test the transaction's results against rules, such as whether an unexpected asset moved. If an assertion fails, the execution effects are rolled back, but the transaction is still included with a failed receipt and the gas used is still charged. That gives wallets a way to constrain outcomes after execution and could reduce blind signing risk. EIP-7906 is marked Draft, so these opcodes and behavior are a proposal, not currently deployed Ethereum behavior.

Advertise

ETH Daily is the trusted Ethereum news briefing since 2022, reaching 10,000+ subscribers. Want to reach the ETH Daily audience? Learn more at ethdaily.io/ads.


Disclaimer: Content is for informational and educational purposes only and does not constitute financial, investment, legal, or other professional advice. No representations or warranties are made as to accuracy, completeness, or timeliness. Use of this content is at your own risk, and you should consult a qualified professional before making decisions. No fiduciary or advisory relationship is created

Subscribe to our newsletter