-
Notifications
You must be signed in to change notification settings - Fork 13
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
Memory-Safe Proxy Code Without Allocation #67
Conversation
I'm struggling to understand how it works. It says that the memory beyond the location can be safely used, but how? If we put some data to the memory location P, now the safe space is P + data size (in my understanding), but it didn't get updated. Or does the |
Is that related to the |
Exactly! Typically, the Solidity compiler sets the free memory pointer to
This translates to the following opcodes:
So, basically the free memory pointer is initialized to something large enough so that the required space for the memory variables is already allocated. |
Understood now! Thanks so much for the detailed explanation |
@mmv08 - do you think we should merge as is or is further clarification needed? |
Ah, sorry, I forgot to approve. It can be merged for sure |
This PR modifies the account fallback code to no longer use allocations, as they are not required for memory-safety. From the docs:
I also did some investigation 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