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: support multiple build info files #164

Closed
montyly opened this issue Mar 23, 2021 · 3 comments
Closed

hardhat: support multiple build info files #164

montyly opened this issue Mar 23, 2021 · 3 comments

Comments

@montyly
Copy link
Member

montyly commented Mar 23, 2021

We currently only take the first file in the build-info directory:

build_info = Path(build_directory, files[0])

However, it appears that hardhat can now generate multiple files and the others are thus not analyzed.

A breaking change to support multiple build-info files, is that because there are all compiled separately it is likely to break third-party integrations (see crytic/slither#731)

montyly added a commit that referenced this issue Apr 7, 2021
This is a breaking change (see the PR notes)
montyly added a commit that referenced this issue Apr 7, 2021
This is a breaking change (see the PR notes)

 Please enter the commit message for your changes. Lines starting
@alcuadrado
Copy link

Hey @montyly! Someone pointed me to this issue, and thought I could clarify things a bit.

Hardhat normally creates multiple build info files, one per compilation job. Recompiling a project doesn't mean that the same compilation job is going to be created, as we don't recompile things that haven't changed.

For example you can start with a single compilation job that builds everything, and hence a single build info file. Then modify a single file, recompile, and a new compilation job that only compiles it is created, so you end up with two build info files. Note that the first build info file will still have info about the recompiled contract.

The way to navigate these files is to start from the artifact's .dbg.json file, and read the build info that's indicated there.

@montyly
Copy link
Member Author

montyly commented Apr 8, 2021

Hi @alcuadrado

Thanks a lot for writing this, I was not aware of this partial recompiling behavior, it's nice. I explored the idea of using the dbg.json files, and found an issue (NomicFoundation/hardhat#1384).

We might switch to a workflow where we run hardhat compile --force or hardhat clean to ensure we always have a complete view of the contracts, while minimizing the duplicate contracts that can be in artifacts/build-info. I will investigate the tradeoff here.

@Jovonni
Copy link

Jovonni commented Jan 2, 2022

Is this following error due to my version of crytic-compile?

Command

echidna-test . --contract <Contract Name>
echidna-test: Couldn't compile given file
stdout:
stderr:
INFO:CryticCompile:'npx hardhat compile --force' running
INFO:CryticCompile:Compiling 70 files with 0.7.4
Generating typings for: 71 artifacts in dir: build/types for target: ethers-v5
Successfully generated 125 typings!
Compilation finished successfully


Traceback (most recent call last):
  File "/usr/local/bin/crytic-compile", line 33, in <module>
    sys.exit(load_entry_point('crytic-compile==0.2.2', 'console_scripts', 'crytic-compile')())
  File "/usr/local/lib/python3.9/site-packages/crytic_compile/__main__.py", line 192, in main
    compilations = compile_all(**vars(args))
  File "/usr/local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 637, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/usr/local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 117, in __init__
    self._compile(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 548, in _compile
    self._platform.compile(self, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/crytic_compile/platform/hardhat.py", line 87, in compile
    os.listdir(build_directory), key=lambda x: os.path.getmtime(Path(build_directory, x))
FileNotFoundError: [Errno 2] No such file or directory: 'artifacts/build-info'

This is in the root directory btw, targeting a contract inside the /contracts/ folder

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