crytic/crytic-compile

Fail to compile some hardhat projects

Xenomega opened this issue · 5 comments

The crytic-compile CI shows a failure to compile some projects: https://github.com/crytic/crytic-compile/actions/runs/4754028647/jobs/8446340120

Output:

Testing hardhat integration of /opt/hostedtoolcache/Python/3.8.16/x64/bin/crytic-compile
npm WARN deprecated ganache-core@2.13.2: ganache-core is now ganache; visit https://trfl.io/g7 for details
npm WARN deprecated ganache-core@2.13.2: ganache-core is now ganache; visit https://trfl.io/g7 for details
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated testrpc@0.0.1: testrpc has been renamed to ganache-cli, please use this package from now on.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated @ensdomains/ens@0.4.5: Please use @ensdomains/ens-contracts
npm WARN deprecated @ensdomains/resolver@0.2.4: Please use @ensdomains/ens-contracts

added 1433 packages, and audited 1437 packages in 38s

127 packages are looking for funding
  run `npm fund` for details

71 vulnerabilities (20 moderate, 27 high, 24 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
INFO:CryticCompile:'npx hardhat clean' running (wd: /home/runner/work/crytic-compile/crytic-compile/tests/hardhat)
INFO:CryticCompile:'npx hardhat clean --global' running (wd: /home/runner/work/crytic-compile/crytic-compile/tests/hardhat)
INFO:CryticCompile:'npx hardhat compile --force' running
INFO:CryticCompile:Downloading compiler 0.7.3

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.[16](https://github.com/crytic/crytic-compile/actions/runs/4754028647/jobs/8446340120#step:9:17)/x64/bin/crytic-compile", line 8, in <module>
    sys.exit(main())
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/crytic_compile/__main__.py", line 221, in main
    compilations = compile_all(**vars(args))
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 643, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
    self._compile(**kwargs)
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
    self._platform.compile(self, **kwargs)
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/crytic_compile/platform/hardhat.py", line [19](https://github.com/crytic/crytic-compile/actions/runs/4754028647/jobs/8446340120#step:9:20)5, in compile
    hardhat_like_parsing(crytic_compile, self._target, build_directory, hardhat_working_dir)
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/crytic_compile/platform/hardhat.py", line 49, in hardhat_like_parsing
    os.listdir(build_directory), key=lambda x: os.path.getmtime(Path(build_directory, x))
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/work/crytic-compile/crytic-compile/tests/hardhat/artifacts/build-info'
Monorepo test failed
Error: Process completed with exit code [25](https://github.com/crytic/crytic-compile/actions/runs/4754028647/jobs/8446340120#step:9:26)5.

Similarly, this is causing medusa's CI to fail.

Output:

--- FAIL: TestCryticDirectoryNoArgs (79.95s)
    crytic_compile_test.go:245: 
        	Error Trace:	/Users/runner/work/medusa/medusa/compilation/platforms/crytic_compile_test.go:245
        	            				/Users/runner/work/medusa/medusa/utils/testutils/test_directory_utils.go:65
        	            				/Users/runner/work/medusa/medusa/compilation/platforms/crytic_compile_test.go:235
        	Error:      	Received unexpected error:
        	            	error while executing crytic-compile:
        	            	OUTPUT:
        	            	INFO:CryticCompile:'npx hardhat clean' running (wd: /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/TestCryticDirectoryNoArgs13356[76](https://github.com/crytic/medusa/actions/runs/4756484891/jobs/8453387494#step:7:77)214/001/medusaTest/basic_project)
        	            	INFO:CryticCompile:'npx hardhat clean --global' running (wd: /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/TestCryticDirectoryNoArgs1335676214/001/medusaTest/basic_project)
        	            	INFO:CryticCompile:'npx hardhat compile --force' running
        	            	INFO:CryticCompile:Downloading compiler 0.8.10
        	            	Downloading compiler 0.7.1
        	            	
        	            	Traceback (most recent call last):
        	            	  File "/Library/Frameworks/Python.framework/Versions/Current/bin/crytic-compile", line 8, in <module>
        	            	    sys.exit(main())
        	            	             ^^^^^^
        	            	  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/crytic_compile/__main__.py", line 221, in main
        	            	    compilations = compile_all(**vars(args))
        	            	                   ^^^^^^^^^^^^^^^^^^^^^^^^^
        	            	  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/crytic_compile/crytic_compile.py", line 643, in compile_all
        	            	    compilations.append(CryticCompile(target, **kwargs))
        	            	                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        	            	  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
        	            	    self._compile(**kwargs)
        	            	  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
        	            	    self._platform.compile(self, **kwargs)
        	            	  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/crytic_compile/platform/hardhat.py", line 1[95](https://github.com/crytic/medusa/actions/runs/4756484891/jobs/8453387494#step:7:96), in compile
        	            	    hardhat_like_parsing(crytic_compile, self._target, build_directory, hardhat_working_dir)
        	            	  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/crytic_compile/platform/hardhat.py", line 49, in hardhat_like_parsing
        	            	    os.listdir(build_directory), key=lambda x: os.path.getmtime(Path(build_directory, x))
        	            	    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        	            	FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/TestCryticDirectoryNoArgs1335676214/001/medusaTest/basic_project/artifacts/build-info'

This is possibly related to NomicFoundation/hardhat#3877 -- see also crytic/slither-action#56

As a workaround, downgrading Node can resolve the failures.

Note that we are seeing this issue with Node 16 so downgrade may or may not be helpful.

I encountered the same error with a foundry project.
Source url: https://github.com/code-423n4/2023-01-ondo (commit f3426e5b6b4561e09460b2e6471eb694efdd6c70)

When I ran crytic-compile ., I got this error:

Traceback (most recent call last):
  File "/opt/homebrew/bin/crytic-compile", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/crytic_compile/__main__.py", line 221, in main
    compilations = compile_all(**vars(args))
  File "/opt/homebrew/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 643, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/opt/homebrew/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
    self._compile(**kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
    self._platform.compile(self, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/crytic_compile/platform/foundry.py", line 90, in compile
    hardhat_like_parsing(crytic_compile, self._target, build_directory, self._target)
  File "/opt/homebrew/lib/python3.9/site-packages/crytic_compile/platform/hardhat.py", line 49, in hardhat_like_parsing
    os.listdir(build_directory), key=lambda x: os.path.getmtime(Path(build_directory, x))
FileNotFoundError: [Errno 2] No such file or directory: 'out/build-info'

My crytic-compile version: 0.3.1

forge build --build-info --force runs fine, otherwise.

Hi @duckki, that error message seems to be unrelated. The repo you linked has a custom out folder name, which crytic-compile cannot autodetect yet: https://github.com/code-423n4/2023-01-ondo/blob/main/foundry.toml#L4

You can either remove that line and use the default foundry out name, or provide the custom name to crytic-compile using the --foundry-out-directory option:

crytic-compile . --foundry-out-directory ./artifactsforge/

@elopez Thanks for the info!