foundry: Not being able to compile because of "Discovered incompatible solidity versions in following"

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

0.2.0

What command(s) is the bug in?

forge build

Operating System

macOS (amd)

Describe the bug

I’m migrating https://www.damnvulnerabledefi.xyz/ v2 to forge as both a CTF exercise and a learning exercise (for Forge).

I’m attempting to migrate the Puppet-v2 challenge and when I attempt to build the code I get this error:

[⠃] Compiling...2022-04-01T06:28:20.723718Z ERROR ethers_solc::resolver: failed to resolve versions
[⠊] Compiling...
Error: 
   0: Discovered incompatible solidity versions in following
      : src/test/puppet-v2/PuppetV2Test.t.sol (^0.6.0) imports:
          lib/forge-std/src/stdlib.sol (>=0.6.0 <0.9.0)
          src/test/utils/Utilities.sol (>=0.8.0)
          src/test/BaseTest.sol (0.8.10)
          src/DamnValuableToken.sol (^0.8.0)
          lib/forge-std/src/Vm.sol (>=0.6.0)
          lib/ds-test/src/test.sol (>=0.4.23)
          lib/forge-std/src/Vm.sol (>=0.6.0)
          lib/ds-test/src/test.sol (>=0.4.23)
          lib/forge-std/src/Vm.sol (>=0.6.0)
          lib/forge-std/src/console.sol (>=0.4.22 <0.9.0)
          src/test/utils/Utilities.sol (>=0.8.0)
          lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol (^0.8.0)
          lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol (^0.8.0)
          lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol (^0.8.0)
          lib/openzeppelin-contracts/contracts/utils/Context.sol (^0.8.0)
          lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol (^0.8.0)

If you want to reproduce this clone the puppet-v2 branch from my repo and just hit forge build.

This specific challenge involves a mix of external contracts like WETH9 + Uniswap v2 core + Uniswap v2 periphery.

The testing file that will break everything is PuppetV2Test.t.sol

I’ve already moved WETH9 from being a solidity contract (in the original CTF) to be an artifact deployed using deployCode but as soon you uncomment this line

import "../../puppet-v2/PuppetV2Pool.sol";

and attempt to build, you will see the above error.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

your source file is incompatible with its imports src/test/puppet-v2/PuppetV2Test.t.sol (^0.6.0) is only compatible with 0.6 while this src/test/utils/Utilities.sol (>=0.8.0) requires at least 0.8.0 so there’s no solc version that’s compatible

upgrading src/test/puppet-v2/PuppetV2Test.t.sol to 0.8.0 should fix it though

src/test/puppet-v2/PuppetV2Test.t.sol is using pragma solidity 0.8.10; not ^0.6.0

src/puppet-v2/PuppetV2Pool.sol is using pragma solidity ^0.6.0;. If the Pool is the problem, I’m afraid that I cannot change that. That is part of the CTF, so I would say that there’s a specific reason why Tincho made the contract use solc <0.8 but I need to solve the CTF before saying so.

The question would be: is fixable on foundry side? Or should I fix it on my side? If we’re on the second option, do you have any suggestions?

these are semver incompatible

 lib/forge-std/src/Test.sol (>=0.6.0 <0.9.0)
          contracts/UniswapV2Pair.sol (=0.5.16)

It would be good to specify an array of solc versions i think tho. I don’t feel comfortable removing the pinning and just relying on auto-detection. Being explicit is always better so if it was possible to do this i would:

# foundry.toml
[default]
solc_version = ["0.8.13", "0.7.6"]

[ci]
fuzz-runs = 10_000

You cannot import a contract with an incompatible Solidity version in another contract! The ‘right’ way to do this, is via deployCode, e.g. see here.

pinning gives an error still. But I found a workaround… or well… the design of foundry is so good that i guess it’s already possible like this:

// MockUniswapV3Factory.sol
pragma solidity 0.7.6;
import "v3-core/UniswapV3Factory.sol";
// Fixture.sol
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "v3-core/interfaces/IUniswapV3Factory.sol";

abstract contract Fixture is Test {
    IUniswapV3Factory internal uniswapV3Factory;

    constructor() {
        uniswapV3Factory = IUniswapV3Factory(deployCode("UniswapV3Factory.sol"));
    }
}
# foundry.toml
[default]
# remove pinning
# solc_version = "0.8.13"

[ci]
fuzz-runs = 10_000

Remove explicit solc version pinning in foundry.toml and then when doing forge build it will auto use the correct compiler version for each contract thanks to this

Including the mock file is necessary I think so that an artifact for “UniswapV3Factory.sol” is built

then

forge test

everything seems to work. Haven’t actually tested this yet tried to interact with the uni contract lol - but the deploy looks like it works