foundry-rs / compilers

Utilities for working with native solc and compiling projects.
Apache License 2.0
58 stars 36 forks source link

Compiler source mapping differences between forge build and forge verify-contract causing verification to fail #112

Open heyskylark opened 2 months ago

heyskylark commented 2 months ago

Hello,

I think I have found a bug in the way the compiler maps sources. The sources in the artifact produced by the build are different than the source paths in the verify json output. I noticed this issue when trying to verify an existing smart contract. I figured out that the reason that the verification was failing was because the standard_json_input compilation was using a different source which was a slightly different version of openzeppelin-contracts. It appears that it was using a version of openzeppelin-contracts that was within another dependency instead of the openzeppelin-contracts that existed in the root of the lib directory.

Source Pathing Example

Build source paths (compile)

Verify source paths (standard_json_input)

Minimal steps to reproduce

import "@chiru-labs/pbt/PBTSimple.sol"; import "@openzeppelin/contracts/access/Ownable.sol";

contract Test is PBTSimple, Ownable { uint256 public number;

function setNumber(uint256 newNumber) public {
    number = newNumber;
}

function increment() public {
    number++;
}

}

- Create remappings.txt in the root directory

@chiru-labs/pbt=lib/PBT/src @openzeppelin=lib/openzeppelin-contracts

- Create build artifacts: `forge build`
- Create verification json:
```bash
forge verify-contract \
--verifier etherscan --show-standard-json-input \
--constructor-args $(cast abi-encode "constructor(string,string)" "Test" "Test") \
0x000000000000000000000000000000000000dEaD src/Test.sol:Test

Versions & Other details