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-Candidate]: Slither calls solc with non-existant option "--evm-version" #2422

Open
izcoser opened this issue Apr 11, 2024 · 2 comments
Open
Labels
bug-candidate Bugs reports that are not yet confirmed

Comments

@izcoser
Copy link

izcoser commented Apr 11, 2024

Describe the issue:

This issue happens when we have a foundry.toml in the current working directory. Slither detects foundry and tries to pass its configurations to solc.

One config is evm_version which defaults to "paris", however the --evm-version option does not exist in old versions of solc (such as 0.4.18), so solc breaks.

Code example to reproduce the issue:

pragma solidity ^0.4.18;

contract WETH9 {
    string public name     = "Wrapped Ether";
    string public symbol   = "WETH";
    uint8  public decimals = 18;

    event  Approval(address indexed src, address indexed guy, uint wad);
    event  Transfer(address indexed src, address indexed dst, uint wad);
    event  Deposit(address indexed dst, uint wad);
    event  Withdrawal(address indexed src, uint wad);

    mapping (address => uint)                       public  balanceOf;
    mapping (address => mapping (address => uint))  public  allowance;

    function() public payable {
        deposit();
    }
    function deposit() public payable {
        balanceOf[msg.sender] += msg.value;
        Deposit(msg.sender, msg.value);
    }
    function withdraw(uint wad) public {
        require(balanceOf[msg.sender] >= wad);
        balanceOf[msg.sender] -= wad;
        msg.sender.transfer(wad);
        Withdrawal(msg.sender, wad);
    }

    function totalSupply() public view returns (uint) {
        return this.balance;
    }

    function approve(address guy, uint wad) public returns (bool) {
        allowance[msg.sender][guy] = wad;
        Approval(msg.sender, guy, wad);
        return true;
    }

    function transfer(address dst, uint wad) public returns (bool) {
        return transferFrom(msg.sender, dst, wad);
    }

    function transferFrom(address src, address dst, uint wad)
        public
        returns (bool)
    {
        require(balanceOf[src] >= wad);

        if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
            require(allowance[src][msg.sender] >= wad);
            allowance[src][msg.sender] -= wad;
        }

        balanceOf[src] -= wad;
        balanceOf[dst] += wad;

        Transfer(src, dst, wad);

        return true;
    }
}

Just put the above code in a foundry project, with a simple foundry.toml:

[profile.default]
src = "src"
out = "out"
libs = ["lib"]

And try to run slither from the same directory, making Slither detect foundry.

slither /home/user/default/src/WETH9.sol --disable-color --json /home/user/default/src/WETH9.json --solc-solcs-select 0.4.18

Version:

0.10.2

Relevant log output:

slither /home/user/default/src/WETH9.sol --disable-color --json /home/user/default/src/WETH9.json --solc-solcs-select 0.4.18

'forge config --json' running
Could not detect solc version from Foundry config. Falling back to system version...
'solc --version' running
'solc ds-test/=lib/forge-std/lib/ds-test/src/ forge-std/=lib/forge-std/src/ /home/user/default/src/WETH9.sol --combined-json abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc,hashes,compact-format --optimize --optimize-runs 200 --evm-version paris --allow-paths .,/home/user/default/src' running
Compilation warnings/errors on /home/user/default/src/WETH9.sol:
unrecognised option '--evm-version'
@izcoser izcoser added the bug-candidate Bugs reports that are not yet confirmed label Apr 11, 2024
@izcoser
Copy link
Author

izcoser commented Apr 14, 2024

Found a way around it after digging a little bit.
If I first compile with Foundry and then run:

slither src/WETH9.sol --foundry-ignore-compile --compile-force-framework "Foundry" --foundry-out-directory "absoluteOutPath"

It works. But it's absolutely a bug.

@elopez
Copy link
Member

elopez commented Apr 14, 2024

Hi! This is a known foundry bug, being tracked upstream here foundry-rs/foundry#7014

slither / crytic-compile query foundry config --json to learn information such as the the EVM version, but foundry sometimes reports "paris" when it shouldn't. You should be able to work around the problem by setting an explicit evm_version in your foundry.toml

Also related: #2287

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-candidate Bugs reports that are not yet confirmed
Projects
None yet
Development

No branches or pull requests

2 participants