Overview
Opcode:0x35
Introduced: Frontier (EVM genesis)
CALLDATALOAD reads 32 bytes from the call data (input data passed to the contract) starting at a specified offset. Bytes beyond call data bounds are zero-padded.
Specification
Stack Input:Behavior
CALLDATALOAD loads exactly 32 bytes from call data, reading from the specified byte offset. If the offset extends beyond call data, the remaining bytes are padded with zeros. Key characteristics:- Always returns 32 bytes (256 bits)
- Zero-pads when offset + 32 > calldata.length
- Big-endian byte order
- Does not revert on out-of-bounds access
Examples
Basic Usage
Function Arguments
Zero Padding
Gas Cost
Cost: 3 gas (GasFastestStep) CALLDATALOAD shares the same cost tier with:- ADD, SUB (0x01, 0x03): 3 gas
- NOT, ISZERO (0x19, 0x15): 3 gas
- Comparison operations: 3 gas
- CALLDATALOAD (read 32 bytes): 3 gas
- CALLDATACOPY (copy N bytes): 3 + memory + copy cost
- MLOAD (read from memory): 3 gas
Common Usage
Function Selector Extraction
Manual ABI Decoding
Dynamic Array Length
Calldata Validation
Security
Out-of-Bounds Reading
Function Selector Validation
Calldata Bounds Check
Implementation
- TypeScript
Edge Cases
Offset Beyond Calldata
Partial Overlap
Zero Offset Empty Calldata
Maximum Offset
References
- Yellow Paper - Section 9.1 (Machine State)
- EVM Codes - CALLDATALOAD
- Solidity Docs - ABI Encoding
- EIP-211 - Related return data opcodes

