DEV Community

苏格拉路易驴
苏格拉路易驴

Posted on Fully Autonomous

From bytecode to a token transfer: an EVM opcode primer

When a wallet says “send tokens,” the EVM executes a contract one instruction at a time. Understanding that gap makes transaction traces much easier to read.

This is a short written companion to my opcode explainer. Start with three questions: what data enters the contract, where does execution go, and what state changes?

1. Read a tiny stack program

An opcode specifies an operation. Some instructions also consume immediate data from the bytecode. For example:

PUSH1 0x02   // stack: [2]
PUSH1 0x03   // stack: [2, 3] (top on the right)
ADD          // stack: [5]
Enter fullscreen mode Exit fullscreen mode

The corresponding bytes are 60 02 60 03 01. Each PUSH1 consumes the next byte as data; those data bytes are not separate instructions. This example is illustrative, rather than a complete deployed contract.

2. Follow the input into a contract

For a standard ABI function call, calldata begins with a four-byte selector, followed by encoded arguments. The selector comes from the first four bytes of the Keccak-256 hash of the canonical function signature.

The readable function name is not sent as a string for the EVM to look up. Contract bytecode handles dispatch. Instructions such as CALLDATALOAD, comparisons and conditional jumps can help implement that dispatch, but the actual sequence varies with compiler settings, optimisation and contract structure. A proxy may forward execution to another implementation.

That is why an ERC-20 transfer is not one universal token-transfer opcode. The token contract implements the balance checks and updates.

3. Separate working data from persistent state

Keep three places distinct when reading a trace:

  • Stack: operands used by instructions.
  • Memory: temporary working space for the current call.
  • Storage: persistent contract state, accessed by instructions such as SLOAD and SSTORE.

For a transfer, ask where the sender and recipient enter, where balances are read, which condition can revert, and which storage writes commit the result. The answer depends on the token implementation; do not assume every token has identical storage or behaviour.

4. Read gas in context

Gas measures execution work. The gas price is the price paid per gas unit. Counting instructions alone does not give a reliable transaction cost: some costs depend on state access, memory expansion or other execution details. Use the relevant fork's rules when analysing a trace.

A current example: proposed SLOTDURATION

As of November 9, 2026, Hadrien Croubois's EIP-8484 proposal is an open draft. It proposes an opcode exposing the current slot duration in milliseconds, helping contracts avoid hardcoded duration assumptions. It does not itself shorten slots and is not a live mainnet instruction.

Video and references

The English video also compares the EVM with Bitcoin Script:

This written companion was drafted by an AI assistant using my video topics and the linked references.

Top comments (0)