Fix false-positive assertion violation (SWC-110) at PC 0 for contracts without assert (#1911)#1922
Open
jose-compu wants to merge 1 commit intoConsenSysDiligence:developfrom
Conversation
…SysDiligence#1911) Skip INVALID opcode at PC address 0 in the Exceptions module to prevent false-positive SWC-110 reports caused by analyzing runtime bytecode as creation bytecode. Co-authored-by: Cursor <cursoragent@cursor.com>
Author
|
please review @yrashk @lazzarello @rocky if you can. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
myth analyze -c <bytecode>reports a spurious SWC-110 (Assertion Violation) on Solidity contracts that contain noassert()statements. The false positive appears at PC address 0 with function namefallback.This occurs because the
-cflag treats input as creation bytecode by default. When runtime bytecode is fed this way, the symbolic executor runs it as a constructor, and theRETURNinstruction deploys arbitrary memory content as the "runtime code." If the first byte of that garbage happens to map toINVALID(or any unrecognized opcode), theExceptionsmodule flags it as an assertion violation — even though noassert()exists in the original contract.Reported in #1911 with a reproducible example compiled via
solc --optimize --via-ir --bin-runtimewith heavy Yul optimizations.Fix
Added a guard in
Exceptions._analyze_state()that skipsINVALIDopcodes at address 0. No legitimately compiled Solidity contract starts with an assertion; the first instructions are always the free-memory-pointer setup (PUSH1 0x80 PUSH1 0x40 MSTORE). AnINVALIDat PC 0 is reliably an artifact of non-contract bytecode being executed.Testing
test_no_assert_false_positive_at_pc0using the exact bytecode from the issue report.exceptions_0.8.0.sol.otests that verify legitimate assertion violations (2 issues) are still correctly detected.