#17051·solidity

Sorted remappings in metadata can select a different file than the one compiled

Author: nikola-maticCreated Sep 29, 2026Updated Sep 30, 2026
Labelsbug :bug:

Description

Contract metadata records import remappings sorted and deduplicated (CompilerStack::createMetadata puts them in a std::set). Remapping resolution depends on order, so when two remappings have the same context and prefix, the one specified last is selected. If the remapping given last doesn't also sort last, the metadata resolves the import to a different file than the one the compiler actually used. Recompiling from the metadata then fails. It stops with ParserError: Source not found or produces different bytecode.

Expected: metadata remappings resolve imports the same way the compiler did. Either keep the input order, or drop remappings that a later one with the same context and prefix overrides before sorting.

Environment

  • Compiler version: 0.8.37 and develop (reproduces back to 0.4.24)
  • Compilation pipeline (legacy, IR, SSA CFG): all (pipeline-independent)
  • Target EVM version (as per compiler settings): any
  • Framework/IDE (e.g. Foundry, Hardhat, Remix): none (solc CLI / Standard JSON)
  • EVM execution environment / backend / blockchain client: N/A
  • Operating system: any (reproduced on Linux and macOS)

Steps to Reproduce

Main.sol:

solidity
pragma solidity *;
import {Config} from "cfg/Config.sol";
contract Main { function value() external pure returns (uint) { return Config.value(); } }

v1/Config.sol:
solidity
pragma solidity *;
library Config { function value() internal pure returns (uint) { return 1; } }

v2/Config.sol:
solidity
pragma solidity *;
library Config { function value() internal pure returns (uint) { return 2; } }

solc cfg/=v2/ cfg/=v1/ Main.sol --metadata

The compiler resolves cfg/Config.sol to v1/Config.sol, and the metadata lists v1/Config.sol in sources. However, settings.remappings is [":cfg/=v1/", ":cfg/=v2/"], which resolves to v2/Config.sol under the last-wins rule. Compiling the metadata's sources with its recorded settings fails with ParserError: Source "v2/Config.sol" not found.

Original report