This EIP proposes repricing certain opcodes, to obtain a good balance between gas expenditure and resource consumption.
The growth of the Ethereum state has caused certain opcodes to be more resource-intensive at this point than
they were previously. This EIP proposes to raise the gasCost for those opcodes.
An imbalance between the price of an operation and the resource consumption (CPU time, memory etc) has several drawbacks:
If operations are well-balanced, we can maximise the block gaslimit and have a more stable processing time.
At block N,
SLOAD (0x54) operation changes from 200 to 800 gas,BALANCE (0x31) operation changes from 400 to 700 gas,EXTCODEHASH (0x3F) operation changes from 400 to 700 gas,SELFBALANCE is introduced at 0x47. SELFBALANCE pops 0 arguments off the stack, SELFBALANCE pushes the balance of the current address to the stack,SELFBALANCE is priced as GasFastStep, at 5 gas. Here are two charts, taken from a full sync using Geth. The execution time was measured for every opcode, and aggregated for 10K blocks. These bar charts show the top 25 'heavy' opcodes in the ranges 5M to 6M and 6M to 7M:
Note: It can also be seen that the SLOAD moves towards the top position. The GASPRICE (0x3a) opcode has position one which I believe can be optimized away within the client -- which is not the case with SLOAD/BALANCE.
Here is another chart, showing a full sync with Geth. It represents the blocks 0 to 5.7M, and highlights what the block processing time is spent on.

It can be seen that storage_reads and account_reads are the two most significant factors contributing to the block processing time.
SLOADSLOAD was repriced at EIP-150, from 50 to 200.
The following graph shows a go-ethereum full sync, where each data point represents
10K blocks. During those 10K blocks, the execution time for the opcode was aggregated.

It can be seen that the repricing at EIP-150 caused a steep drop, from around 67 to 23.
Around block 5M, it started reaching pre-EIP-150 levels, and at block 7M
it was averaging on around 150 - more than double pre-eip-150 levels.
Increasing the cost of SLOAD by 4 would bring it back down to around 40.
It is to be expected that it will rise again in the future, and may need future repricing, unless
state clearing efforts are implemented before that happens.
BALANCEBALANCE (a.k.a EXTBALANCE) is an operation which fetches data from the state trie. It was repriced at EIP-150 from 20 to 400.

It is comparable to EXTCODESIZE and EXTCODEHASH, which are priced at 700 already.
It has a built-in high variance, since it is often used for checking the balance of this,
which is an inherently cheap operation, however, it can be used to lookup the balance of arbitrary account which often require trie (disk) access.
In hindsight, it might have been a better choice to have two
opcodes: EXTBALANCE(address) and SELFBALANCE, and have two different prices.
0x3X is already full, hence the suggestion to place SELFBALANCE in the 0x4X range. 5 (GasFastStep) instead of 2 (GasQuickStep), like other similar operations: the EVM execution engine still needs a lookup into the (cached) trie, and balance, unlike gasPrice or timeStamp, is not constant during the execution, so it has a bit more inherent overhead. EXTCODEHASHEXTCODEHASH was introduced in Constantinople, with EIP-1052. It was priced at 400 with the reasoning:
The gas cost is the same as the gas cost for the
BALANCEopcode because the execution of theEXTCODEHASHrequires the same account lookup as inBALANCE.
Ergo, if we increase BALANCE, we should also increase EXTCODEHASH
The changes require a hardfork. The changes have the following consequences:
2300 gas (the minimum gas that is always available in calls). supportsInterface must return a bool and use at most 30,000 gas.586 gas for any input, and 236 gas, but increases linearly with a higher number of supported interfacessupportsInterface implementation will go above 30.000 gas. That would require that the second variant is used, and thirty:ish interfaces are supported. I expect that certain patterns will be less used, for example the use of multiple modifiers which SLOADs the same opcode will be merged into one. It may also lead to less log operations containing SLOADed values that are not strictly necessary.
Testcases that should be implemented:
- Test that selfbalance == balance(address),
- Test that balance(this) costs as before,
- Test that selfbalance does not pop from stack
- Gascost verification of SLOAD, EXTCODEHASH and SELFBALANCE
- Verify that SELFBALANCE is invalid before Istanbul
Some testcases have been implemented as statetests at https://github.com/holiman/IstanbulTests/tree/master/GeneralStateTests
This EIP has not yet been implemented in any client. Both these opcodes have been repriced before, and the client internals for managing reprices are already in place.
SELFBALANCEThis is the implementation for the new opcode in go-ethereum:
func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
stack.push(interpreter.intPool.get().Set(interpreter.evm.StateDB.GetBalance(contract.Address())
return nil, nil
}
SELFBALANCE, if we define it as BALANCE with address instead of popping an address from the stack -- since BALANCE is already well-defined.ether from a CALL will want to issue a LOG. The LOG operation costs 375 plus 375 per topic. If the LOG also wants to do an SLOAD, this change may make some such transfers fail. Copyright and related rights waived via CC0.