HomeEIPs
EIPsEIP-3322
EIP-3322

Account gas storage opcodes

StagnantStandards Track: Core
Created: 2020-03-04
William Morriss (@wjmelements)
DiscussionsOriginal linkEdit
1 min read

EIP-3322, titled "Account gas storage opcodes," proposes a mechanism that allows contract accounts to store gas that can be transferred to the refund counter. This is aimed at providing a more efficient way for contracts to manage gas, reducing the need for unnecessary state growth. The EIP introduces three new opcodes: SELFGAS, USEGAS, and STOREGAS. SELFGAS pushes the current account's gas refund counter onto the stack. USEGAS pops an amount from the stack, transferring the minimum of this amount and the current account's gas refund counter to the execution context's refund counter. STOREGAS pops an amount from the stack, increases the current account's gas refund counter by this amount, and costs 5000 plus the popped amount in gas. The rationale behind this EIP is to provide a superior gas storage mechanism that requires less storage and computation. By reusing the execution context's refund counter, the EIP also leverages its 50% DoS protection, limiting its block elasticity contribution to 2x. The EIP also discusses the gas costs, the opcode numbers chosen, and provides test cases. It anticipates no compatibility issues as the gas is added to the refund counter. The EIP also considers DoS, which is already limited by the 50% refund limit.

Video
Anyone may contribute to propose contents.
Go propose
Original

Simple Summary

Allows contract accounts to store gas that can be transferred to the refund counter.

Abstract

Contracts can persist gas for later transfer to the refund counter. Three opcodes are introduced to read, add to, and use this gas counter.

Motivation

The refund mechanism is currently being used by gas tokens to arbitrage gas price. This brings gas supply elasticity and price stability by moving gas from blocks with less demand to blocks with more demand. Unfortunately this rewards unnecessary state growth. By introducing a superior gas storage mechanism, the gas market will require less storage and computation.

Specification

Contract accounts gain an unsigned gas refund counter, initially zero.

Three new opcodes are introduced to manage this state.

  • SELFGAS (0x49): Pushes the current account's gas refund counter onto the stack. Shares gas pricing with SELFBALANCE.
  • USEGAS (0x4a): Pops amount from the stack. The minimum of amount and the current account's gas refund counter is transferred to the execution context's refund counter. Costs 5000 gas.
  • STOREGAS (0x4b): Pops amount from the stack. Costs 5000 + amount gas. Increases the current account's gas refund counter by amount.

Rationale

By reusing the execution context's refund counter we can reuse its 50% DoS protection, which limits its block elasticity contribution to 2x.

The gas costs are based on similar opcodes SELFBALANCE and SSTORE.

Most accounts will store no gas, so the per-account storage overhead should be minimal or even zero in the normal case.

The opcode numbers chosen are in the same 0x4X range as SELFBALANCE and GASLIMIT.

Backwards Compatibility

Because the gas is added to the refund counter, no compatibility issues are anticipated.

Test Cases

CodeUsed GasRefundOriginalFinal
0x600049005003000
0x600349005003220
0x600349005003330
0x600349005003341
0x6003496003490010006440
0x6003496003490010006660
0x48490050101000001000000
0x61ffff4a00705380065535

Security Considerations

DoS is already limited by the 50% refund limit.

Copyright and related rights waived via CC0.

Further reading
Anyone may contribute to propose contents.
Go propose
Adopted by projects
Anyone may contribute to propose contents.
Go propose

Not miss a beat of EIPs' update?

Subscribe EIPs Fun to receive the latest updates of EIPs Good for Buidlers to follow up.

View all
Serve Ethereum Builders, Scale the Community.
Resources
GitHub
Supported by