Skip to content

autosetup: read Hardhat compiler settings from build-info when Node is absent - #318

Open
jar-ben wants to merge 4 commits into
masterfrom
jaroslav/hardhat-build-info-config
Open

jar-ben wants to merge 4 commits into
masterfrom
jaroslav/hardhat-build-info-config

Conversation

@jar-ben

@jar-ben jar-ben commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

Autosetup resolves a Hardhat project's compiler settings by loading hardhat.config.{js,ts} through
a Node.js extraction script. When that fails (no Node.js, or the extraction errors), it falls back to
the default configuration: no solc version, so solc is resolved from the source pragmas and the newest
version they admit is used.

For a project pinned to an older solc, the newest admitted version can fail where the pinned one
compiles. Seen on a ^0.8.19 project configured for 0.8.19 with viaIR: autosetup picked
0.8.34, the main contract hit stack-too-deep (YulException: Cannot swap Variable ... too deep in the stack) under every setting the compilation workarounds tried, and compilation analysis failed.
Compiled directly with solc from the project's own build-info input, the same contract compiles on
0.8.19 and fails on 0.8.34 with or without the optimizer and viaIR.

Fix

HardhatManager.parse_config falls back to artifacts/build-info/*.json when the config cannot be
resolved through Node.js. Each build-info file is the solc standard-json input of one job of the
project's own hardhat compile, with the exact solcVersion and settings it ran with.

  • Every distinct (version, settings) pair becomes one solidity.compilers entry, the job compiling
    the most sources first, in the same shape the Node.js extractor produces. It goes through the
    existing _extract_config_from_json, so single vs. multiple solc versions (compiler_map),
    evmVersion, and not inheriting the optimizer / viaIR behave exactly as for an extracted config.
  • Files without a solcVersion and an input are skipped; unreadable ones are skipped with a
    warning.
  • Falling back to the default configuration is now a WARNING instead of an INFO.

Node.js is still tried first, so environments where it is available behave as before.

Limitations

  • Per-file solidity.overrides are not recovered: an override job is just another compilers entry,
    so the first entry's settings (e.g. evmVersion) apply to every file. The Node.js path still
    handles overrides.
  • A build-info left from an earlier compile with different settings is read as current.
  • Only the default artifacts dir is read; a custom paths.artifacts is only known through Node.js.

Testing

  • tests/test_hardhat_config.py: build-info used when Node.js resolution fails (version, optimizer,
    viaIR, evmVersion); multiple versions leave solc unset; the largest job sets the settings;
    files without solc input and malformed JSON are skipped; defaults when neither source is available.
  • Ran parse_config with Node.js off PATH on the affected project's sources: resolves to
    {'solc': 'solc8.19'} (previously no solc, resolved to 0.8.34).
  • pytest tests/ -m "not expensive": no new failures (the only errors are tests needing a local
    postgres/docker). pyright clean on the changed module.

@jar-ben
jar-ben force-pushed the jaroslav/hardhat-build-info-config branch from f254dd4 to 9b2411a Compare November 18, 2026 19:10
@jar-ben
jar-ben requested a review from shellygr November 18, 2026 19:15

This branch has not been deployed

No deployments
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.

2 participants