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

bug: forge coverage --ir-minimum compilation fails with Error: Unknown key "inliner (solc < 0.8.5) #9322

Open
2 tasks
anajuliabit opened this issue Nov 14, 2024 · 9 comments · May be fixed by #9341
Open
2 tasks
Assignees
Labels
C-forge Command: forge Cmd-forge-coverage Command: forge coverage T-bug Type: bug

Comments

@anajuliabit
Copy link

anajuliabit commented Nov 14, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (25f24e6 2024-09-30T00:22:05.952969000Z)

What command(s) is the bug in?

forge coverage

Operating System

macOS (Apple Silicon)

Describe the bug

λ forge coverage --ir-minimum --skip test --skip script
Warning! "--ir-minimum" flag enables viaIR with minimum optimization, which can result in inaccurate source mappings.
Only use this flag as a workaround if you are experiencing "stack too deep" errors.
Note that "viaIR" is only available in Solidity 0.8.13 and above.
See more: https://github.com/foundry-rs/foundry/issues/3357
[⠊] Compiling...
[⠒] Compiling 311 files with Solc 0.8.19
[⠢] Compiling 43 files with Solc 0.6.12
[⠆] Compiling 12 files with Solc 0.8.10
[⠰] Solc 0.8.10 finished in 969.96ms
[⠔] Solc 0.6.12 finished in 614.18s
[⠒] Solc 0.8.19 finished in 614.78s
Error: 
Compiler run failed:
Error: Unknown key "inliner

I suspect that the foundry or some dependency is setting the inliner configuration for the compiler under the hood

foundry.toml:

[profile.default]
src = 'src'
out = 'artifacts/foundry'
libs = ['node_modules', 'lib']
test = 'test'
cache_path  = 'artifacts/forge-cache'
fs_permissions = [{ access = "read", path = "./"}]
auto_detect_solc = true
evm_version = 'shanghai' # lock to shanghai to use push0 opcode which is live on base, optimism and Moonbeam
optimizer_runs = 1
rpc_storage_caching = { chains = "all", endpoints = "all" }
ignored_warnings_from = ["src/MErc20Delegator.sol", "src/tokensale/TokenSaleDistributorProxy.sol"]
gas_limit = "18446744073709551615" # u64::MAX
block_gas_limit = "18446744073709551615"
@anajuliabit anajuliabit added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Nov 14, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Nov 14, 2024
@grandizzy
Copy link
Collaborator

@anajuliabit is there any optimizer_details section in toml file? could you share a way to reproduce this failure? thank you!

@anajuliabit
Copy link
Author

@grandizzy there is not, you can check here https://github.com/moonwell-fi/moonwell-contracts-v2/blob/main/foundry.toml

to reproduce:

clone https://github.com/moonwell-fi/moonwell-contracts-v2 then run

forge coverage --ir-minimum

@grandizzy
Copy link
Collaborator

I am getting a seg fault on solc, so probably not too much we can do here, maybe you can reorg contracts to avoid such...

See more: https://github.com/foundry-rs/foundry/issues/3357
[⠰] Compiling...
[⠔] Compiling 428 files with Solc 0.8.19
[⠒] Compiling 43 files with Solc 0.6.12
[⠑] Compiling 12 files with Solc 0.8.10
[⠘] Solc 0.6.12 finished in 16.31ms
[⠒] Solc 0.8.10 finished in 1.03s
Error: solc exited with signal: 11 (SIGSEGV) (core dumped)
<empty output>

@zerosnacks
Copy link
Member

Also running into the same

Error: solc exited with signal: 11 (SIGSEGV) (core dumped)
<empty output>

@anajuliabit would you mind reporting this crash over at https://github.com/ethereum/solidity?

If possible please provide an alternative minimal reproduction in the meantime

For future reference: https://github.com/foundry-rs/compilers/blob/034ecd611eef030217c4b363a794226cd50b4b9e/crates/artifacts/solc/src/lib.rs#L713-L714

@anajuliabit
Copy link
Author

@zerosnacks

