-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
RuntimeError: memory access out of bounds
when compiling a large input file with soljson.js
(but not solc
)
#13966
Comments
Thanks for the report! I can confirm that this is reproducible with node v16.19.0 and Solidity 0.8.18 as well. The discrepancy is definitely not intended. It might be coming from the fact that
This sounds like the issue is in processing long comments. By switching to line comments, you're basically breaking a single huge multi-line comment into lots of small comments that will be processed separately. The file is 1.6 MB so the comment can't possibly be long enough to actually exhaust available memory but maybe e.g. the regex parser we use is not particularly efficient. We do have issue reports related to that already: #12208.
Yeah, this part is not surprising since it's a crash during compilation. Still, good to know.
Interestingly, I managed to crash solc Test.txt --via-ir And then only on a release build. A recent build from In any case, this does look like a bug. I'm going to transfer the issue to the main repo because the crash is clearly inside the binary and not in the JS code. |
RuntimeError: memory access out of bounds
when compiling a large multi-line comment with soljson.js
(but not solc
)
@cameel out of interest, which release build could you crash using the |
I used the Linux release binary for 0.8.18. |
Oh, you mean it's still reproducible without the comment? To be honest, I only quickly triaged it, I did not investigate what exactly is the cause but from your description and the effects I observed the huge comment seemed like a reasonable guess. |
Yes with solcjs it can be reproduced using just Test.txt which contains no comments. I just thought it was surprising that a) commenting out a big chunk made no difference and then b) if I changed the comments from being commented out code e.g.
to
Then the problem no longer happened. |
RuntimeError: memory access out of bounds
when compiling a large multi-line comment with soljson.js
(but not solc
)RuntimeError: memory access out of bounds
when compiling a large input file with soljson.js
(but not solc
)
ok so that's probably not just the comment then. I investigated this now and I think we're just running into the limits of the 32-bit memory space. It seems to be simply because of now much memory solc eats to process such a big contract. Not saying it cannot be improved to use less RAM but that would be just a matter of better optimization and not really a bugfix. I confirmed this by trying to remove as much as possible from {
printf 'function f() {'
for i in {1..200000}; do
printf ' 0;\n'
done
printf '}'
} > input.sol
npx solcjs --bin input.sol Further proof is that simply removing the indent from the above makes the crash go away. But then increasing the loop count to 800k brings it back again. It's just the memory overhead of processing such a big file. It's very possible you could crash So it seems to be more of a performance issue. It's not great that wasm is so limited because we always consider it as the canonical build you could use anywhere. But we might have to just live with it until 64-bit wasm becomes a thing. @ekpyron @axic Do you think we can do anything concrete here or should we close this as "wontfix"? tl;dr is that extremely large |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
@cameel Thank you so much, commenting and removing the comments actually worked!! |
Hi im facing this issue with one of our repos. Has this been addressed? |
Guys, I've written article on how to solve this |
For anyone running into this error, the actual solution is to upgrade to 0.8.28. With #15451 memory use went down significantly, even as much as 80% in some cases. Between 0.8.21 and 0.8.27 memory usage jumped a lot due to some artifacts not being generated on demand, which we noticed only recently (see benchmarks: #15561 (comment)). Now that I think of it, it must have been the underlying cause of this issue too. I mean, the example is quite contrived and if you make it large enough, you'll still reach the bounds of available memory eventually, but it should not have been happening that easily. And if anyone is still having memory problems even on 0.8.28+ (in real-life, non-contrived cases), please report that as a bug. The compiler is designed to cache most artifacts but it does it in a very simplistic way and they accumulate during compilation of large projects. It has never been seen as much of a problem, but some bigger projects I've seen do need 5+ GB of RAM even with the fix from #15451. With some effort the compiler stack could be redesigned to free unused artifacts earlier, but optimizing that won't be high on our priority list unless it's actually affecting users in practice. |
Running
solcjs --bin --optimize Test.sol
produces the following:However, running
solc --bin Test.sol
will successfully compile the program. Furthermore, the produced binary executes successfully using evmone.Test.txt contains the solidity code. What is interesting is that I can comment out functions
f4
andf5
, andsolcjs
will still reject the program. However, if I replace the commented out functions with repeating simple line comments e.g.// // comment
thensolcjs
will successfully compile it. Here is comment.txt.I see that this comment suggests a memory access error is related to exceeding the Solidity maximum contract size, however, clearly there is a discrepancy between the behaviour of
solc
andsolcjs
. I don't know if this discrepancy is intended.The text was updated successfully, but these errors were encountered: