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

Remapping Troubleshooting FAQ to README #2236

Closed
wants to merge 3 commits into from
Closed

Remapping Troubleshooting FAQ to README #2236

wants to merge 3 commits into from

Conversation

alexbabits
Copy link

FAQ for others figuring out the remappings in order to run slither on a single contract that had imports from OpenZeppelin. I also found that remapping was needed for the special slither tools like slither-check-erc.

This adds another bullet point to the FAQ about remaps and setting up slither.config.json if node_modules is not in the same housing as contracts/, using hardhat as an example.

@CLAassistant
Copy link

CLAassistant commented Nov 17, 2023

CLA assistant check
All committers have signed the CLA.

@@ -274,6 +274,22 @@ If you have a `node_modules/` folder, it must be in the same directory as `contr
run the compilation command for the framework you are using e.g `npx hardhat compile`. That must work successfully;
otherwise, slither's compilation engine, crytic-compile, cannot generate the AST.

* If `node_modules/` is not in your `contracts/` directory of your project, you will need to involve **remappings**. If a project has dependencies like OpenZeppelin or Chainlink, but you want to run Slither on a single `.sol` file or use [slither's tools](https://github.com/crytic/slither#tools) like `slither-check-erc`, you can add the `--solc-remaps @=node_modules/@` flag and/or configure `slither.config.json` in your project's root with the remapping. If `slither.config.json` remappings are setup the flag is no longer needed unless using [slither's tools](https://github.com/crytic/slither#tools). Foundry projects also require remappings if you want to analyze a specific `.sol` file that requires imports. Read more here: [Foundry Static Analysis Docs](https://book.getfoundry.sh/config/static-analyzers).

Copy link
Contributor

Choose a reason for hiding this comment

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

Foundry projects also require remappings if you want to analyze a specific .sol file that requires imports. Read more here: Foundry Static Analysis Docs.

I'm not sure this is accurate as of the 0.10.0 release. We use Foundry (which automatically configures the remappings) to compile single files

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if the last bit ("... or use a slither tool like slither-check-erc...") is accurate either. You can run both slither and tools like slither-check-erc with a project directory (like .) as target and not worry about remappings; in the case of standalone tools, they take the contract name you want to analyze:

% slither-check-erc .  Counter
# Check Counter

## Check functions
[ ] totalSupply() is missing 
[ ] balanceOf(address) is missing 
[ ] transfer(address,uint256) is missing 
[ ] transferFrom(address,address,uint256) is missing
...

Copy link
Author

Choose a reason for hiding this comment

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

elopez is correct my mistake, slither-check-erc . Counter does work without any remappings.

README.md Outdated
@@ -274,6 +274,22 @@ If you have a `node_modules/` folder, it must be in the same directory as `contr
run the compilation command for the framework you are using e.g `npx hardhat compile`. That must work successfully;
otherwise, slither's compilation engine, crytic-compile, cannot generate the AST.

* If `node_modules/` is not in your `contracts/` directory of your project, you will need to involve **remappings**. If a project has dependencies like OpenZeppelin or Chainlink, but you want to run Slither on a single `.sol` file or use [slither's tools](https://github.com/crytic/slither#tools) like `slither-check-erc`, you can add the `--solc-remaps @=node_modules/@` flag and/or configure `slither.config.json` in your project's root with the remapping. If `slither.config.json` remappings are setup the flag is no longer needed unless using [slither's tools](https://github.com/crytic/slither#tools). Foundry projects also require remappings if you want to analyze a specific `.sol` file that requires imports. Read more here: [Foundry Static Analysis Docs](https://book.getfoundry.sh/config/static-analyzers).
Copy link
Contributor

@0xalpharush 0xalpharush Nov 17, 2023

Choose a reason for hiding this comment

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

Suggested change
* If `node_modules/` is not in your `contracts/` directory of your project, you will need to involve **remappings**. If a project has dependencies like OpenZeppelin or Chainlink, but you want to run Slither on a single `.sol` file or use [slither's tools](https://github.com/crytic/slither#tools) like `slither-check-erc`, you can add the `--solc-remaps @=node_modules/@` flag and/or configure `slither.config.json` in your project's root with the remapping. If `slither.config.json` remappings are setup the flag is no longer needed unless using [slither's tools](https://github.com/crytic/slither#tools). Foundry projects also require remappings if you want to analyze a specific `.sol` file that requires imports. Read more here: [Foundry Static Analysis Docs](https://book.getfoundry.sh/config/static-analyzers).
* If `node_modules/` is not in the `contracts/` directory of your project, you may need to use **remappings**. If a project has dependencies such as OpenZeppelin and you want to run Slither on a single `.sol` file or use a [slither tool](https://github.com/crytic/slither#tools) like `slither-check-erc`, add the remapping on the command line e.g. `--solc-remaps @=node_modules/@` or to the `slither.config.json` in your project's root. Note, this should not be required for Foundry projects as it is handled automatically.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for this! We need to publish the FAQs somewhere besides the README but this is fine in the meantime

@0xalpharush
Copy link
Contributor

@alexbabits
Copy link
Author

Let me know if you'd like anything else, latest attempt is README.md remappings FAQ at abf518d. Thanks!

@alexbabits
Copy link
Author

(I ran the markdownlint in both cases and passed, but the Lint Code Base Superlinter failed).

@alexbabits alexbabits closed this by deleting the head repository May 5, 2024
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