EEVM.Gas.Static (eevm v0.1.0)

Copy Markdown View Source

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)

TierCostOpcodes
Zero0STOP, RETURN, REVERT
Base2ADDRESS, ORIGIN, CALLER, CALLVALUE, CALLDATASIZE, CODESIZE, GASPRICE, COINBASE, TIMESTAMP, NUMBER, PREVRANDAO, GASLIMIT, CHAINID, BASEFEE, POP, PC, MSIZE, PUSH0
Very Low3ADD, 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
Low5MUL, DIV, SDIV, MOD, SMOD, SIGNEXTEND, CLZ
Mid8ADDMOD, MULMOD, JUMP
High10JUMPI

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:

OpcodeFrontierEIP-150 (Tangerine Whistle)EIP-1884 (Istanbul)
BALANCE20400700
EXTCODESIZE, EXTCODECOPY20700700
EXTCODEHASH—400 (EIP-1052)700
SLOAD50200800
CALL, CALLCODE, DELEGATECALL, STATICCALL40700700
SELFDESTRUCT050005000

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

static_cost(op)

@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.

static_cost(opcode, spec_id)

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