Zokyo Automated Tools
  • πŸ€–Unlocking Smart Contract Security: A Comprehensive Guide to Automated Vulnerability Analysis
  • 🐍Mastering Slither: A Comprehensive Guide to Smart Contract Vulnerability Detection
    • πŸš€Prerequisites
      • πŸ’»Code Editor
      • 🐍Setting up Python and Configuring Virtual Environments
      • πŸ”­Setting Up Git
      • πŸ‘ŠGit Bash
    • ⚑What Is Static Analysis
    • 🐍What Is Slither
    • πŸ“©Setting Up Slither: Installation and Virtual Environment Configuration
    • πŸ”©Installing solc and Crytic Compile: Foundation Tools for Slither
    • πŸ”Analyzing Smart Contracts Locally with Slither
      • πŸ—ΊοΈHandling Import Errors in Slither: A Guide on Solc Remappings
      • πŸ›£οΈHandling Path Errors In Slither
    • 🌍Analyzing Smart Contracts Already Deployed On Main-nets
    • πŸ”ŒExploring Slither's Tools and Printers: A Comprehensive Tutorial
    • πŸ€–Using Bash Scripts for Batch Analysis with Slither
    • πŸ’»Slither Intermediate Representation
    • 🌐Slither Python API
    • ⚠️Custom Detectors in Slither
      • 🀝Leveraging Custom Detectors from the Community
        • πŸ€—Leveraging Custom Detectors from the Community: Spotlight on the pessimistic.io Team
      • 🌱Making your own detectors
  • βš›οΈOyente: Symbolic Execution Tool
    • 😎What Is Symbolic Execution?
Powered by GitBook
On this page
  • Introduction
  • Understanding the Error
  • Understanding solc-remaps
  • Tutorial Steps: Using solc-remaps to Resolve Import Errors
  • Conclusion
  1. Mastering Slither: A Comprehensive Guide to Smart Contract Vulnerability Detection
  2. Analyzing Smart Contracts Locally with Slither

Handling Import Errors in Slither: A Guide on Solc Remappings

PreviousAnalyzing Smart Contracts Locally with SlitherNextHandling Path Errors In Slither

Last updated 1 year ago

Introduction

While using Slither for static analysis of Solidity contracts, one common issue that users might face is related to the importing of external dependencies or libraries such as OpenZeppelin. This tutorial aims to guide you through resolving such errors, particularly when Slither can’t find your imported files. Here, we will focus on the use of --solc-remaps to solve this problem.

Understanding the Error

Error Description:

Error: Source "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol" not found: File not found.

Error Analysis:

This error occurs when the Solidity compiler (solc) can't locate the imported dependencies in the specified paths. In the context of the error above, the compiler is unable to find the ERC721Enumerable.sol file in the OpenZeppelin contracts library.

Understanding solc-remaps

solc-remaps is an option that allows us to redirect the compiler to the correct directory where the dependencies are located. It essentially creates a mapping between the logical import paths used in the code and the actual physical location of the dependency files on the disk.

Tutorial Steps: Using solc-remaps to Resolve Import Errors

Step 1: Identifying the Error

When you run Slither, identify the import errors, which typically indicate the logical paths where dependencies couldn’t be found.

Step 2: Locating Dependencies

Locate where the dependencies like OpenZeppelin contracts are installed in your project. You might find them in the node_modules directory if you are using Node.js.

Step 3: Using solc-remaps Option in Slither

  1. Use the --solc-remaps option followed by the mapping between the logical import path and the actual physical location.

    slither <your-contract.sol> --solc-remaps "@openzeppelin/=C:/Users/Omar/Desktop/InternshipTask/internship-tasks/node_modules/@openzeppelin/"
    • @openzeppelin/ is the logical path used in the import statement.

    • C:/Users/Omar/Desktop/InternshipTask/internship-tasks/node_modules/@openzeppelin/ is the actual location where the OpenZeppelin contracts are installed.

  2. Run the command, and Slither should now be able to locate the dependencies and run the analysis without import errors.

Conclusion

Understanding and using solc-remaps is crucial for handling import errors in Slither when dealing with external dependencies. By redirecting the Solidity compiler to the correct directories, we ensure that the code analysis proceeds smoothly without interruptions due to missing dependencies. Always ensure that your mappings correctly align with the physical locations of the libraries and contracts to avoid such errors during the static analysis process.

🐍
πŸ”
πŸ—ΊοΈ
Book an audit with Zokyo