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

🔨 fallback to Foundry remappings #44

Merged
merged 2 commits into from
Apr 26, 2024
Merged

Conversation

GianfrancoBazzani
Copy link
Contributor

Hey guys i had a problem with resolution when not all remappings are defined in remmapings.txt

@CLAassistant
Copy link

CLAassistant commented Apr 3, 2024

CLA assistant check
All committers have signed the CLA.

@0xalpharush
Copy link
Contributor

We should probably just get them from crytic-compile here

remappings = find_remappings(False)

https://github.com/crytic/crytic-compile/blob/b5c538aaa66be44b7a68d9723881a7eba2c20898/crytic_compile/platform/abstract_platform.py#L34

@GianfrancoBazzani GianfrancoBazzani force-pushed the main branch 2 times, most recently from c482880 to 1fbd4d2 Compare April 3, 2024 19:23
@GianfrancoBazzani
Copy link
Contributor Author

Hi @0xalpharush not sure how to do that, seems that find_remappings is performing some extra checks.

@tuturu-tech
Copy link
Collaborator

If we want to use crytic-compile I think we can do this like so:

def find_remappings(include_attacks: bool, slither: Slither) -> dict:
    ... # regex
    working_dir = slither.crytic_compile.working_dir
    platform_config = slither.crytic_compile.platform.config(working_dir)

    remappings: str = ""
    if platform_config:
        remappings = "\n".join(platform_config.remappings)
    else:
        output = subprocess.run(["forge", "remappings"], capture_output=True, text=True, check=True)
        forge_remaps = str(output.stdout).split("\n")

        if os.path.exists("remappings.txt"):
            with open("remappings.txt", "r", encoding="utf-8") as file:
                remappings_file = file.read().split("\n")
                # Converting to set to remove duplicates, back to list for joining
                forge_remaps = list(set(forge_remaps + remappings_file))

        remappings = "\n".join(forge_remaps)

We'd need to update all the places that call find_remappings as well, but this should handle the case where the remappings file is defined but doesn't contain all the remappings. I think the crytic-compile remappings should contain both by default.

Would be cool if we could have a test for this specific case as well.

Copy link
Collaborator

@tuturu-tech tuturu-tech left a comment

Choose a reason for hiding this comment

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

  • Update the PR so that the crytic-compile platform config remappings are used
  • Run the subprocess before fetching the remappings file and merge the two (without duplicates)
  • Add a single test case for when the remappings file does not contain all of the remappings

@tuturu-tech
Copy link
Collaborator

I'll be updating the PR with the proposed changes sometime this week so we can merge it. @GianfrancoBazzani really appreciate you opening the PR and highlighting the issue

@GianfrancoBazzani
Copy link
Contributor Author

Thank you, I don't had time to check it out :(.

@tuturu-tech tuturu-tech merged commit 4b1510d into crytic:main Apr 26, 2024
8 checks passed
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.

4 participants