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

Compile a subdirectory #8071

Closed
aviggiano opened this issue Jun 5, 2024 · 1 comment · Fixed by #8149
Closed

Compile a subdirectory #8071

aviggiano opened this issue Jun 5, 2024 · 1 comment · Fixed by #8149
Labels
T-feature Type: feature

Comments

@aviggiano
Copy link

aviggiano commented Jun 5, 2024

Component

Forge

Describe the feature you would like

While working invariant testing projects with Echidna/Medusa, I often encounter a compilation issue related to Foundry's default project structure.

By default, Echidna/Medusa uses crytic-compile to compile a project using Foundry if . is passed as the target. This results in a forge build --build-info --skip */test/** */script/** --force command.

The problem is that this makes it impossible to host invariant tests under test/invariants and compile them using Foundry. The only alternative is to pass --foundry-compile-all to crytic-compile, which will then fall back to a forge build --build-info command. However, this will compile ALL Solidity files, which is also undesired, since in most cases the majority of files are unit and fuzz test files.

This results in a significant slowdown of the invariant testing process, and forces security researchers to either move invariant tests to src/, which is semantically incorrect, or to compile everything and waste time.

This feature request suggests introducing a configuration parameter in Foundry that allows specifying a subdirectory for compilation. This can be achieved by extending the forge build command with an option to compile only the specified subdirectory, such as forge build --dir test/invariants. This way, we could either update crytic-compile or simply pass --ignore-compile to these tools, relying on Foundry's subdirectory compilation.

Additional context

No response

@aviggiano aviggiano added the T-feature Type: feature label Jun 5, 2024
@0xalpharush
Copy link
Contributor

0xalpharush commented Jun 5, 2024

Happy to coordinate on how best to update this as the binary of --foundry-compile-all probably isn't the best solution for fuzzers despite working well for Slither. For background, the reason we force a clean and recompile by default in crytic-compile is the caching logic in Foundry is not robust yet, resulting in strange failures that are really hard to troubleshoot

It seems caching was disabled recently if build info is requested which would present a problem trying to workaround this with --ignore-compile (see #7379). We had a really rough time initially trying to use Foundry's native cache (e.g. gakonst/ethers-rs#1995) and the build info was much more stable since it was based off Hardhat's artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants