EIPs/EIPS/eip-1153.md

76 lines
5.5 KiB
Markdown
Raw Normal View History

---
Switch validator to eipv (#2860) * switch to eipv * fix * fix * 1153 remove trailing whitespace * remove file name checks * 615 remo whitespace before comma * 884 remove extra single-quotes * 1337 remove whitespace before comma * 1057 remove extra spaces after comma * 2470 update created date to Y/M/D format * 1078 update required eips to be in ascending order * 2477 update required eips to be in ascending order * 1271 remove extra whitespace * 2767 required eipupdated to be in ascending order * 2525 update created date to Y/M/D format * 2458 remove trailing whitespace * 1884 remove trailing whitespace * 712 authors should be on a single line * 601 remove extra whitespace * 1485 remove unneeded parentheses * 634 remove trailing whitespace * 2657 update discussions-to to correct spelling * 2009 remove trailing whitespace * 998 required eips updated to be in ascending order * 1186 remove trailing whitespace * 1470 remove extra whitespace * 1895 update created date to Y/M/D format * 2747 remove extra whitespace * 1613 remove leading whitespace * 1571 can'have both handle and email in author field * 1191 remove trailing whitespace * 1973 remove trailing whitespace * 196 don't wrap title field * 1679 required eips must be in ascending order * 1620 author can't have both handle and email * 197 don't line wrap title field * 2378 remove extra newline * 1355 author can't have both handle and email * 698 update created date to Y/M/D format * 2193 required eips must be in ascending order * 214 remove extra info after author email * use v0.0.3 of eipv * 1 remove malformed field * bump eipv to v0.0.4 * cache eipv build * 1485 remove extra author info * 2771 removing extra whitespaces
2020-08-10 10:18:25 -06:00
eip: 1153
title: Transient storage opcodes
author: Alexey Akhunov (@AlexeyAkhunov)
discussions-to: https://ethereum-magicians.org/t/eip-transient-storage-opcodes/553
status: Draft
type: Standards Track
category: Core
created: 2018-06-15
---
## Simple Summary
Support for efficient transient storage in EVM. It is like regular storage (`SLOAD`/`SSTORE`), but with the lifetime limited to one Ethereum transaction.
Notable use case is efficient reentrancy lock.
## Abstract
This proposal introduces transient storage, which behaves similar to storage,
but the updates will only persist within one Ethereum transaction. Transient storage is accessible to smart contracts via new opcodes: `TLOAD` and `TSTORE` (“T” stands for Transient).
## Motivation
Running a transaction in Ethereum can generate multiple nested frames of execution, each created by `CALL` (or similar) instructions.
Contracts can be re-entered during the same transaction, in which case there are more than one frame belonging to one contract.
Currently, these frames can communicate in two ways - via inputs/outputs passed via `CALL` instructions, and via storage updates.
If there is an intermediate frame belonging to another contract, communication via inputs/outputs is not secure. Notable example is a reentrancy lock which cannot rely on the intermediate frame to pass through the state of the lock.
Communication via storage (`SSTORE`/`SLOAD`) is costly. Transient storage is a dedicated and gas efficient solution to the problem of inter frame communication.
Language support could be added in relatively easy way. For example, in Solidity, a qualifier “transient” can be introduced (similar to the existing qualifiers “memory” and “storage”). Since addressing scheme of `TSTORE` and `TLOAD` is the same as for `SSTORE` and `SLOAD`, code generation routines that exist for storage variables, can be easily generalised to also support transient storage.
Potential use cases unlocked by this EIP include:
1. Reentrancy lock
2. Passing error codes and messages from the execution frames up the execution stack
3. More generic libraries that use callbacks, for example generalised sorting with functions `Less` and `Swap` defined.
4. Shared memory (borrowed from early draft of similar EIP by @holiman). When implementing contract-proxies using `DELEGATECALL`, all direct arguments are relayed from the caller to the callee via the `CALLDATA`, leaving no room for meta-data between the proxy and the proxee. Also, the proxy must be careful about `storage` access to avoid collision with `target` `storage`-slots. Since `transient storage` would be shared, it would be possible to use `transient storage` to pass information between the `proxy` and the `target`.
## Specification
Two new opcodes are added to EVM, `TLOAD` and `TSTORE`.
They use the same arguments on stack as `SLOAD` (`0x54`) and `SSTORE` (`0x55`).
`TLOAD` pops one 32-byte word from the top of the stack, treats this value as the address, fetches 32-byte word from the transient storage at that address, and pops the value on top of the stack.
`TSTORE` pops two 32-byte words from the top of the stack. The word on the top is the address, and the next is the value. `TSTORE` saves the value at the given address in the transient storage.
Addressing is the same as `SLOAD` and `SSTORE`. i.e. each 32-byte address points to a unique 32-byte word.
Gas cost for both is 8 units of gas, regardless of values stored.
The effects of transient storage are discarded at the end of the transaction.
Transient storage is private to the contract that owns it, in the same way as "regular" storage is. Only owning contract frames may access their transient storage. And when they do, all the frames access the same transient store, in the same way as "regular" storage, but unlike "memory".
When transient storage is used in the context of `DELEGATECALL` or `CALLCODE`, then the owning contract of the transient storage is the contract that issued `DELEGATECALL` or `CALLCODE` instruction (the caller). When transient storage is used in the context of `CALL` or `STATICCALL`, then the owning contract of the transient storage is the contract that is the target of the `CALL` or `STATICCALL` instruction (the callee).
Transient storage does not interact with reverts or invalid transactions, that means if a frame reverts, its effects on the transient storage remain until the end of the transaction.
## Rationale
There is a proposal to alleviate the cost of inter-frame communication by reducing the cost of `SSTORE` when it modifies the same item multiple times within the same transaction (EIP-1087).
Relative cons of the transient storage: new opcodes; new code in the clients; new concept for the yellow paper (more to update); requires separation of concerns (persistence and inter-frame communication) when programming.
Relative pros of the transient storage: cheaper to use; does not change the semantics of the existing operations; very simple gas accounting rules;
## Backwards Compatibility
This EIP requires a hard fork to implement.
Since this EIP does not change semantics of any existing opcodes, it does not pose risk of backwards incompatibility for existing deployed contracts.
## Test Cases
TBD
## Implementation
Most straightforward implementation would be a dictionary (map), similar to what exists for the dirty storage, with the difference that it gets re-initialised at the start of each transaction, and does not get persisted.
## Copyright
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).