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

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

Open
heyskylark opened this issue Apr 22, 2024 · 0 comments
Milestone

Comments

@heyskylark
Copy link

heyskylark commented Apr 22, 2024

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)

  • src/Test.sol
  • lib/PBT/src/PBTSimple.sol
  • lib/PBT/lib/openzeppelin-contracts/contracts/access/Ownable.sol
  • lib/PBT/lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol
  • etc

Verify source paths (standard_json_input)

  • src/Test.sol
  • lib/PBT/src/PBTSimple.sol
  • lib/openzeppelin-contracts/contracts/access/Ownable.sol
  • lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol
  • etc

Minimal steps to reproduce

  • Create a new project forge init
  • Install dependencies
  • Create a simple contract: Test.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

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:
forge verify-contract \
--verifier etherscan --show-standard-json-input \
--constructor-args $(cast abi-encode "constructor(string,string)" "Test" "Test") \
0x000000000000000000000000000000000000dEaD src/Test.sol:Test
  • Verify that source paths are different between build (compile) artifacts and verify (standard_json_input) artifacts

Versions & Other details

  • forge 0.2.0 (63fff3510 2024-04-21T21:59:02.827682000Z)
  • OSX Sonoma 14.0 - M2 Mac
  • I would love to take a crack at fixing this myself and opening a PR, but I wanted to start a conversation beforehand to check in on if this outcome is expected for any reason.
@zerosnacks zerosnacks added this to the v1.0.0 milestone Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants