EIP-3322: Account gas storage opcodes
作者 | William Morriss |
---|---|
讨论-To | https://ethereum-magicians.org/t/eip-3322-efficient-gas-storage/5470 |
状态 | Stagnant |
类型 | Standards Track |
分类 | Core |
创建日期 | 2020-03-04 |
英文版 | https://eips.ethereum.org/EIPS/eip-3322 |
简述
Allows contract accounts to store gas that can be transferred to the refund counter.
摘要
Contracts can persist gas for later transfer to the refund counter. Three opcodes are introduced to read, add to, and use this gas counter.
动机
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.
规范
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 withSELFBALANCE
.USEGAS
(0x4a
): Popsamount
from the stack. The minimum ofamount
and the current account’s gas refund counter is transferred to the execution context’s refund counter. Costs5000
gas.STOREGAS
(0x4b
): Popsamount
from the stack. Costs5000 + amount
gas. Increases the current account’s gas refund counter byamount
.
基本原理
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
.
向后兼容性
Because the gas is added to the refund counter, no compatibility issues are anticipated.
测试用例
| Code | Used Gas | Refund | Original | Final | | —————- | ——– | —— | ——– | —– | | 0x60004900 | 5003 | 0 | 0 | 0 | | 0x60034900 | 5003 | 2 | 2 | 0 | | 0x60034900 | 5003 | 3 | 3 | 0 | | 0x60034900 | 5003 | 3 | 4 | 1 | | 0x60034960034900 | 10006 | 4 | 4 | 0 | | 0x60034960034900 | 10006 | 6 | 6 | 0 | | 0x484900 | 5010 | 100000 | 100000 | 0 | | 0x61ffff4a00 | 70538 | 0 | 0 | 65535 |
Security Considerations
DoS is already limited by the 50% refund limit.
版权声明
Copyright and related rights waived via CC0.
参考文献
Please cite this document as:
William Morriss, "EIP-3322: Account gas storage opcodes [DRAFT]," Ethereum Improvement Proposals, no. 3322, March 2020. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3322.