-
Notifications
You must be signed in to change notification settings - Fork 178
Add Support for EIP-1153 (Transient Storage) in the FEVM (FIP-0097) #1084
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
rvagg
merged 19 commits into
filecoin-project:master
from
snissn:transient-storage-draft
Dec 11, 2024
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ddee2c7
Add FIP draft: Support for EIP-1153 Transient Storage in FEVM
snissn 264c81b
Readme for Add Support for EIP-1153 (Transient Storage) in the FEVM
snissn 606c1c1
add discussions link relevant to transient storage fip
snissn 6a35a62
Update FIPS/fip-draft_transient_storage.md
snissn e0f94d2
clarify scope of nested contract calls
snissn 4dfc6b3
Merge branch 'transient-storage-draft' of github.com:snissn/FIPs into…
snissn c7d03e3
add reference to ethereum cancun upgrade adopting EIP1153
snissn 12556d9
ensure reentrancy tests are valid
snissn f576eab
requirement for independent storage spaces
snissn caa886a
Update FIPS/fip-draft_transient_storage.md
snissn 66bab77
update fip number
snissn 772237a
Merge branch 'transient-storage-draft' of github.com:snissn/FIPs into…
snissn 13f6f98
merge
snissn 206557b
assign 0097 fip number
snissn 79d0086
fix spelling issue / remove archaic usage
snissn 06ced1d
fix Dencun typo
snissn b69533d
delete word ephemeral which creates confusion
snissn 58d7f88
Update FIPS/fip-0097.md
snissn ddf9501
clarify incentive considerations
snissn 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,104 @@ | ||
| --- | ||
| fip: "0097" | ||
| title: Add Support for EIP-1153 (Transient Storage) in the FEVM | ||
| author: Michael Seiler (@snissn), Steven Allen (@stebalien) | ||
| discussions-to: https://github.com/filecoin-project/FIPs/discussions/855 | ||
| status: Draft | ||
| type: Technical | ||
| category: Core | ||
| created: 2024-11-19 | ||
| --- | ||
|
|
||
| # FIP-0097: Add Support for EIP-1153 (Transient Storage) in the FEVM | ||
|
|
||
| ## Simple Summary | ||
| This proposal introduces support for **[EIP-1153: Transient Storage](https://eips.ethereum.org/EIPS/eip-1153)** in the Filecoin Ethereum Virtual Machine (FEVM). Transient storage provides data storage during transaction execution, scoped strictly to the transaction and the contract utilizing it. To maintain compatibility with Ethereum contracts utilizing this feature, the FEVM will implement transient storage with lifecycle validation and isolation. | ||
|
|
||
| ## Abstract | ||
| EIP-1153 defines transient storage as temporary data accessible only during the originating transaction, cleared automatically at the end of the transaction. This FIP adapts transient storage to the FEVM using `TLOAD` and `TSTORE` opcodes, ensuring compatibility with Ethereum contracts and libraries that rely on this feature. Transient storage is scoped to the specific contract and transaction, ensuring that each contract’s transient storage is isolated. Nested contract calls cannot access the transient storage of other contracts, but reentrant calls to the same contract within a transaction will access the same transient storage space. Lifecycle validation mechanisms enforce this behavior, achieving functional equivalence with Ethereum’s implementation while maintaining seamless integration with Filecoin’s architecture. | ||
|
|
||
| ## Change Motivation | ||
| Transient storage offers developers temporary, transaction-scoped storage for managing intermediate states. One key benefit of this feature is its ability to improve the implementation of reentrancy locks, enhancing security by mitigating risks associated with multiple calls to a function within sub-transactions. This feature was introduced on Ethereum mainnet in March 2024 as part of the Cancun (Dencun) upgrade, making adopting this FIP important to align the FEVM with Ethereum’s evolving tooling and Solidity’s modern features. By implementing transient storage, the FEVM ensures a seamless developer experience while supporting advanced contract use cases and secure computing. | ||
|
|
||
| While the FEVM implementation utilizes permanent storage for practical reasons, its lifecycle validation ensures it functionally replicates Ethereum’s transient storage. This enables compatibility with contracts and libraries that rely on `TLOAD` and `TSTORE` while supporting transaction-scoped data handling. | ||
|
|
||
| ## Specification | ||
|
|
||
| ### Opcode Descriptions | ||
|
|
||
| #### `TLOAD` | ||
| - **Opcode Hex:** `0x5C` | ||
| - **Stack Input:** | ||
| - `key`: Location of the transient storage value to load | ||
| - **Stack Output:** | ||
| - `value`: Stored value or zero if no value exists | ||
| - **Description:** Retrieves the value associated with `key` in the transient storage for the current transaction. | ||
|
|
||
| #### `TSTORE` | ||
| - **Opcode Hex:** `0x5D` | ||
| - **Stack Input:** | ||
| - `key`: Location to store the value | ||
| - `value`: Value to store | ||
| - **Output:** None | ||
| - **Description:** Stores `value` at the specified `key` in the transient storage for the current transaction. | ||
|
|
||
| ### Lifecycle Management | ||
| Transient storage is valid only within the context of a single transaction. A lifecycle mechanism tracks transaction metadata (`origin` and `nonce`) to enforce lifecycle validation. | ||
|
|
||
| ### Implementation Details | ||
| The FEVM implements transient storage using a lifecycle validation mechanism to ensure data remains accessible only during the originating transaction. This validation enforces the same behavior as Ethereum’s transient storage. Internally, transient storage relies on permanent storage to manage lifecycle data and state while ensuring functional adherence to Ethereum’s behavior. | ||
|
|
||
| --- | ||
|
|
||
| ## Design Rationale | ||
|
|
||
| The design adheres to the intent of EIP-1153 while adapting to Filecoin's architecture. The use of lifecycle validation ensures transient storage behaves as expected within the scope of a single transaction. This approach balances compatibility with Ethereum contracts and simplifies implementation within the existing FEVM architecture. | ||
|
|
||
| Alternative designs, such as purely in-memory storage, were considered but deemed impractical due to technical implementation difficulties. | ||
|
|
||
| ## Backwards Compatibility | ||
| The addition of transient storage is fully backward-compatible. Existing contracts remain unaffected unless they utilize `TLOAD` and `TSTORE`. Contracts compiled with older Solidity versions will continue to execute without changes. | ||
|
|
||
| At the time of writing, support for `TLOAD` and `TSTORE` in current versions of Solidity is only available using inline-assembly. Thus, it is an explicitly opt-in feature, rather than a feature that contract authors may unknowngly be enabling when bumping compiler version and EVM target. | ||
|
|
||
| ## Test Cases | ||
|
|
||
| ### Essential Tests | ||
| 1. **Basic Functionality:** | ||
| - Verify `TLOAD` retrieves the correct value. | ||
| - Verify `TSTORE` writes data to the transient storage correctly. | ||
| - Verify `TLOAD` from an unitialized location returns the zero value. | ||
|
|
||
| 2. **Lifecycle Validation:** | ||
| - Verify that transient storage is automatically cleared and becomes inaccessible after the transaction ends. | ||
| - Verify that transient storage is properly cleared at the end of each transaction and any out-of-lifecycle data does not interfere with subsequent transaction operations. | ||
| - Verify that nested contracts have independent transient storage spaces can read and write independently. | ||
| - Verify that memory remains accessible and stable after contract reentry. | ||
|
|
||
| --- | ||
|
|
||
| ## Security Considerations | ||
| Transient storage introduces minimal additional risk compared to existing state storage. Lifecycle validation ensures storage is inaccessible outside the originating transaction. Security measures include: | ||
| - Preventing out-of-bounds memory access. | ||
| - Ensuring transient storage clears properly after a transaction ends. | ||
| - Ensuring nested contracts do not have access to each other's memory spaces. | ||
|
|
||
| --- | ||
|
|
||
| ## Incentive Considerations | ||
| By adding support for transient storage, this FIP improves the FEVM's compatibility with Ethereum and provides developers with useful functionality for transaction-scoped data handling. This feature enables capabilities outlined in EIP-1153, such as reentrancy locks, temporary approvals, on-chain address computation, and enhanced proxy call metadata handling. These improvements align with Filecoin's goal of enabling scalable and reliable decentralized applications. However, transient storage does not introduce or impact economic incentives within the network. | ||
|
|
||
| --- | ||
|
|
||
| ## Product Considerations | ||
| Adding transient storage ensures compatibility with modern Ethereum tooling, attracting developers to Filecoin’s ecosystem. This feature supports the development of advanced smart contracts and storage-related services. This addition further solidifies Filecoin’s position as a robust EVM-compatible chain, enhancing its attractiveness to Ethereum developers and expanding its ecosystem of decentralized applications. | ||
|
|
||
| --- | ||
|
|
||
| ## Implementation | ||
| The reference implementation, including `TLOAD` and `TSTORE`, is available in the following pull request: [filecoin-project/builtin-actors#1588](https://github.com/filecoin-project/builtin-actors/pull/1588). The implementation includes lifecycle validation and persistent backing for ease of use. | ||
|
|
||
| --- | ||
|
|
||
| ## Copyright | ||
| Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). | ||
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
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.