Skip to content

Adding support for Hardhat 3 projects#631

Merged
smonicas merged 16 commits intocrytic:devfrom
imadarchid:dev
Jan 5, 2026
Merged

Adding support for Hardhat 3 projects#631
smonicas merged 16 commits intocrytic:devfrom
imadarchid:dev

Conversation

@imadarchid
Copy link
Copy Markdown
Contributor

Summary

This PR adds initial support for Hardhat v3 projects in crytic-compile. Hardhat v3 introduces breaking changes in artifact generation and path handling that cause the current parser to fail. The implementation remains fully backward-compatible with Hardhat v2.

Context #629

Background

Hardhat v3 introduces:

  • Split artifacts: compiler outputs are now separated into multiple files, which breaks crytic-compile’s assumption of a single artifact per contract.

  • Prefixed paths: sources are now referenced using project/ and npm/ prefixes, affecting both project parsing and filename lookup during compilation.

Changes

  • Added detection of Hardhat v3 projects and a separate parsing flow.
  • Normalized filenames using regex to restore correct lookup behavior.
  • Updated artifact processing to handle the new multi-file structure.
  • Added tests covering Hardhat v3 scenarios.

Disclaimer

I am not yet fully familiar with the entire codebase, so there may be edge cases I missed. This PR should be considered a starting point for discussion.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 9, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Member

@elopez elopez left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the PR! Here's some things I noticed from a first look at it.

Copy link
Copy Markdown
Member

@elopez elopez left a comment

Choose a reason for hiding this comment

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

There's a few failures on the CI lint jobs, can you take a look at those? thanks!

@imadarchid
Copy link
Copy Markdown
Contributor Author

There's a few failures on the CI lint jobs, can you take a look at those? thanks!

Yes on it

@imadarchid imadarchid requested a review from elopez December 14, 2025 16:38
@imadarchid
Copy link
Copy Markdown
Contributor Author

Hi @elopez, anything else required here?

@elopez
Copy link
Copy Markdown
Member

elopez commented Dec 19, 2025

Hi @imadarchid! Looks good from my side, thanks! I'm waiting for a review from @smonicas before we merge.

@imadarchid
Copy link
Copy Markdown
Contributor Author

Got it, thanks for the update @elopez!

Copy link
Copy Markdown
Collaborator

@smonicas smonicas left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the PR. Only one thing that Hardhat outputs in the stdout also Warnings for example if you are using a node version not officially supported.

WARNING: You are using Node.js 23.11.0 which is not supported by Hardhat.
Please upgrade to 22.10.0 or a later LTS version (even major version number)

In the _run_hardhat_console function we can filter that out and still try to continue the execution while showing a log to the user, just in case it can cause an actual problem. Adding something like the following would be good enough to handle this case, in the current code we would get an error when trying to deserialize the configuration since it's not a valid json.

            brace_index = stdout.find('{')
            if brace_index > 2:
                LOGGER.info("Unexpected output from Hardhat, trying to parse it anyway: %s", stdout)
                stdout = stdout[brace_index:]

@imadarchid
Copy link
Copy Markdown
Contributor Author

In the _run_hardhat_console function we can filter that out and still try to continue the execution while showing a log to the user, just in case it can cause an actual problem. Adding something like the following would be good enough to handle this case, in the current code we would get an error when trying to deserialize the configuration since it's not a valid json.

Thanks for flagging this, I will address it in the code

@imadarchid imadarchid requested a review from smonicas December 24, 2025 11:57
@smonicas smonicas merged commit 62ce55b into crytic:dev Jan 5, 2026
103 of 105 checks passed
@imadarchid imadarchid mentioned this pull request Jan 6, 2026
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