Notes:
Assumptions:
abstract contract Extsload {
function extsload(bytes32[] memory slots) external returns (bytes32[] values) {
for(uint i; i < slots.length) {
bytes32 slot = slots[i];
bytes32 val;
assembly {
val := sload(val)
}
}
return values;
}
}
contract DeFiProtocol is Extsload {
// ...
}
Now let's consider someone wants to read 6 slots from DeFiProtocol, they can either use EXTSLOAD opcode or the extsload method.
If they use EXTSLOAD opcode to read the 6 slots, the cost would simply be 6 * (G[EXTCODEHASH] + G[SLOAD])
. While if they use the extsload function, the cost would be G[CALL] + 6 * G[SLOAD]
(including a bit of memory expansion and encoding decoding stuff).
Issue with this is, the currently specified pricing in EIP is more, and this experiment shows that the actual cost through other inefficient route turns out to be less.
Before an account / address is touched, it should be considered as cold account. Once it is touched using CALL, STATICCALL, DELEGATECALL, CALLCODE or EXTSLOAD it should be considered as warm address. This set of warm addresses (accessed_addresses) is implemented in EIP-2929.
Also in addition to this concept, it should consider the accessed and non-accessed concept after berlin (doc).