Fix inheritance resolution for transitive duplicate contract names - #3071
Open
suxnju wants to merge 1 commit into
Open
Fix inheritance resolution for transitive duplicate contract names#3071suxnju wants to merge 1 commit into
suxnju wants to merge 1 commit into
Conversation
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
Slither can resolve a Solidity base contract to the wrong declaration when a transitive import exposes another declaration with the same name. Solidity's compact AST already identifies every entry in
linearizedBaseContractsandbaseContractswith areferencedDeclaration, but Slither's remapping path discarded that identity and performed a name-based lookup through imported and current file scopes.For example, consider four source files:
BaseLock.soldeclares an abstract contract namedLock.LockLibrary.soldeclares a library namedLock.IndirectBase.solimports the library and uses it withusing Lock for uint256.Target.solinherits bothIndirectBaseand the contractLock.The compiler identifies the intended base contract unambiguously. The previous lookup could nevertheless bind
Targetto the transitiveLocklibrary. In a larger compilation this incorrect dependency can leave Slither's semantic analysis with no analyzable contracts and make analysis appear to hang.This occurred in a verified Universal Router compilation from Ethereum. The artifact contains both a contract and a library named
Lock; Slither selected the library forDispatcher's inheritance and did not complete within the 10-second diagnostic timeout.Change
When resolving a remapped inheritance entry, first look up the compiler-provided declaration ID in
_contracts_by_id. Use that declaration when its name agrees with the AST remapping name.The name check is intentional. It keeps the existing import-renaming and file scope lookup as a compatibility path for invalid IDs and aliased imports, while using compiler identity whenever that identity is internally consistent.
A four-file regression fixture reproduces the collision and asserts that
Targetinherits theLockcontract rather than the same-named library.Tests
Minimal reproduction
The new fixture is under
tests/unit/core/test_data/inheritance_resolution/transitive_duplicate_name/.It is compiled as Solidity Standard JSON with solc 0.8.15.
Before the change, the isolated reproduction did not complete within 10 seconds. After the change, Slither builds the model and resolves:
The complete inheritance-resolution unit module passes:
This includes the existing renamed-import and duplicate-name tests, so their fallback behavior remains covered.
Real verified on-chain contract
The fix was validated against existing Solidity Standard JSON artifacts for:
chainId=1)0x66a9893cc07d91d95644aedd05d03f95e1dba8afsrc/pkgs/universal-router/contracts/UniversalRouter.sol:UniversalRouter0.8.26+commit.8a97fa7aThe patched source tree completed semantic construction in approximately 2.5 seconds and produced the following checked results:
Before the fix, the same artifact selected the
Locklibrary and timed out during analysis.Slither regression suite
No Solidity or inheritance-resolution regression was observed. Ruff reported
All checks passed, andgit diff --checkcompleted without errors.