-
Notifications
You must be signed in to change notification settings - Fork 996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use contract declarer's scope for name resolution #2459
Conversation
WalkthroughWalkthroughThe changes address a bug in Slither where the scope determination logic for variable assignments was incorrect when using the same alias for different imports. The updates involve modifying the scope assignment logic, adding new Solidity contracts and libraries for testing, and introducing new tests to ensure the correct handling of variable scopes and error handling. Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Out of diff range and nitpick comments (2)
slither/solc_parsing/expressions/find_variable.py (2)
Line range hint
191-191
: Replace lambda expressions with function definitions to improve readability and maintainability.- getter_available = lambda f: f.functions_declared + def getter_available(f): + return f.functions_declared - getter_available = lambda m: m.modifiers_declared + def getter_available(m): + return m.modifiers_declaredAlso applies to: 205-205
Line range hint
33-33
: Remove the unused importContractSolc
to clean up the code.- from slither.solc_parsing.declarations.contract import ContractSolc
Review Details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (7)
- slither/solc_parsing/expressions/find_variable.py (1 hunks)
- tests/unit/core/test_data/scope_with_renaming/core/MainContract.sol (1 hunks)
- tests/unit/core/test_data/scope_with_renaming/core/ParentContract.sol (1 hunks)
- tests/unit/core/test_data/scope_with_renaming/errors/MainErrors.sol (1 hunks)
- tests/unit/core/test_data/scope_with_renaming/errors/ParentContractErrors.sol (1 hunks)
- tests/unit/core/test_scope_with_renaming.py (1 hunks)
- tests/unit/core/test_using_for.py (1 hunks)
Files skipped from review due to trivial changes (1)
- tests/unit/core/test_data/scope_with_renaming/errors/MainErrors.sol
Additional Context Used
Ruff (3)
slither/solc_parsing/expressions/find_variable.py (3)
33-33:
slither.solc_parsing.declarations.contract.ContractSolc
imported but unused
191-191: Do not assign a
lambda
expression, use adef
205-205: Do not assign a
lambda
expression, use adef
Additional comments not posted (6)
tests/unit/core/test_data/scope_with_renaming/errors/ParentContractErrors.sol (1)
4-7
: The new custom errorsAccessControlErrors1
andAccessControlErrors2
are well-defined and follow Solidity conventions.tests/unit/core/test_scope_with_renaming.py (1)
11-17
: The test functiontest_find_variable_scope_with_renaming
is well-structured and correctly sets up the environment for testing the scope resolution with renaming. The use ofdisallow_partial=True
in theSlither
initialization ensures that partial analyses are not allowed, which is crucial for the accuracy of this test.tests/unit/core/test_data/scope_with_renaming/core/ParentContract.sol (1)
13-27
: The functionsfunctionWithAccessControlErrors1
andfunctionWithAccessControlErrors2
are correctly implemented to handle specific access control errors. The use of custom errors from theErrors
alias is consistent with the intended changes in the PR.tests/unit/core/test_data/scope_with_renaming/core/MainContract.sol (1)
16-38
: The functionsfunctionWithMainError1
,functionWithMainError2
, andfunctionWithMainError3
inMainContract
are implemented correctly to handle specific errors using theErrors
alias. This aligns with the PR's objective to ensure correct error handling in inherited contract scenarios.tests/unit/core/test_using_for.py (1)
20-20
: The update to initializeSlither
withdisallow_partial=True
in thetest_using_for_global_collision
function is a good practice to ensure that the analysis is comprehensive and does not skip any parts.slither/solc_parsing/expressions/find_variable.py (1)
307-307
: The change to useunderlying_function.contract_declarer.file_scope
instead ofunderlying_function.contract.file_scope
is crucial for ensuring that the scope resolution uses the correct contract's scope, especially in inheritance scenarios. This change directly addresses the issue described in the PR and is a significant improvement.
closes #2454
replaces #2455
The scope for
FunctionContract
was using the inherited contract's scope and not the declarer's so it was find the wrong aliasSummary by CodeRabbit
New Features
MainContract
andParentContract
Solidity smart contracts with enhanced error handling functions.MainErrors
andAccessControlErrors
Solidity libraries for custom error definitions.Bug Fixes
Tests
Slither
object.