EIPs Explained

EIP-3322 · Stagnant · Core · 2020-03-04

EIP-3322: Account gas storage opcodes

A stagnant proposal for three opcodes that let a contract bank gas in an account-level counter and later release it into the transaction's refund counter, replacing storage-bloating gas tokens.

What problem does it solve?

In 2020, gas tokens (GST2, CHI and similar) exploited the refund for clearing storage: you filled storage slots or created contracts when gas was cheap, then deleted them when gas was expensive and collected the refund. This shifted gas from quiet blocks to busy ones, which is arguably useful, but it did so by writing useless data into state, bloating every node's database.

EIP-3322 proposed doing the same thing directly: let a contract store "gas" in a counter on its account, and release it later into the refund counter, with no junk storage involved.

How it works

Every contract account gains an unsigned gas refund counter, starting at zero. Three opcodes manage it:

Opcode Byte Stack Gas Effect
SELFGAS 0x49 → counter same as SELFBALANCE Push this account's stored gas
USEGAS 0x4a amount → 5000 Move min(amount, counter) from the account into the transaction's refund counter
STOREGAS 0x4b amount → 5000 + amount Add amount to this account's counter

Because released gas goes through the normal refund counter, it inherits the existing cap on refunds (at the time, 50 % of gas used), which limits how much it could stretch any one block. Gas costs were modelled on SELFBALANCE and SSTORE.

Sample code

Illustrative assembly for "bank now, spend later" (the opcodes were never added to Ethereum, so this will not compile with current tools):

; when gas is cheap: bank 100000 gas (costs 5000 + 100000)
PUSH3 0x0186a0
STOREGAS          ; 0x4b

; later, when gas is expensive: release up to 100000 into the refund counter
PUSH3 0x0186a0
USEGAS            ; 0x4a  (costs 5000)

; read the remaining balance
SELFGAS           ; 0x49

Things to know

  • Status is Stagnant; it was never scheduled for a fork.
  • The motivation largely disappeared with EIP-3529 (London), which removed the SELFDESTRUCT refund and cut the storage-clearing refund and refund cap, making gas tokens unprofitable.
  • The spec's test-case table appears to use different opcode bytes from its own specification (for example 0x49 behaving like USEGAS and 0x4a like STOREGAS), so the exact byte assignment is unclear.
  • Opcode bytes 0x49–0x4b have since been used by other proposals (for example BLOBHASH is 0x49 and BLOBBASEFEE is 0x4a), so these assignments are no longer available.

#evm #opcodes #gas #refunds #core

Details

Authors
William Morriss (@wjmelements)
Status
Stagnant
Type
Standards Track / Core
Created
2020-03-04

Machine-readable: Markdown · JSON