GasCosts.md

February 23, 2021 ยท View on GitHub

Current (Istanbul) costs

With Istanbul rules, EIP-2200: https://eips.ethereum.org/EIPS/eip-2200#test-cases, the following gas usages apply for the various scenarions below:

CodeUsed GasRefundOriginal1st2nd3rdEffective gas (after refund)
0x60006000556000600055161200001612
0x6000600055600160005520812000120812
0x6001600055600060005520812192000101612
0x6001600055600260005520812001220812
0x6001600055600160005520812001120812
0x60006000556000600055581215000100-9188
0x60006000556001600055581242001011612
0x60006000556002600055581201025812
0x60026000556000600055581215000120-9188
0x60026000556003600055581201235812
0x60026000556001600055581242001211612
0x60026000556002600055581201225812
0x60016000556000600055581215000110-9188
0x60016000556002600055581201125812
0x60016000556001600055161201111612
0x6001600055600060005560016000554081819200010121618
0x60006000556001600055600060005510818192001010-8382

Berlin costs

With Berlin, and EIP-2929, the gas costs changes. Note, there is a difference between 'hot' and 'cold' slots. The following table is generated based on the slot in question (0) being 'cold'.

CodeUsed GasRefundOriginal1st2nd3rdEffective gas (after refund)
0x60006000556000600055231200002312
0x6000600055600160005522212000122212
0x6001600055600060005522212199000102312
0x6001600055600260005522212001222212
0x6001600055600160005522212001122212
0x60006000556000600055511215000100-9888
0x60006000556001600055511228001012312
0x60006000556002600055511201025112
0x60026000556000600055511215000120-9888
0x60026000556003600055511201235112
0x60026000556001600055511228001212312
0x60026000556002600055511201225112
0x60016000556000600055511215000110-9888
0x60016000556002600055511201125112
0x60016000556001600055231201112312
0x6001600055600060005560016000554221819900010122318
0x6000600055600160005560006000558018178001010-9782

If the slot is already 'warm', this is the corresponding table:

CodeUsed GasRefundOriginal1st2nd3rdEffective gas (after refund)
0x600060005560006000552120000212
0x6000600055600160005520112000120112
0x600160005560006000552011219900010212
0x6001600055600260005520112001220112
0x6001600055600160005520112001120112
0x60006000556000600055301215000100-11988
0x6000600055600160005530122800101212
0x60006000556002600055301201023012
0x60026000556000600055301215000120-11988
0x60026000556003600055301201233012
0x6002600055600160005530122800121212
0x60026000556002600055301201223012
0x60016000556000600055301215000110-11988
0x60016000556002600055301201123012
0x600160005560016000552120111212
0x6001600055600060005560016000554011819900010120218
0x6000600055600160005560006000555918178001010-11882

Without refunds

If refunds were to be removed, this would be the comparative table

CodeOriginal1st2nd3rdIstanbulBerlin (cold)Berlin (hot)Berlin (hot)+norefund
0x6000600055600060005500016122312212212
0x6000600055600160005500120812222122011220112
0x600160005560006000550101612231221220112
0x6001600055600260005501220812222122011220112
0x6001600055600160005501120812222122011220112
0x60006000556000600055100-9188-9888-119883012
0x60006000556001600055101161223122123012
0x600060005560026000551025812511230123012
0x60026000556000600055120-9188-9888-119883012
0x600260005560036000551235812511230123012
0x60026000556001600055121161223122123012
0x600260005560026000551225812511230123012
0x60016000556000600055110-9188-9888-119883012
0x600160005560026000551125812511230123012
0x6001600055600160005511116122312212212
0x600160005560006000556001600055010121618223182021840118
0x6000600055600160005560006000551010-8382-9782-118825918

In partcular, the following cases become more expensive:

  • '0-1-0' goes from 10K to 20K,
  • '0-1-0-1' goes from 21K to 40K,

For these cases, a better scheme under the no-refund rule would be to use non-zero slots, e.g. '1-2-1' and thus wind up with 3K gas.

Note: In reality, there are never a negative gas cost, since the refund is capped at 0.5 * gasUsed. However, these tables show the negative values, since in a more real-world scenarion would likely spend the extra gas on other operations.'