-
Notifications
You must be signed in to change notification settings - Fork 269
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
Why force turning off solc optimizer in 0.7.0 beta? #417
Comments
Somehow if we adding 'require' inside 'buildParams' in BondSize and use that in our Routers during their constructor, the compile would fail with the exception of "Assembly exception for bytecode". However, this would be fine if the optimizer is turned on. After a few tries, by making it being called in a non-constructor solves the compile issue. Thus, this commit changes the constructor for Routers to become a 'init' function instead. This was found because solidity coverage would force turning off the optimizer, see: sc-forks/solidity-coverage#417
Somehow if we adding 'require' inside 'buildParams' in BondSize and use that in our Routers during their constructor, the compile would fail with the exception of "Assembly exception for bytecode". However, this would be fine if the optimizer is turned on. After a few tries, by making it being called in a non-constructor solves the compile issue. Thus, this commit changes the constructor for Routers to become a 'init' function instead. This was found because solidity coverage would force turning off the optimizer, see: sc-forks/solidity-coverage#417
@boolafish Yes, the optimizer is turned off because the tool instruments Solidity by injecting small no-op statements which optimization might remove. Can you link to the code which only compiles w/ optimization on? |
Yeah, the above link is the fix on my side. branch: fail_with_optimizer_off |
@boolafish Ah that's really interesting thank you. I think the coverage tool should probably try to be clearer about what the compilation settings are in the docs and terminal output. There are probably more cases like this.... |
Somehow if we adding 'require' inside 'buildParams' in BondSize and use that in our Routers during their constructor, the compile would fail with the exception of "Assembly exception for bytecode". However, this would be fine if the optimizer is turned on. After a few tries, by making it being called in a non-constructor solves the compile issue. Thus, this commit changes the constructor for Routers to become a 'init' function instead. This was found because solidity coverage would force turning off the optimizer, see: sc-forks/solidity-coverage#417
Somehow if we adding 'require' inside 'buildParams' in BondSize and use that in our Routers during their constructor, the compile would fail with the exception of "Assembly exception for bytecode". However, this would be fine if the optimizer is turned on. After a few tries, by making it being called in a non-constructor solves the compile issue. Thus, this commit changes the constructor for Routers to become a 'init' function instead. This was found because solidity coverage would force turning off the optimizer, see: sc-forks/solidity-coverage#417
fwiw, I also had this issue and was lucky to search through existing issues on here for an answer. It's a hard one to communicate to the user, but yeah I think just being clearer about what the compilation settings are is a step in the right direction. Not sure why my method execution fails when optimisation is disabled though :) |
@alsoc77 Out of curiosity - what is your compilation error message? Is the code where youre seeing this public? |
For context @boolafish's error is
which looks like a internal solidity crash... I wonder if these incidents should be collected and reported to solc. |
My scenario is a bit tricky to disect. I did end up figuring out a solution though. |
CompileError: CompilerError: Stack too deep when compiling inline assembly: Variable headStart is 1 slot(s) too deep inside the stack. With optimizer it works. It's a bunch of smart contracts with AbiEncoderv2 using structs as params and return values Any idea how to make coverage work? Solc 7.1 |
No, sorry. Thanks for reporting this. I think these cases should be raised at ethereum/solidity if it's possible to generate minimized reproductions for them. It seems strange that optimization would affect whether or not compilation succeeds. |
Will definetly do it. Any contract over 24k, with Abiv2encoder raises this problem with optimizer=false |
So guys do you came up with any solution about the |
@AndonMitev No, haven't found a solution. This is an open issue about this at solidity 10354. If I understand the maintainer's comments there correctly, this is a known limitation of the solidity compiler and AbiEncoderV2. Out of curiosity, which compiler version are you using? One resource you might look at it is the argentlabs |
version: '0.7.3', |
Hey all, |
BTW, I got it fixed and working here: https://npmjs.com/package/@float-capital/solidity-coverage Hopefully will be up-streamed soon #642 👍 You can test it in the interim. Simply install the package and change the following in your hardhat.config.js: -require("solidity-coverage");
+require("@float-capital/solidity-coverage"); |
This worked for me but I had to set my hardfork to berlin! Thanks JasoonS!! |
Closing this for housekeeping. v0.8.7 now supports viaIR natively. While the optimizer is usually. turned off, if |
Hi, recently somehow I get a code that can only compile with optimizer on 😓😓😓
But anyway, just realized that during the coverage, it actually force flagging the using optimizer flag to false: https://github.com/sc-forks/solidity-coverage/blob/beta/dist/truffle.plugin.js#L92
Is there a reason to do so? Also, shall we also just keep in mind that the coverage would always be running without optimizer on?
The text was updated successfully, but these errors were encountered: