Is optimization in Remix worth the risk of bugs?

Is the future gas savings for users worth the risk of bugs? In other words, is optimization worth it when launching a token using Remix?

Tether has had 112 million transfers…https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7

Does that mean Tether should have optimized itself for 112 million runs or more?

Would Tether even want to risk optimization? Does Tether reach a point where it becomes completely unoptimized?

What is the least buggy way of launching my token? I want my token to have the least bugs as possible even if gas costs are higher. Should I uncheck optimization in that case?

Thank you.

I think optimization is the property of the solidity compiler, you can find more details in the solidity documentation: Using the Compiler | Solidity 0.8.6 documentation

And these is a blog to explain more about it: Ask the Solidity Team Anything #1 Recap | Solidity Blog

2 Likes

Arguably, if you want to absolutely minimize risk of bugs you should disable the optimizer.

However, the fact is there have been very few bugs in the optimizer in recent time. See List of Known Bugs.

1 Like

Thank you. Are the gas savings for users significant with optimization enabled?

For simple erc20 tokens, optimizations would yield around a few hundred gas savings for calls. (For a simple benchmark, see: https://github.com/ethereum/solidity/pull/11598/files; compare gas legacy and gas legacy optimized there.)

Note that there are several OZ based ERC20 tokens deployed with the optimizer turned on. So it’s unlikely that your token would run into optimizer bugs. From the list of known bugs (https://docs.soliditylang.org/en/latest/bugs.html), one can see that optimizer bugs are rather rare, and only affected rather artificial code.

Also, I would argue that tether would be a poor choice for an inspiration on token design, with their ability to blacklist anyone and burn anyone’s funds at any point. AFAIK, they haven’t enabled the optimizer in their contract.

4 Likes

On another forum someone was telling me that there are diminishing returns on optimizer figures in Remix and that 200 would be enough for token with heavy transaction numbers. In other words, a token with a 1,000,000 optimizer would not be 1,000 times more efficient than a token with a 1,000 optimizer and that most of the effect would be felt with 200. Another person said that 1,000 would be good.

What would you recommend?

What would be the downside of using a 1,000,000,000 optimizer?

No definitely not. I don’t think there is a big downside to using 1,000,000,000 as runs value. It may result in larger code but cheaper runtime cost. You can experiment with your own contract and see.