Skip to content

etherscan verification failure (when remapping points to external file) #5307

@adhusson

Description

@adhusson

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (bf56869 2023-07-05T00:05:02.811991000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

If you use files that are outside the project through a remapping (like@remapped/=../remapped/), and a file there does a relative import, then verification fails.

Reproduction

  1. forge init bad_verif,

  2. Add this to the initial bad_verif/foundry.ml:

remappings = ["@remapped/=../remapped/"]
allow_paths = ["../remapped/"]
  1. Create remapped/ so that you have
.
├── remapped
├── bad_verif
  1. In remapped/, create Parent.sol:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "./Child.sol";

and Child.sol:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
  1. In Counter.sol, add:
import "@remapped/Parent.sol";
  1. Deploy with --broadcast --verify

Expected

Verification works.

Actual

If you deploy and verify, you will get the following error (I tried on polygon):

Fail - Unable to verify. Solidity Compilation Error: Source "../remapped/Child.sol" not found: File not found. Searched the following locations: "".

This is because the input json contains the following:

{
   "sources":{
      "src/Counter.sol": <content of Counter.sol>
      "../remapped/Parent.sol":{
         "content":"// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.13;\nimport \"./Child.sol\";\n"
      },
      "/Users/ah/temp/remapped/Child.sol": <content of Child.sol>
   },
   "settings":{
      "remappings":[
         "@remapped/=../remapped/"
      ],
   }
}

Suggestion

The key for Child.sol should probably use the relative path ../remapped/Child.sol instead of the absolute path /Users/ah/temp/remapped/Child.sol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions