-
Notifications
You must be signed in to change notification settings - Fork 5.9k
EIP 3322: Efficient Gas Storage #3322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
91937c8
wip
wjmelements c2b00d6
eip number
wjmelements a467299
opcode numbers
wjmelements 6c01f9e
fix Category line
wjmelements f35ae34
set discussions-to
wjmelements 77a0f78
urls don't work in table
wjmelements bc67f49
fill out abstract
wjmelements 34f5d80
add test cases
wjmelements ce03eee
try to fix table
wjmelements db43572
Update EIPS/eip-3322.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| --- | ||
| eip: 3322 | ||
| title: Account gas storage opcodes | ||
| author: William Morriss (@wjmelements) | ||
| discussions-to: https://ethereum-magicians.org/t/eip-3322-efficient-gas-storage/5470 | ||
| status: Draft | ||
| type: Standards Track | ||
| category: Core | ||
| created: 2020-03-04 | ||
| --- | ||
|
|
||
| ## Simple Summary | ||
| Allows contract accounts to store gas that can be transfered 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` (`0x48`): Pushes the current account's gas refund counter onto the stack. | ||
| Shares gas pricing with `SELFBALANCE`. | ||
| * `USEGAS` (`0x49`): 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` (`0x4a`): 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 | ||
| | 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 | ||
| Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.