46

The EVM instructions are in the yellow paper, or they are summed up in this answer. But their gas costs are not there. Where can I find a list of all instructions with their associated gas costs?

comodoro
  • 1,202
  • 1
  • 12
  • 16

3 Answers3

46

The Yellow Paper is actively maintained and should always be current, and it's not as easy as a table, but the gas costs are there in Appendix G. Fee Schedule and read it with Appendix H.


Historically:

A spreadsheet of opcodes and their gas costs that Ethereum launched with are here.

It has some analysis per How were gas costs chosen for the Ethereum Virtual Machine instructions?

The spreadsheet is titled 1.0 gas costs, so it might not be updated.

edit 2017-12-11: here is the EIP-150 revision of the spreadsheet

Here is a small snippet from it:

ADD .... 3
MUL .... 5
SUB .... 3
DIV .... 5
SDIV ... 5
MOD .... 5
SMOD ... 5
ADDMOD . 8
MULMOD . 8
maurelian
  • 3,211
  • 2
  • 16
  • 34
eth
  • 85,679
  • 53
  • 285
  • 406
  • This data is (has to be) also available in the source code format in node applications. – Mikko Ohtamaa Jan 18 '17 at 02:26
  • Thanks, I missed appendix G of the yellowpaper, I thought only appendix H was relevant – comodoro Jan 18 '17 at 11:48
  • An updated version of the spreadsheet is here: https://docs.google.com/spreadsheets/d/1n6mRqkBz3iWcOlRem_mO09GtSKEKrAsfO7Frgx18pNU/edit#gid=0 – maurelian Dec 11 '17 at 13:46
  • @maurelian Sorry to resurrect this. How are the values for those tagged Formulae calculated? – Vignesh Karthikeyan Jun 14 '18 at 21:45
  • 1
    @Meshugah, The only resources I'm aware of are at the right hand side of that table, or Appendix H of the yellow paper. https://ethereum.github.io/yellowpaper/paper.pdf – maurelian Jun 15 '18 at 21:42
8

If you're looking for such a table for the purpose of golfing down contract gas cost, I'd recommend you bookmark protocol_params.go.

It is good for two reasons:

  1. It is the source of truth. The gas costs specified in that file are what a full node really meters.
  2. It lists the important numbers you really need. For example, the usual gas table doesn't show how storage cost works and they don't tell you much about pre-compiled contracts.

https://github.com/ethereum/go-ethereum/blob/master/params/protocol_params.go

user2754799
  • 121
  • 1
  • 5
4

There are lots of reference websites for EVM opcodes:

My favorite one is evm.codes:

evm.codes screenshot

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143