This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
Overview
Opcode:0x36Introduced: Frontier (EVM genesis)CALLDATASIZE pushes the byte length of the call data (input data) onto the stack.
Specification
Stack Input:
[]
Stack Output:
size (uint256, in bytes)
Gas Cost: 2 (GasQuickStep)Operation:
stack.push(calldata.length)
Behavior
CALLDATASIZE returns the total number of bytes in the call data, including function selector.Key characteristics:
contract CalldataValidator { function requireMinimumCalldata(uint256 minSize) public pure { assembly { if lt(calldatasize(), minSize) { revert(0, 0) } } } function hasArguments() public pure returns (bool) { // Function selector = 4 bytes // If calldatasize > 4, has arguments return msg.data.length > 4; }}
Gas Cost
Cost: 2 gas (GasQuickStep)Same as ADDRESS, ORIGIN, CALLER, etc.
Common Usage
Bounds Checking
function safeDecod() public pure { assembly { // Ensure enough data for selector + 1 uint256 if lt(calldatasize(), 36) { revert(0, 0) } }}
Copying Entire Calldata
function forwardCalldata(address target) public { assembly { let size := calldatasize() calldatacopy(0, 0, size) let result := call(gas(), target, 0, 0, size, 0, 0) if iszero(result) { revert(0, 0) } }}