|
| 1 | +--- |
| 2 | +fip: "0097" |
| 3 | +title: Add Support for EIP-1153 (Transient Storage) in the FEVM |
| 4 | +author: Michael Seiler (@snissn), Steven Allen (@stebalien) |
| 5 | +discussions-to: https://github.com/filecoin-project/FIPs/discussions/855 |
| 6 | +status: Draft |
| 7 | +type: Technical |
| 8 | +category: Core |
| 9 | +created: 2024-11-19 |
| 10 | +--- |
| 11 | + |
| 12 | +# FIP-0097: Add Support for EIP-1153 (Transient Storage) in the FEVM |
| 13 | + |
| 14 | +## Simple Summary |
| 15 | +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. |
| 16 | + |
| 17 | +## Abstract |
| 18 | +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. |
| 19 | + |
| 20 | +## Change Motivation |
| 21 | +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. |
| 22 | + |
| 23 | +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. |
| 24 | + |
| 25 | +## Specification |
| 26 | + |
| 27 | +### Opcode Descriptions |
| 28 | + |
| 29 | +#### `TLOAD` |
| 30 | +- **Opcode Hex:** `0x5C` |
| 31 | +- **Stack Input:** |
| 32 | + - `key`: Location of the transient storage value to load |
| 33 | +- **Stack Output:** |
| 34 | + - `value`: Stored value or zero if no value exists |
| 35 | +- **Description:** Retrieves the value associated with `key` in the transient storage for the current transaction. |
| 36 | + |
| 37 | +#### `TSTORE` |
| 38 | +- **Opcode Hex:** `0x5D` |
| 39 | +- **Stack Input:** |
| 40 | + - `key`: Location to store the value |
| 41 | + - `value`: Value to store |
| 42 | +- **Output:** None |
| 43 | +- **Description:** Stores `value` at the specified `key` in the transient storage for the current transaction. |
| 44 | + |
| 45 | +### Lifecycle Management |
| 46 | +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. |
| 47 | + |
| 48 | +### Implementation Details |
| 49 | +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. |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Design Rationale |
| 54 | + |
| 55 | +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. |
| 56 | + |
| 57 | +Alternative designs, such as purely in-memory storage, were considered but deemed impractical due to technical implementation difficulties. |
| 58 | + |
| 59 | +## Backwards Compatibility |
| 60 | +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. |
| 61 | + |
| 62 | +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. |
| 63 | + |
| 64 | +## Test Cases |
| 65 | + |
| 66 | +### Essential Tests |
| 67 | +1. **Basic Functionality:** |
| 68 | + - Verify `TLOAD` retrieves the correct value. |
| 69 | + - Verify `TSTORE` writes data to the transient storage correctly. |
| 70 | + - Verify `TLOAD` from an unitialized location returns the zero value. |
| 71 | + |
| 72 | +2. **Lifecycle Validation:** |
| 73 | + - Verify that transient storage is automatically cleared and becomes inaccessible after the transaction ends. |
| 74 | + - 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. |
| 75 | + - Verify that nested contracts have independent transient storage spaces can read and write independently. |
| 76 | + - Verify that memory remains accessible and stable after contract reentry. |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## Security Considerations |
| 81 | +Transient storage introduces minimal additional risk compared to existing state storage. Lifecycle validation ensures storage is inaccessible outside the originating transaction. Security measures include: |
| 82 | +- Preventing out-of-bounds memory access. |
| 83 | +- Ensuring transient storage clears properly after a transaction ends. |
| 84 | +- Ensuring nested contracts do not have access to each other's memory spaces. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Incentive Considerations |
| 89 | +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. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Product Considerations |
| 94 | +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. |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## Implementation |
| 99 | +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. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## Copyright |
| 104 | +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
0 commit comments