-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 allocation in for-loops are never treated as temporary #13885
Comments
There are some issues related to this already: #12335, #5107 What's interesting about how this interacts with for loops or while loops is that a programmer might analyze a function and conclude it should run in linear or sublinear time/gas, but instead get quadratic gas due to memory expansion. This should be considered a serious issue. |
Currently the plan is to tackle these issues in Q3: #13722. |
Yeah, this is a known issue and we'll get to it this year - closing this as duplicate of the linked issues. |
Description
An effective memory leak in for-loops or while loops leads to blowup in evm memory usage. The compiler does not recognize basically any memory storage as temporary inside a for-loop so there is a boatload of unnecessary memory expansions.
Environment
Steps to Reproduce
alternative, abi.encode version:
here is a foundry.toml to use:
while the above wouldn't be possible in normal deployed applications, it highlights that there are unneeded free memory pointer updates and treating memory variables as permanent inside a for-loop when unnecessary. The above in latest foundry errors out with
OutOfGas
but only because of our imposed memory limit of 33.5mb per call frame. This means that for each iteration we are expanding memory. It affects non-function call loops (i.e.abi.encode
and its variants) as well.The text was updated successfully, but these errors were encountered: