Bugs in the Solidity optimizer were reported in the following ways: Ethereum Foundation Bounty Program, by Christoph Jentsch. This bug has been patched as of May 3, 2017, and Solidity 0.4.11 has been released.
background
The bug in question was related to how the optimizer optimizes constants in byte code. “Bytecode constant” means all of the following: pushStored on the stack (not to be confused with the Solidity constant).For example, if the value 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff teeth pushed, the optimizer can do one of the following PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffor choose to encode this as push 1 1; no;.
An error in the optimizer generates a routine that does not properly recreate the original constant, causing byte code constant optimization to fail in certain cases.
The behavior described in the reported bug was discovered within a contract, causing one method to stop working when another completely unrelated method was added to the contract. Analysis revealed that a number of conditions must exist simultaneously for the bug to occur. There are always two combinations of conditions that cause a bug:
- Constant must start with 0xFF… Ends with a long series of zeros (or vice versa).
- The same constant must be used in multiple places for the optimizer to choose to optimize this particular constant. Alternatively, it should be used in a constructor that optimizes for size rather than gas.
In addition to the two conditions above, a more complex condition is required.
analysis
This bug has been present in all released versions of Solidity since at least the summer of 2015 until now. This bug has been around since his 2015, but it seems very difficult to trigger by “random” code.
We performed a static analysis of all contract code deployed on the blockchain and found no such invalidly generated routines. Please note that the fact that no bugs have been found in all contract code does not guarantee that such problems will not occur.
Improvement points
To increase Solidity transparency and bug awareness, we have started exporting information about Solidity-related vulnerabilities to the Solidity code repository as JSON files (1,2). We expect block explorers to be able to integrate this information with other contract-related information.
Etherscan has already implemented this. here and here.
As for the bug itself, we added a mini-EVM to the optimizer that verifies the correctness of each generated routine at compile time.
Additionally, development of a fully specified higher-level intermediate language has already begun. Future optimizer routines for this language will be much easier to understand and audit, and will replace the current optimizer.