Fix for tracebacks and dev reverts in solc 0.8.0 #907
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I did
Fix tracebacks and dev revert reasons for solc 0.8.0 when optimization is enabled.
Closes #897
How I did it
Solidity 0.8.0 introduces a new optimization where all reverts/requires that include an error string are handled by the same bytecode. The source mapping for this bytecode points at the first revert statement that the compiler encounters - as such, when attempting to generate a traceback, all reverting tx's that include an error string will appear to fail at the same location.
To fix this, I'm flagging that first revert as the "optimizer revert". When it's encountered, I step back through the trace until I find a jumpdest (arriving at the optimizer revert from a yul optimization), and then further until i find an instruction with a source offset. This offset is the actual location of the failing revert/require.
This, as with many of Brownie's trace operations, is a hacky heuristic that almost certainly has some failing edge cases and will likely be invalidated by a future change in a patch release of Solidity. But it works right now, so.. this is what we're doing.
How to verify it
Don't even try. Just hope and pray.