Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Memory-Safe Proxy Code Without Allocation (#67)
This PR modifies the account fallback code to no longer use allocations, as they are not required for memory-safety. [From the docs](https://docs.soliditylang.org/en/v0.8.22/assembly.html#memory-safety): > In particular, a memory-safe assembly block may only access the following memory ranges: > > * [...] > * Temporary memory that is located after the value of the free memory pointer at the beginning of the assembly block, i.e. memory that is “allocated” at the free memory pointer **without updating the free memory pointer**. > > [...] > > On the other hand, **the following code _is_ memory safe**, because memory beyond the location pointed to by the free memory pointer can safely be used as temporary scratch space: > > ```solidity > assembly ("memory-safe") { > let p := mload(0x40) > returndatacopy(p, 0, returndatasize()) > revert(p, returndatasize()) > } > ``` I also [did some investigation](safe-global/safe-smart-account#544 (comment)) and found that when variables are moved into memory, the space gets reserved **before** user code starts, meaning that the free memory pointer already accounts for the reserved space (i.e. setting variables cannot write past the free memory pointer ever). With that in mind, we do not need to update the free memory pointer when we write past it for scratch space. cc @mmv08
- Loading branch information