Closed brockelmore closed 1 year ago
There are some issues related to this already: https://github.com/ethereum/solidity/issues/12335, https://github.com/ethereum/solidity/issues/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.