┌─[anajulia@MacBook]──[09:32]──[/Users/anajulia/code/work/moonwell-contracts-v2]
└─>:D:origin*? λ forge --version
forge 0.2.0 (31c24b0 2024-11-14T00:20:56.222819000Z)
┌─[anajulia@MacBook]──[09:32]──[/Users/anajulia/code/work/moonwell-contracts-v2]
└─>:D:origin*? λ solc --version
solc, the solidity compiler commandline interface
Version: 0.8.19+commit.7dd6d404.Darwin.appleclang
┌─[anajulia@MacBook]──[09:32]──[/Users/anajulia/code/work/moonwell-contracts-v2]
└─>:D:origin*? λ forge coverage --ir-minimum --skip test --skip script --out artifacts/coverage
Warning: Warning! "--ir-minimum" flag enables viaIR with minimum optimization, which can result in inaccurate source mappings.
Only use this flag as a workaround if you are experiencing "stack too deep" errors.
Note that "viaIR" is only available in Solidity 0.8.13 and above.
See more: https://github.com/foundry-rs/foundry/issues/3357
[⠊] Compiling...
[⠒] Compiling 252 files with Solc 0.8.19
[⠢] Compiling 12 files with Solc 0.8.10
[⠰] Compiling 18 files with Solc 0.6.12
[⠒] Solc 0.6.12 finished in 55.29ms
[⠔] Solc 0.8.10 finished in 1.17s
[⠘] Solc 0.8.19 finished in 71.35s
Error: Compiler run failed:
Error: Unknown key "inliner
```

@grandizzy
Copy link
Collaborator

yeah, I get the same Error: Unknown key "inliner with this command (forge coverage --ir-minimum --skip test --skip script --out artifacts/coverage), the prev one you mentioned forge coverage --ir-minimum results in Error: solc exited with signal: 11 (SIGSEGV) (core dumped)

@zerosnacks zerosnacks changed the title forge coverage --ir-minimum compilation fails with Error: Unknown key "inliner bug: forge coverage --ir-minimum compilation fails with Error: Unknown key "inliner Nov 15, 2024
@zerosnacks zerosnacks added C-forge Command: forge Cmd-forge-coverage Command: forge coverage and removed T-needs-triage Type: this issue needs to be labelled labels Nov 15, 2024
@grandizzy
Copy link
Collaborator

grandizzy commented Nov 16, 2024

issue can be reproduce with any contract using solc <= 0.8.4, starting with 0.8.5 the following bug was addressed
Standard JSON: Properly allow the inliner setting under settings.optimizer.details. hence coverage works OK (see https://soliditylang.org/blog/2021/06/10/solidity-0.8.5-release-announcement/)

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.4;

contract AnotherCounter {
    
    function isContract(address account) internal view returns (bool) {
        bytes32 codehash;
        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
        assembly {
            codehash := extcodehash(account)
        }
        return (codehash != accountHash && codehash != 0x0);
    }
}

In compilers we're setting inliner to Some(false), which fails for versions <= 0.8.4 https://github.com/foundry-rs/compilers/blob/b5c2a49df8d271a9d0d3f851fc4f0023c1e29c9e/crates/artifacts/solc/src/lib.rs#L468-L471
Probably should be set to None.

master...grandizzy:issue-9322

@grandizzy grandizzy changed the title bug: forge coverage --ir-minimum compilation fails with Error: Unknown key "inliner bug: forge coverage --ir-minimum compilation fails with Error: Unknown key "inliner (solc < 0.8.5) Nov 16, 2024
klkvr pushed a commit to foundry-rs/compilers that referenced this issue Nov 18, 2024
Ref
foundry-rs/foundry#9322 (comment)

ethereum/solidity#15576 (comment)

Set inliner to None since it is properly supported from 0.8.5 version(
see `Standard JSON: Properly allow the inliner setting under
settings.optimizer.details`
https://soliditylang.org/blog/2021/06/10/solidity-0.8.5-release-announcement/)

---------

Co-authored-by: DaniPopes <[email protected]>
@grandizzy
Copy link
Collaborator

grandizzy commented Nov 18, 2024

not sure if we should take any action here though the message error could be misleading. viaIR with minimum optimization is only available in Solidity 0.8.13 and above and we exit with err message if so, but only if version is auto detected

// TODO: How to detect solc version if the user does not specify a solc version in
// config case1: specify local installed solc ?
// case2: multiple solc versions used and auto_detect_solc == true
if let Some(SolcReq::Version(version)) = &config.solc {
if *version < Version::new(0, 8, 13) {
return Err(eyre::eyre!(
"viaIR with minimum optimization is only available in Solidity 0.8.13 and above."
));
}
}

If we cannot detect version then coverage continues and for versions < 0.8.5 compilation fails with Error: Unknown key "inliner. Could sanitize settings to 0.8.4 if version cannot be detected but not sure a good idea, @zerosnacks @DaniPopes any thoughts on this? thanks

@zerosnacks
Copy link
Member

zerosnacks commented Nov 18, 2024

Solady uses ^0.8.4 but for the vast majority of users ^0.8.13 is where via-ir was marked as production ready and became usable as it prevents the majority of stack-to-deep errors.

I think it would make sense to sanitize as suggested given the scope is limited to forge coverage.

I don't think there is anything inherently limiting this to ^0.8.13 (excluding some settings) given the--ir-minimum profile is something defined by us, not passed through to solc:

https://github.com/foundry-rs/compilers/blob/2db27d74ef5739da47ccf88ab3146b94462d3810/crates/artifacts/solc/src/lib.rs#L463-L491

@grandizzy grandizzy self-assigned this Nov 18, 2024
@grandizzy grandizzy moved this from Todo to In Progress in Foundry Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-coverage Command: forge coverage T-bug Type: bug
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants