Tenderly / hardhat-tenderly

Tenderly plugin for HardHat
https://www.npmjs.com/package/@tenderly/hardhat-tenderly
Other
154 stars 40 forks source link

Unable to verify a contract that imports OpenZeppelin #139

Closed pegahcarter closed 1 year ago

pegahcarter commented 1 year ago

I'm running a simple script script/deploy.ts which deploys a very minimal ERC20 contract:

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract SinkDrain is ERC20 {
    constructor() ERC20("My Token", "TKN") {
        _mint(msg.sender, 1e18);
    }
}

I'm authenticated with tenderly CLI and here is my hardhat config:

import * as dotenv from "dotenv";
import * as tdly from "@tenderly/hardhat-tenderly";
import "@nomicfoundation/hardhat-toolbox";
import "@nomicfoundation/hardhat-foundry";

dotenv.config();
tdly.setup({ automaticVerifications: true });

export default {
    defaultNetwork: "tenderly",
    networks: {
        hardhat: {
        },
        tenderly: {
            url: `https://rpc.tenderly.co/fork/${process.env.FORK_ID}`,
            accounts: [`${process.env.PRIVATE_KEY_DEPLOY}`]
        }
    },
    solidity: {
        version: "0.8.13",
        settings: {
            optimizer: {
                enabled: true,
                runs: 200
            }
        }
    },
    tenderly: {
        username: process.env.TENDERLY_USERNAME,
        project: process.env.TENDERLY_PROJECT,
        privateVerification: false
    },
    paths: {
        sources: "./contracts",
        tests: "./test",
        cache: "./cache",
        artifacts: "./artifacts"
    },
    typechain: {
        outDir: "artifacts/types",
        target: "ethers-v5"
    }
};

When I run npx hardhat run script/deploy.ts --network tenderly I get the following error:

2023-04-17 18:58:46.648 ERROR Service =>There have been compilation errors while verifying contracts. [
  {
    source_location: {
      file: 'contracts/Deploy.sol',
      start: '70',
      end: '138'
    },
    error_type: 'ParserError',
    component: 'general',
    message: 'Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File not found. Searched the following locations: "".',
    formatted_message: undefined
  },

What am I missing to make this automatic verification work?

SolcAndMe commented 1 year ago

Encountering the same issue with a foundry based setup where the dependencies are under lib/. I've installed hardhat-foundry as well. I'm not sure if hardhat-tenderly uses hardhats ability to derive the correct contract dependency path or if it implements it by itself. Either way it does not account for remappings. For contracts without dependencies it works fine. Without any custom workarounds currently it's not possible to use this plugin in a foundry + hardhat setup.

dule-git commented 1 year ago

Hello 👋🏽

The resolving of dependencies is offloaded to hardhat. That is, we are asking hardhat to do the compilation and resolving of dependencies making the request to our backend server.

It seems that hardhat didn't resolve the dependencies right, thus all of the sources needed for compilation are not sent to the backend server which then reports the compilation error.

I can't pinpoint the problem since I am not able to reproduce it, that is, I am successfully managing to verify the contract you provided on my fork.

Some of the questions I can ask in order to debug the problem are:

SolcAndMe commented 1 year ago

I've created this POC. https://github.com/BarnBridge/tenderly-poc. I would expect it to work if hardhat-foundry is installed.

dule-git commented 1 year ago

Resolved. We named remappings parameter in compiler configuration remapping. So when the client was sending remappings parameter to our backend server, the server couldn't resolve it.

This caused the compiler to fail to find the sources it needed to compile the contract for verification.

The new version is deployed now and the PoC should work as expected.