In this track: Inside the EVM
advanced · 4 MIN READ

Calldata load and copy

Read message input as bytes before interpreting an ABI.

LET’S PICTURE IT

An incoming envelope contains raw bytes; a schema explains which parts are fields.

SEE IT FOR YOURSELF
Build a transfer call from typed fieldsStep 1 / 4
Build a transfer call from typed fieldstransfer(address,uint256)Recipient: 0x0000…0001Raw amount: 100Diagram labels abbreviate addresses; the lab shows full bytes4-byte selectora9059cbbEach box is one byte; this prefix is not a 32-byte wordWord 0 · recipient address12 zero bytes20 address bytes000…0001Left padding preserves the lower-order address valueSelector4 bytesa9059cbbAddress32 bytesword 0Amount32 bytesword 1 → 0x644 + 32 + 32 = 68 bytesThe integer does not contain token decimals or market price

The standard transfer interface takes an address and a raw integer amount. This diagram uses address one and amount one hundred.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Load a word from input

CALLDATALOAD reads thirty-two bytes beginning at a supplied calldata offset. Bytes beyond the input are treated according to the opcode’s zero-padding behavior.

Do not skip framing automatically

At offset zero, ordinary function input begins with a four-byte selector. A raw word load does not automatically remove that selector or decode the first argument.

Copy into memory explicitly

CALLDATACOPY copies a selected input range into memory. The destination uses memory byte offsets and may cause memory expansion.

Validate higher-level lengths

Zero-padding at opcode level does not make truncated ABI input semantically valid. A safe ABI decoder still checks that required fields and tails exist.

Trace the idea

ordinary calldata:
bytes 0–3: selector
bytes 4–35: first static argument word

CALLDATALOAD(4) can read that word when the schema and length are valid.

Stack examples list the bottom first and the top last. These small traces omit gas and surrounding dispatch unless stated.

QUICK CHECK · NO PRESSURE

Does CALLDATALOAD automatically decode an ABI argument?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.