Pick a depth. Each prompt opens in your AI pre-loaded with the lesson. Click a row to preview the prompt.
Each data location has wildly different gas costs — calldata is cheap to read, memory is volatile per-call, and storage is the only place that persists between calls. Picking the wrong location bloats gas by 10–100× and is one of the most common sources of avoidable cost in production contracts.
Same function, three locations — radically different gas profiles.
forge test --gas-report against the Costs contract and compare gas for readCalldata vs readMemory.bytes32[10] calldata x to bytes32[10] memory x in readCalldata and note the gas delta — that's the copy cost.// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Costs {
bytes32[10] internal stored;
// Cheap: ~22k gas
function readCalldata(bytes32[10] calldata x) external pure returns (bytes32) {
return x[5];
}
// Medium: ~24k gas (memory copy)
function readMemory(bytes32[10] memory x) external pure returns (bytes32) {
return x[5];
}
// Expensive on first read (~24k cold SLOAD), cheap on re-read (~100 warm)
function readStorage() external view returns (bytes32) {
return stored[5];
}
}