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
- Gas tokens trade on gas price by creating and deleting storage slots to receive refunds
- This process causes unnecessary state to accumulate permanently on chain
- Accounts have no way to store gas directly
After EIP-3322
- Each contract account gets a gas refund counter, allowing it to store gas directly
- Gas is stored via STOREGAS when cheap, then moved to the refund counter and spent via USEGAS when expensive
- No process of creating and deleting storage slots is needed, reducing state growth
Who is affected
- Smart contract developers: A new gas storage pattern using an account gas counter instead of a storage based gas token can be designed
- Gas token users: They gain access to an alternative token that achieves the same gas price trading effect without state growth
- Client and EVM implementation teams: Three new opcodes (SELFGAS, USEGAS, STOREGAS) and a per account gas refund counter state must be implemented in the EVM
- Validators and miners: Even with additional refund paths, the existing 50% refund cap still applies, limiting the risk of sudden swings in block gas usage
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.