I'm at a very puzzling scenario.

While using Remix, I noticed that adding a few asserts has caused a significant increase in execution cost (from ~50K to ~59K). And not only did it increase the execution cost of the updated function, but also of any other (public) function!!!

The only solid conclusion that I came up with, is that there's a "gas penalty" which takes effect as soon as the global number of asserts in the contract exceeds a certain threshold. BTW, the exact same behavior occurs when I replace the asserts with requires.

My current Solidity version is 0.4.16+commit.d7661dd9.Emscripten.clang, and I am compiling with optimization enabled. However, it seems to happen on previous compiler versions as well (I've tried a few of them, down to v0.4.11).

Unfortunately, I am unable to reproduce this problem within a minimal working code snippet, and pasting the entire contract here would probably mess up the entire question. So if possible to get an answer (or any other suggestion regarding the source of this problem) without a coding example, then I would be grateful.

Thank you very much.

  • Could you share the code in a github gist? – maurelian Aug 28 '17 at 13:55
  • @maurelian: How do I do that (i.e., what's "github gist")? Thanks. – goodvibration Aug 28 '17 at 14:02
  • Are your asserts causing a big increase in gas in a loop by any chance? Or called by something in a loop. – lungj Aug 28 '17 at 14:31
  • @lungj: No, certainly not. That would be too easy if it had been the case. Though, I've now realized that it could possibly be an addition of any (arbitrary) piece of code. It's just that I was focused on those asserts, and it kinda eluded me that it might be any other opcode. In any case, the problem of one function's execution cost increasing after adding code in another function - this problem sustains. I can't find any way to explain this other than "caching" issues, which I sincerely doubt could even exist on the EVM. – goodvibration Aug 28 '17 at 14:39
  • @goodvibration I didn't entirely follow your last comment, but are your asserts using expensive operations like calling function as part of the assert? – lungj Aug 28 '17 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.