ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.23k stars 5.75k forks source link

Option to harden the Yul optimizer against AST-ID based non-determinism. #14535

Open ekpyron opened 1 year ago

ekpyron commented 1 year ago

Note: this issue is meant to lay out a solution that will take a good amount of refactoring merely for consideration and may not be what we end up doing.

We keep running into issues like https://github.com/ethereum/solidity/issues/14494 with the Yul optimizer. The symptom is differences in bytecode between one compilation of a contract and another compilation with additional, but unrelated source files. In these cases the compiler-generated metadata is identical, which is supposed to guarantee identical compiler output. However, this guarantee is violated.

There are potential causes already in IR code generation, this issue means to address causes in the Yul optimizer.

The following would be an option to evade this issue once and for all, while potentially allowing to increase the optimizer performance in the process (however, the actual expected improvement is hard to estimate and may not be significant):

Complications:

ekpyron commented 1 year ago

Actually, there is a less-invasive, yet messier, variant of the above:

We could leave the Yul AST data structures untouched, but translate all identifiers, excluding builtins, to _1, _2, ... in the beginning of optimization, while still keeping above mapping to original names for a back-translation.