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

Hardhat dependencyCompiler breaks compilation - crytic_compile.platform.exceptions.InvalidCompilation #743

Closed
krasi-georgiev opened this issue Dec 28, 2020 · 8 comments

Comments

@krasi-georgiev
Copy link

krasi-georgiev commented Dec 28, 2020

Master version - 7751cba

here is the full output

slither .  
'npx hardhat compile' running
Nothing to compile

(node:2977304) Warning: Accessing non-existent property 'INVALID_ALT_NUMBER' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2977304) Warning: Accessing non-existent property 'INVALID_ALT_NUMBER' of module exports inside circular dependency

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/slither_analyzer-0.7.0-py3.8.egg/slither/__main__.py", line 712, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.8/dist-packages/slither_analyzer-0.7.0-py3.8.egg/slither/__main__.py", line 71, in process_all
    compilations = compile_all(target, **vars(args))
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 1076, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 137, in __init__
    self._compile(**kwargs)
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 987, in _compile
    self._platform.compile(self, **kwargs)
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/platform/hardhat.py", line 145, in compile
    path = convert_filename(
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/utils/naming.py", line 102, in convert_filename
    raise InvalidCompilation(f"Unknown file: {filename}")
crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: contracts/_hardhat-dependency-compiler/tellorplayground/contracts/TellorPlayground.sol
ERROR:root:None
ERROR:root:Error in .
ERROR:root:Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/slither_analyzer-0.7.0-py3.8.egg/slither/__main__.py", line 712, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.8/dist-packages/slither_analyzer-0.7.0-py3.8.egg/slither/__main__.py", line 71, in process_all
    compilations = compile_all(target, **vars(args))
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 1076, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 137, in __init__
    self._compile(**kwargs)
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 987, in _compile
    self._platform.compile(self, **kwargs)
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/platform/hardhat.py", line 145, in compile
    path = convert_filename(
  File "/home/krasi/.local/lib/python3.8/site-packages/crytic_compile/utils/naming.py", line 102, in convert_filename
    raise InvalidCompilation(f"Unknown file: {filename}")
crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: contracts/_hardhat-dependency-compiler/tellorplayground/contracts/TellorPlayground.sol

here are the imports

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.3;

import "usingtellor/contracts/UsingTellor.sol";
import "./Token.sol";
import "./Math.sol";
import "./Inflation.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

and here is the package.json file

{
  "name": "chorus",
  "version": "1.0.0",
  "description": "A protocol for creating stable community currencies",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/tellor-io/chorus.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/tellor-io/chorus/issues"
  },
  "homepage": "https://github.com/tellor-io/chorus#readme",
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.1",
    "@nomiclabs/hardhat-etherscan": "^2.1.0",
    "@nomiclabs/hardhat-waffle": "^2.0.0",
    "chai": "^4.2.0",
    "dotenv": "^8.2.0",
    "ethereum-waffle": "^3.2.1",
    "ethers": "^5.0.23",
    "hardhat": "^2.0.4",
    "hardhat-dependency-compiler": "^1.0.0",
    "hardhat-gas-reporter": "^1.0.3",
    "hardhat-log-remover": "^2.0.0",
    "solidity-coverage": "^0.7.12",
    "tellorplayground": "github:tellor-io/tellorplayground#main"
  },
  "dependencies": {
    "@openzeppelin/contracts": "^3.3.0",
    "usingtellor": "github:krasi-georgiev/usingtellor#enablie-ci"
  }
}

@krasi-georgiev
Copy link
Author

some additional info

this happened becuase I had

dependencyCompiler: {
    paths: [
      'tellorplayground/contracts/TellorPlayground.sol',
    ],
  },

when I removed it deleted the artifacts and cache folder and now it seems to work fine.,

@krasi-georgiev
Copy link
Author

Unfortunately, I can't remove the dependencyCompiler as it is required for the tests.

@krasi-georgiev krasi-georgiev changed the title Within a hardhat project - crytic_compile.platform.exceptions.InvalidCompilation Hardhat dependencyCompiler breaks compilation - crytic_compile.platform.exceptions.InvalidCompilation Dec 28, 2020
@ItsNickBarry
Copy link

The hardhat-dependency-compiler plugin works by creating a temporary .sol file which imports an external contract before Hardhat compilation, and deleting it afterwards.

So what this error means is that the source file no longer exists:

crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: contracts/_hardhat-dependency-compiler/tellorplayground/contracts/TellorPlayground.sol

Is there any configuration option within Slither to skip analysis of certain contracts? Theoretically a contract imported by hardhat-dependency-compiler should be tested and validated within the repository in which it is published, so skipping analysis would make sense here. If not, I will consider adding an option to hardhat-dependency-compiler to prevent the deletion of the temporary contracts.

@krasi-georgiev
Copy link
Author

In my case this contract is used only in the tests so it is not used in the actual deployment and can safely be skipped for the checks.

@krasi-georgiev
Copy link
Author

OTOH I think it would be better to just remove the reference of this from the cache json

@krasi-georgiev
Copy link
Author

ping

@ItsNickBarry
Copy link

@krasi-georgiev See the linked issue. I still think Slither should allow for excluding certain files and paths from analysis (assuming it doesn't already), but this particular issue can now be closed.

@montyly
Copy link
Member

montyly commented Mar 4, 2021

Thanks @krasi-georgiev and @ItsNickBarry for digging into this issue.

I will take a closer look at this. Right now Slither needs
1 - All the compilations artifacts generated by solc
2 - All the source code

(1) might be difficult to remove. We had partial exploration of this in the past (see #352), yet I am not sure if it is something we can implement in the short term without significant changes (most of Slither codebase assumes it knows everything, and removing this will break a lot of internal assumptions).

(2) might be feasible, I will see how this can be implemented alongside with #695

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

No branches or pull requests

3 participants