EIP-3322 Account gas storage opcodes

No call decision · Fees & gas · EIP status Stagnant · created 2020-03-04

Adds three opcodes (SELFGAS, USEGAS, STOREGAS) that let a contract account store gas and later move it into the refund counter.

Why it is needed

Gas tokens exploit Ethereum's refund mechanism to trade on gas price differences: they create a storage slot to consume gas when gas prices are cheap, then delete that slot to receive a refund when gas prices are expensive. While this kind of trading smooths out uneven per block gas demand and helps stabilize gas prices, it comes at the cost of continually accumulating unnecessary state that persists permanently on chain. This EIP aims to achieve the same price stabilizing effect without the process of creating and deleting storage slots, offering a better way to store gas directly in an account and move it to the refund counter when needed, reducing the storage and computation that the gas market demands.

What changes

Today

After EIP-3322

Who is affected

In depth

Account gas refund counter

This EIP introduces a new unsigned gas refund counter for each contract account. Every account starts at 0, and the original text explains that since most accounts will never use this value, the per account storage overhead will typically be minimal or nonexistent.

SELFGAS (0x49)

A read only opcode that pushes the current contract account's gas refund counter value directly onto the stack. Its gas cost is set the same as SELFBALANCE.

USEGAS (0x4a)

Pops amount from the stack and moves the smaller of amount and the current account's gas refund counter into the execution context's refund counter. Costs a flat 5000 gas.

STOREGAS (0x4b)

Pops amount from the stack and increases the account's gas refund counter by amount. The cost is 5000 + amount gas, so storing more also costs more gas immediately.

Reusing the existing 50% refund cap

Since gas moved via USEGAS ultimately enters the execution context's refund counter, the refund per transaction is still capped at 50% of the gas used, as before. The original text explains that reusing this cap limits the contribution to block gas usage to at most 2x. It states that the opcode gas costs were set based on similar existing opcodes, SELFBALANCE and SSTORE, and that the opcode numbers were also chosen from the same 0x4X range as SELFBALANCE and GASLIMIT.

Backwards compatibility and security

The original states there are no compatibility issues, since the saved gas only flows into the refund counter. On the security side, it likewise explains that this opcode creates no new risk, since the existing 50% refund cap already limits DoS as before.

Current status

This EIP is classified as Stagnant, meaning the document has sat without active discussion or changes for some time. No call records addressing fork inclusion have been found either.

Original EIP · ← EIPs