EIP-2330 · Stagnant · Core · 2019-10-29
EIP-2330: EXTSLOAD opcode
Proposes an EXTSLOAD opcode that lets a contract read another contract's storage slot directly, skipping the cost of a CALL plus ABI encoding and decoding.
What problem does it solve?
Anyone off-chain can read any contract's storage, but a contract on-chain cannot. If contract A wants a value held by contract B (a token balance, a registry entry), it has to CALL a view function on B. That costs a cross-contract call, ABI encoding and decoding, function dispatch, and often extra SLOADs inside the view function that A never needed.
For lookups that are really just "read one slot of a mapping", most of that gas is overhead. EIP-2330 adds a single opcode that reads the slot directly, which the authors argue can cut the cost of such reads by more than 10x and makes the cost predictable for the caller.
How it works
- New opcode
EXTSLOADat0x5c. It pops two stack items,addressandslot, and pushes the 32-byte value stored atslotin that account's storage (or0if the account does not exist). - It behaves like
SLOAD(0x54) with an extra address argument. It is read-only; there is no external write counterpart. - Gas follows the warm/cold model from EIP-2929:
- account part:
0if the address is already warm, otherwiseCOLD_ACCOUNT_ACCESS_COST; - storage part:
WARM_STORAGE_READ_COSTif the(address, slot)pair is warm, otherwiseCOLD_STORAGE_READ_COST.
- account part:
- The spec notes that after a move to Verkle trees the account part would no longer apply, leaving only the storage-read cost.
The rationale points out that a contract can already opt in to this by exposing a function that SLOADs and returns arbitrary slots. EXTSLOAD makes that universal, and the gas model mirrors "one call plus N slot reads".
Sample code
Reading an ERC-20 balance straight from storage. This assumes the token keeps mapping(address => uint256) balances at slot 0, which you must verify per contract. EXTSLOAD is not a real opcode on mainnet, so this is illustrative pseudocode:
// Illustrative only: EXTSLOAD (0x5c) is not available on mainnet.
function balanceViaExtsload(address token, address owner) view returns (uint256 bal) {
// Solidity mapping layout: slot = keccak256(abi.encode(key, mappingSlot))
bytes32 slot = keccak256(abi.encode(owner, uint256(0)));
assembly {
// bal := extsload(token, slot) // hypothetical opcode
}
}
Today's opt-in equivalent, which some protocols expose on their own contracts:
function extsload(bytes32 slot) external view returns (bytes32 value) {
assembly { value := sload(slot) }
}
Things to know
- Status: Stagnant. The opcode was never scheduled into a network upgrade and is not available on Ethereum mainnet.
- Storage layout is not part of a contract's public interface. Code that reads raw slots breaks if the target changes its layout (for example through a proxy upgrade), so this trades safety for gas.
- The proposal also makes a point about developer misconceptions:
privatevariables in Solidity are not secret. Everything in storage is already readable off-chain. - The security section notes that a callee could read the caller's state during re-entrancy; because the opcode cannot write, the authors consider this no worse than calling existing view functions.