Skip to content

fix: traverse up to discover compilation framework config#676

Open
cats2101 wants to merge 1 commit intocrytic:masterfrom
cats2101:traverse-config-discovery
Open

fix: traverse up to discover compilation framework config#676
cats2101 wants to merge 1 commit intocrytic:masterfrom
cats2101:traverse-config-discovery

Conversation

@cats2101
Copy link
Copy Markdown

Closes #538.

When the target is a single Solidity file and crytic-compile falls back to the Solc platform, the code used to check only the working directory for a known compilation framework (Foundry, Hardhat, ...). If the user invoked crytic-compile from a subdirectory of their project, the framework was not detected and remappings / solc version were silently dropped.

This walks up the directory tree from the working directory and accepts the first ancestor that matches a non-Solc platform, then passes that directory to platform.config(...) so the framework is queried at its actual root.

Foundry already traverses upwards inside Foundry.locate_project_root, so it was unaffected. Hardhat/Truffle/Dapp/Brownie/Waffle/Embark/Buidler/Etherlime only check the literal path they're given — those are the cases this change actually fixes.

Changes

  • Extract the detection into a _locate_framework_root helper that walks up from the working directory.
  • Use the directory where the platform was detected (not the original working directory) when calling platform.config(...), so framework-specific subprocesses (e.g. forge config --json) run at the project root.

Tests

Added tests/test_locate_framework_root.py covering:

  • Hardhat detection from a nested subdirectory
  • Foundry detection at the project root
  • (None, None) when no framework is present up to /
  • hardhat_ignore kwarg disables detection

Pre-existing tests/test_library_linking.py and tests/test_sourcify_proxy.py failures on my machine are unrelated (solc binary architecture mismatch in solc-select) and reproduce on master.

When the target is a single Solidity file, search the ancestors of the
working directory for a Foundry/Hardhat/Truffle/... project instead of
only the working directory itself. This allows remappings and the
expected solc version to be picked up when crytic-compile is invoked
from a subdirectory of a project.

Closes crytic#538
@cats2101
Copy link
Copy Markdown
Author

cats2101 commented May 1, 2026

Gentle ping — anything else needed here?

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.

traverse file tree to discover config file

1 participant