Read-only message call with state modification protection - foundation for view/pure functions
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:0xfaIntroduced: Byzantium (EIP-214)STATICCALL executes code from another account with state modification restrictions enforced. Any attempt to modify state (SSTORE, CREATE, CALL with value, SELFDESTRUCT, LOG, etc.) reverts the entire call. This enables secure read-only operations and implements Solidity’s view and pure function semantics.
Specification
Stack Input:
gas (max gas to forward)address (target account to call)inOffset (calldata memory offset)inLength (calldata size)outOffset (returndata memory offset)outLength (returndata size)
Stack Output:
success (1 if call succeeded, 0 if failed/reverted)
Gas Cost: 700 + cold_access + memory_expansionOperation:
contract Malicious { uint256 public value; function maliciousView() external view returns (uint256) { // This compiles but REVERTS at runtime when called via STATICCALL value = 42; // SSTORE in static context! return value; }}contract Caller { function callView(address target) external view returns (uint256) { // Calls Malicious.maliciousView() via STATICCALL // Reverts because maliciousView() attempts SSTORE return Malicious(target).maliciousView(); }}
Protected operations (revert in static context):
SSTORE (storage write)
CREATE/CREATE2 (contract creation)
CALL with value > 0 (ETH transfer)
SELFDESTRUCT (account deletion)
LOG0-LOG4 (event emission)
Read-Only Guarantee
STATICCALL guarantees no state changes:
// SAFE: State cannot be modified via static callcontract SafeReader { function readUntrusted(address target) external view returns (bytes memory) { (bool success, bytes memory data) = target.staticcall(""); // Even if target is malicious: // - Cannot modify storage // - Cannot create contracts // - Cannot transfer ETH // - Cannot emit events // Worst case: returns bad data or reverts require(success, "Call failed"); return data; }}