Withdrew PR to flesh it out a bit more. (https: //github .com/ethereum/EIPs/pull/1666)
Transient storage repo, related: https://github.com/androlo/tstorage
Much of this comes from experimenting with transient storage (EIP-1153: Transient storage opcodes).
There are three types of memory involved here:
- EVM-bound memory - protected memory used by the EVM to store things like call-, and returndata. Can be read from contract code.
- Account-bound memory - Lasts throughout an entire transaction and can be written to and read from by contract code. Needs special consideration when a revert happens.
- VM-bound memory. Can only be accessed from a specific VM. Can be written to and read from by contract code.
Suggestions
-
Add a address->Memory map that lasts throughout an entire transaction.
-
Keep
MLOAD/MSTORE/MSTORE8as is. -
Add a map,
Map<Address, Memory>to the EVM which binds memories to contract addresses. -
Add instructions
TSTORE,TLOAD,TCOPYto work with account-bound memory. -
Change
CALLDATALOAD/CALLDATASIZE/CALLDATACOPYto read fromaccountMemory[0]. -
Change
RETURNDATASIZE/RETURNDATACOPYto read fromaccountMemory[0]. -
Change call related instructions (
CALL,DELEGATECALL, etc.) to write toaccountMemory[0]. -
Change
RETURN/REVERTinstructions to write toaccountMemory[0].
Note: Address 0x00 of accountMemory[0] can be used for data size, and 0x20 and beyond for the data itself. Lifetime of calldata and returndata is now related, and works like returndata does now.
New instructions
TLOAD cAddr sAddr
TLOAD reads the data stored at address sAddr in the transient storage of the account with address cAddr .
Example: if the account with address 0x00...01 wants to read from its own transient storage at address 0x20 , in LLL that would be (TSTORE 0x00...01 0x20)
TSTORE sAddr val
Stores the 32 byte value val at address sAddr in the account’s own transient storage.
TCOPY cAddr sAddr mAddr len
Copies len bytes of data from the address sAddr in the transient storage of account cAddr to memory address mAddr .
Notes
The big change is to add a new memory with a different scope, and making other instructions use memory rather then their own special storage locations, instructions, and gas rules. Harmonization + simplification. Also enables reentrancy locks + other things that has to last over an entire transaction.