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

Selective compilation of certain Solidity files via foundry.toml #6099

Closed
Vectorized opened this issue Oct 24, 2023 · 2 comments · Fixed by #8668
Closed

Selective compilation of certain Solidity files via foundry.toml #6099

Vectorized opened this issue Oct 24, 2023 · 2 comments · Fixed by #8668
Labels
A-compiler Area: compiler A-config Area: config P-normal Priority: normal T-feature Type: feature
Milestone

Comments

@Vectorized
Copy link

Vectorized commented Oct 24, 2023

Component

Forge

Describe the feature you would like

Suppose I want to include 2 different ReentracyGuard files in Solady.

  • ReentrancyGuard.sol (uses regular old sstore).
  • ReentrancyGuard.cancun.sol (uses the tstore opcode probably available in solc 0.8.23 in the future).

Compilation will throw an error when using "solc_version" < "0.8.23" or "evm_version" < "cancun".

Suggestion

Suppose Solady's foundry.toml has:

[profile.default]
solc_version = "0.8.21"
evm_version = "paris" # Shanghai will be tested in the CI.
auto_detect_solc = false
optimizer = true
optimizer_runs = 1_000
gas_limit = 100_000_000 # ETH is 30M, but we use a higher value.
remappings = [
  "forge-std=test/utils/forge-std/"
]
selective_compile = [
  { path = "./**/*.cancun.sol", min_solc_version = "0.8.23", min_evm_version = "cancun" }
]

Ideally any library that installs Solady via forge must be able to compile with solc >= 0.8.4 (minimum supported version by Solady).

But if their foundry.toml specifies "solc_version" = "0.0.23" and "evm_version" = "cancun", they will be able to include and compile ReentrancyGuard.cancun.sol.

A project that targets many EVM chains (e.g. for canonical create2 deployments with vanity addresses) would use "solc_version" = "0.0.23" (or any other version that supports paris) and "evm_version" = "paris". They will include the traditional ReentrancyGuard.sol in files.

A project that only targets Ethereum mainnet would use "solc_version" = "0.0.23" and "evm_version" = "cancun". They will include ReentrancyGuard.cancun.sol in files instead.

Why?

I mean... we cannot expect L2s (and Solidity) to be shipping as fast and hardcore as the Foundry team.

PUSH0 was a good test of what's to come.

Additional context

No response

@Vectorized Vectorized added the T-feature Type: feature label Oct 24, 2023
@gakonst gakonst added this to Foundry Oct 24, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Oct 24, 2023
@Vectorized Vectorized changed the title Allow skipping compilation of certain Solidity files via foundry.toml Selective compilation of certain Solidity files via foundry.toml Oct 24, 2023
@mattsse
Copy link
Member

mattsse commented Oct 24, 2023

yeah, we kind of want this in one form or another.

I think this is some form of configuration conditional where a library can allow/disallow certain files based on the configured version

all of this needs to be solved during preprocessing, independently from solc.

I can see how this will become important with new cancun opcodes and already is problematic with push0...

Because this depends on the file itself, I can imagine this could be solved with some natspec custom modifier and via the config like you suggested.

I think it's most important to prevent compilation if evm version is invalid.
but I wonder if the ideal DX would be something like, "if cancun use cancun.sol variant of that file, if < cancun use this file"

but this is likely a niche feature only for certain libraries like solady and should probably be solved via a package manager solution instead.

But adding rules into the config would be possible and we should start with that.

@zerosnacks
Copy link
Member

Related: #5715

@zerosnacks zerosnacks changed the title Selective compilation of certain Solidity files via foundry.toml Selective compilation of certain Solidity files via foundry.toml Jul 4, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy grandizzy added the P-normal Priority: normal label Nov 12, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiler Area: compiler A-config Area: config P-normal Priority: normal T-feature Type: feature
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants