Static gas costs for each EVM opcode.
Every opcode has a fixed ("static") gas cost that is charged before execution, independent of the operand values. These costs come from the Ethereum Yellow Paper (Appendix G) and subsequent EIPs.
Gas Tiers (Yellow Paper, Appendix G)
| Tier | Cost | Opcodes |
|---|---|---|
| Zero | 0 | STOP, RETURN, REVERT |
| Base | 2 | ADDRESS, ORIGIN, CALLER, CALLVALUE, CALLDATASIZE, CODESIZE, GASPRICE, COINBASE, TIMESTAMP, NUMBER, PREVRANDAO, GASLIMIT, CHAINID, BASEFEE, POP, PC, MSIZE, PUSH0 |
| Very Low | 3 | ADD, SUB, NOT, LT, GT, SLT, SGT, EQ, ISZERO, AND, OR, XOR, BYTE, SHL, SHR, SAR, CALLDATALOAD, MLOAD, MSTORE, MSTORE8, PUSH1–PUSH32, DUP1–DUP16, SWAP1–SWAP16 |
| Low | 5 | MUL, DIV, SDIV, MOD, SMOD, SIGNEXTEND, CLZ |
| Mid | 8 | ADDMOD, MULMOD, JUMP |
| High | 10 | JUMPI |
Some opcodes have a static cost of 0 because their full cost is computed dynamically (e.g., BALANCE, EXTCODESIZE, SLOAD, SSTORE use EIP-2929 access costs instead).
Pre-Berlin schedule
static_cost/1 is the Berlin-onward schedule. Before EIP-2929, the
state-access opcodes carried flat static prices instead, which
static_cost/2 applies by hardfork:
| Opcode | Frontier | EIP-150 (Tangerine Whistle) | EIP-1884 (Istanbul) |
|---|---|---|---|
| BALANCE | 20 | 400 | 700 |
| EXTCODESIZE, EXTCODECOPY | 20 | 700 | 700 |
| EXTCODEHASH | — | 400 (EIP-1052) | 700 |
| SLOAD | 50 | 200 | 800 |
| CALL, CALLCODE, DELEGATECALL, STATICCALL | 40 | 700 | 700 |
| SELFDESTRUCT | 0 | 5000 | 5000 |
References
Summary
Functions
Returns the static gas cost for the given opcode byte under the
Berlin-onward schedule. See static_cost/2 for earlier hardforks.
Returns the static gas cost of opcode under hardfork spec_id.
Functions
@spec static_cost(non_neg_integer()) :: non_neg_integer()
Returns the static gas cost for the given opcode byte under the
Berlin-onward schedule. See static_cost/2 for earlier hardforks.
This cost is charged by the executor before dispatching to the opcode handler. Dynamic costs (memory expansion, storage access, etc.) are charged separately within each opcode's implementation.
@spec static_cost(non_neg_integer(), EEVM.HardforkConfig.spec_id()) :: non_neg_integer()
Returns the static gas cost of opcode under hardfork spec_id.
From Berlin on this is static_cost/1; earlier forks price the
state-access opcodes with the flat schedules in the module docs.
Examples
iex> EEVM.Gas.Static.static_cost(0x54, :frontier)
50
iex> EEVM.Gas.Static.static_cost(0x54, :istanbul)
800
iex> EEVM.Gas.Static.static_cost(0x54, :berlin)
0