Skip to content
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

Fixing parsing import alias issue #2455

Closed
wants to merge 6 commits into from
Closed

Conversation

MarHalborn
Copy link

@MarHalborn MarHalborn commented May 7, 2024

Fixing the issue explained in: https://github.com/crytic/slither/issues/2454

Summary by CodeRabbit

  • New Features
    • Enhanced handling of contract name resolution in expressions to improve accuracy and efficiency.

dependabot bot and others added 2 commits May 6, 2024 23:33
Bumps [undici](https://github.com/nodejs/undici) from 5.21.0 to 5.28.4.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](nodejs/undici@v5.21.0...v5.28.4)

---
updated-dependencies:
- dependency-name: undici
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
@CLAassistant
Copy link

CLAassistant commented May 7, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented May 7, 2024

Important

Auto Review Skipped

Review was skipped due to path filters

Files ignored due to path filters (1)
  • tests/e2e/compilation/test_data/test_node_modules/package-lock.json is excluded by !**/package-lock.json

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The update introduces logic to handle contract name resolution in the parse_expression function of expression_parsing.py, enhancing the management of contract imports with the same alias, a common challenge in intricate Solidity projects.

Changes

File Path Change Summary
slither/solc_parsing/expressions/expression_parsing.py Added logic for contract name resolution in parse_expression.

Possibly related issues

  • [Bug]: ERROR:ContractSolcParsing when using same alias for import #2454: This issue describes a problem with contract name resolution when aliases are used for imports. The changes in this PR could potentially address the parsing errors mentioned by ensuring correct contract name resolution, which aligns with the proposed debugging steps and solutions in the issue.

🐰✨
In the code where bugs once hopped,
A clever rabbit made a stop.
With a twitch of its nose,
And a wiggle of toes,
It patched the code; now it's top! 🚀
🐰💻


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fdf54f6 and 08bb3a5.
Files selected for processing (1)
  • slither/solc_parsing/expressions/expression_parsing.py (1 hunks)
Additional Context Used
GitHub Check Runs (1)
Lint Code Base failure (1)

slither/solc_parsing/expressions/expression_parsing.py: [warning] 525-525:
C0303: Trailing whitespace (trailing-whitespace)

Comment on lines 511 to 525

pattern = r'\b(\w+)\s*\)'

type_string = expression["typeDescriptions"]["typeString"]

type_string_name = re.search(pattern, type_string)

if type_string_name:
found_contract = type_string_name.group(1)
all_contracts_dict = {c.name: c for c in caller_context.compilation_unit.contracts}

if str(var) in all_contracts_dict.keys() and found_contract in all_contracts_dict.keys():
if str(var) != found_contract:
var = all_contracts_dict[found_contract]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve contract names correctly in import aliases.

-        if was_created:
-            var.set_offset(src, caller_context.compilation_unit)
-
-        identifier = Identifier(var)
-        identifier.set_offset(src, caller_context.compilation_unit)
-        var.references.append(identifier.source_mapping)
-
-        return identifier
+        if was_created:
+            var.set_offset(src, caller_context.compilation_unit)
+
+        identifier = Identifier(var)
+        identifier.set_offset(src, caller_context.compilation_unit)
+        var.references.append(identifier.source_mapping)
+
+        return identifier

Please remove the trailing whitespace on line 525 as it is a minor style issue but important for maintaining clean code.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
pattern = r'\b(\w+)\s*\)'
type_string = expression["typeDescriptions"]["typeString"]
type_string_name = re.search(pattern, type_string)
if type_string_name:
found_contract = type_string_name.group(1)
all_contracts_dict = {c.name: c for c in caller_context.compilation_unit.contracts}
if str(var) in all_contracts_dict.keys() and found_contract in all_contracts_dict.keys():
if str(var) != found_contract:
var = all_contracts_dict[found_contract]
pattern = r'\b(\w+)\s*\)'
type_string = expression["typeDescriptions"]["typeString"]
type_string_name = re.search(pattern, type_string)
if type_string_name:
found_contract = type_string_name.group(1)
all_contracts_dict = {c.name: c for c in caller_context.compilation_unit.contracts}
if str(var) in all_contracts_dict.keys() and found_contract in all_contracts_dict.keys():
if str(var) != found_contract:
var = all_contracts_dict[found_contract]

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 08bb3a5 and afe9418.
Files selected for processing (1)
  • slither/solc_parsing/expressions/expression_parsing.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • slither/solc_parsing/expressions/expression_parsing.py

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between afe9418 and 6721110.
Files selected for processing (1)
  • slither/solc_parsing/expressions/expression_parsing.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • slither/solc_parsing/expressions/expression_parsing.py

…e2e/compilation/test_data/test_node_modules/undici-5.28.4

Bump undici from 5.21.0 to 5.28.4 in /tests/e2e/compilation/test_data/test_node_modules
@0xalpharush
Copy link
Contributor

Thanks for the PR! I found the root cause and fixed it in #2459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants