Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article examines EIP-150, which increases the gas costs of certain opcodes to make denial-of-service attacks more difficult.
This article translates, summarizes, and supplements the material linked below.
I have also covered other EIPs.
Parameters
| FORK_BLKNUM | CHAIN_ID | CHAIN_NAME |
|---|---|---|
2,463,000 |
1 |
Main net |
Specification
The following changes to Ethereum transaction execution apply starting at the specified fork block (FORK_BLKNUM).
- Increase the gas cost of
EXTCODESIZE(retrieving contract code size) from20to700. - Increase the base gas cost of
EXTCODECOPY(copying contract code) from20to700. - Increase the gas cost of
BALANCE(retrieving account balance) from20to400. - Increase the gas cost of
SLOAD(reading storage) from50to200. - Increase the gas cost of
CALL,DELEGATECALL, andCALLCODE(contract calls) from40to700.
These increases better reflect the load imposed by EXTCODESIZE, EXTCODECOPY, BALANCE, SLOAD, and CALL-family operations. The goal is to prevent excessive network load and improve security.
- Increase the gas cost of
SELFDESTRUCTfrom0to5000.- An additional
25000gas is charged when the operation creates a beneficiary account under the applicable rules.
- An additional
Charging gas for SELFDESTRUCT helps account for its resource consumption and protect network integrity.
- Increase the recommended block gas limit to 5.5 million.
Increasing the block gas limit to 5.5 million aims to maintain network transaction-processing capacity despite the increased opcode costs.
- Define and use it to change how calls are handled when their requested gas exceeds the maximum available amount.
- A request exceeding the maximum permitted amount is capped according to the 63/64 rule.
CREATEforwards all but one sixty-fourth of the applicable parent gas to the child execution.
The 63/64 rule provides a mechanism for limiting the gas forwarded to a child execution, leaving gas available in the parent context.
The following code illustrates part of the gas accounting used in Ethereum smart contract execution.
extra_gas = (not ext.account_exists(to)) * opcodes.GCALLNEWACCOUNT + \
(value > 0) * opcodes.GCALLVALUETRANSFER
if compustate.gas < gas + extra_gas:
return vm_exception('OUT OF GAS', needed=gas+extra_gas)
submsg_gas = gas + opcodes.GSTIPEND * (value > 0)extra_gas- Calculates additional gas costs using two conditions.
(not ext.account_exists(to)) * opcodes.GCALLNEWACCOUNT- Calculates the additional gas required to create an account if the specified destination (
to) does not exist.
- Calculates the additional gas required to create an account if the specified destination (
(value > 0) * opcodes.GCALLVALUETRANSFER- Calculates the additional cost associated with transferring nonzero value, such as Ether.
if compustate.gas < gas + extra_gas- Checks whether the gas available in the current computation state (
compustate) is less than the requested gas plus additional gas. - If insufficient gas is available, execution raises an OUT OF GAS exception.
- Checks whether the gas available in the current computation state (
submsg_gas = gas + opcodes.GSTIPEND * (value > 0)- Calculates the gas for a child message, such as a call to another contract.
- When the call transfers nonzero value, the fixed gas stipend (
opcodes.GSTIPEND) is added.
The following code shows the updated approach to calculating and managing gas during smart contract execution.
def max_call_gas(gas):
return gas - (gas // 64)
extra_gas = (not ext.account_exists(to)) * opcodes.GCALLNEWACCOUNT + \
(value > 0) * opcodes.GCALLVALUETRANSFER
if compustate.gas < extra_gas:
return vm_exception('OUT OF GAS', needed=extra_gas)
if compustate.gas < gas + extra_gas:
gas = min(gas, max_call_gas(compustate.gas - extra_gas))
submsg_gas = gas + opcodes.GSTIPEND * (value > 0)max_call_gas(gas)- Returns the supplied gas amount minus one sixty-fourth of that amount, rounded down.
- Calculates the maximum gas that can be forwarded to a call.
- Calculation of
extra_gas(not ext.account_exists(to)) * opcodes.GCALLNEWACCOUNT- Calculates the additional cost of creating the destination account when necessary.
(value > 0) * opcodes.GCALLVALUETRANSFER- Calculates the additional cost associated with a nonzero value transfer.
if compustate.gas < extra_gas- Raises an OUT OF GAS exception if available gas is insufficient to cover the additional costs.
if compustate.gas < gas + extra_gas- Adjusts the requested gas using
max_call_gasif the available gas cannot cover the requested amount plus the additional costs.
- Adjusts the requested gas using
submsg_gas = gas + opcodes.GSTIPEND * (value > 0)- Calculates gas for a child message.
- Adds the stipend when nonzero value is transferred.
These changes account for resource consumption and handle insufficient gas during smart contract execution, improving network security and efficiency.
Additional Notes
This EIP focuses on revising Ethereum gas costs. Denial-of-service attacks revealed that opcodes reading the state tree were underpriced relative to other operations. They imposed substantial resource demands on nodes and could be used to degrade network performance.
Disk reads were a particular concern, including their potential implications for future sharding designs. Sharding aims to improve scalability through partitioning and parallel processing, but transactions requiring large amounts of data can complicate this process.
The proposal increases the costs of opcodes associated with state reads. Its gas calculations build on earlier cost tables and aim to limit the data read during block processing to 8 MB. An additional flat penalty of 300 gas accounts for loading contract code.
EIP-90 and EIP-114 discuss gas-based restrictions on contract calls to reduce the risk of call-stack-depth attacks. These restrictions make call depth increasingly constrained by available gas, reducing the need for developers to account for such attacks.
Finally, the increase in the recommended block gas limit aims to preserve transaction-processing capacity after the changes.
References
Citation
Vitalik Buterin (@vbuterin), "EIP-150: Gas cost changes for IO-heavy operations," Ethereum Improvement Proposals, no. 150, September 2016. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-150.
Conclusion
EIP-150 raises the costs of resource-intensive opcodes and changes gas forwarding rules to better protect Ethereum against denial-of-service attacks.
If you have questions, feel free to contact me on Twitter.
I also publish articles on the following platforms.


