-
Notifications
You must be signed in to change notification settings - Fork 6k
Add EIP: Decrease base cost of TLOAD/TSTORE #8158
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 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1c9f267
reduce transient pricing
charles-cooper ff16244
add authors
charles-cooper cbfbbd2
add brockelmore
charles-cooper e55bd03
updates
charles-cooper 7f4559c
update wording
charles-cooper c67a732
add discussions-to
charles-cooper f6d05af
update pricing based on benchmarks
charles-cooper beaebca
add eip number
charles-cooper 2aa8145
Apply suggestions from code review
charles-cooper 43a0e99
update title
charles-cooper 1d912d5
update abstract
charles-cooper c1bab87
move some text from specification to security considerations
charles-cooper 62bceff
add pseudocode
charles-cooper 504f14b
add creation date
charles-cooper 482b65a
fix lint
charles-cooper ac90462
eip walidator requires shorter title
charles-cooper 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,56 @@ | ||
| --- | ||
| title: Decrease TLOAD/TSTORE pricing for common cases | ||
| description: Improve the efficiency of TLOAD/TSTORE by introducing a quadratic(?) pricing model. | ||
| author: @charles-cooper, @prestwich, @brockelmore | ||
| discussions-to: https://ethereum-magicians.org/t/eip-8158-reduce-transient-storage-pricing/18435 | ||
| status: Draft | ||
| type: Standards Track | ||
| category: Core | ||
| created: tbd | ||
| requires: 1153 | ||
| --- | ||
|
|
||
| ## Abstract | ||
|
|
||
| Increase the efficiency of TLOAD/TSTORE for common use cases, while providing a pricing model to prevent DoS vectors. | ||
charles-cooper marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Motivation | ||
|
|
||
| EIP-1153 introduces a new storage region, termed "transient storage", which behaves like storage in the sense that it is word-addressed and persists between call frames, but unlike storage in the sense that it is wiped at the end of each transaction. During development of the 1153 specification, it was decided to match the pricing to be the same as warm storage loads and stores. This was for two reasons: conceptual simplicity of the EIP, and it also addressed concerns about two related DoS vectors: being able to allocate too much transient storage, and the cost of rolling back state in the case of reverts. | ||
|
|
||
| One of the most important use cases that EIP-1153 enables is cheap reentrancy protection. In fact, if transient storage is cheap enough for the first few slots, reentrancy protection can be enabled by default at the language level without too much burden to users, while simultaneously preventing the largest - and most expensive! - class of smart contract vulnerabilities. | ||
|
|
||
| Furthermore, it seems that transient storage is fundamentally overpriced. Its pricing does not interact with refunds, it only requires a new allocation on contract load (as opposed to memory, which requires a fresh allocation on every call), and has no interaction with the physical database. | ||
|
|
||
| This EIP proposes a pricing model which charges additional per allocation, which is cheaper for common cases (fewer than 33 slots are written per contract), while making DoS using transient storage prohibitively expensive. | ||
|
|
||
| ## Specification | ||
| The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. | ||
|
|
||
| The gas cost for TLOAD is proposed to be 5 gas. The gas cost for TSTORE is proposed to be 8 gas + `expansion_cost`, where expansion cost is calculated as 3 gas * `len(transient storage mapping)` if the key is not yet in the transient storage mapping, and otherwise 0 gas. | ||
|
|
||
| The maximum number of transient slots which can be allocated on a single contract given 30m gas is approximately 4,470 (solution to `x(x-1)/2*3 + 8*x = 30_000_000`), which totals 143KB. | ||
|
|
||
| The maximum number of transient slots which can be allocated in a transaction if you use the strategy of calling a new contract (also designed to maximize transient storage allocation) once the cost of TSTORE is more than the cost of calling a cold contract (2600 gas) is roughly 23,068, which totals 722KB. | ||
|
|
||
| ## Rationale | ||
|
|
||
| ### Gas | ||
|
|
||
| In benchmarking, `TLOAD` was found to cost a similar amount of CPU time as `MUL`, while `TSTORE` was found to cost about 1.5x that. The values `G_low` and `G_mid` were therefore chosen for `TLOAD` and `TSTORE`, respectively. | ||
|
|
||
| ## Backwards Compatibility | ||
|
|
||
| No backward compatibility issues found. | ||
|
|
||
| ## Test Cases | ||
|
|
||
| ## Reference Implementation | ||
|
|
||
| ## Security Considerations | ||
|
|
||
| Needs discussion. | ||
|
|
||
| ## Copyright | ||
|
|
||
| Copyright and related rights waived via [CC0](../LICENSE.md). | ||
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.