matter-labs / hardhat-zksync

Apache License 2.0
282 stars 225 forks source link

Issue with Verifying Solidity Libraries on zkSync #516

Open mshakeg opened 8 months ago

mshakeg commented 8 months ago

Description

I am encountering an issue when attempting to verify a Solidity library on the zkSync network using the @matterlabs/hardhat-zksync plugin. While I was able to deploy a Solidity library (MathLib) successfully, the verification process fails with an error indicating a bytecode mismatch. This issue seems specific to the verification of Solidity libraries, as I was able to verify a regular contract (Greeter) without any problems.

Steps to Reproduce

  1. You can either:
  2. Create a Solidity library (MathLib.sol) and a dependent contract (Calculator.sol).

MathLib:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library MathLib {
    function add(uint a, uint b) external pure returns (uint) {
        return a + b;
    }
}

Calculator:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./MathLib.sol";

contract Calculator {
    function addNumbers(uint a, uint b) public view returns (uint) {
        return MathLib.add(a, b);
    }
}
  1. Deploy the MathLib library to the zkSync network: yarn hardhat deploy-zksync:libraries --private-key <private-key>
  2. Attempt to verify the MathLib library: yarn hardhat verify <MathLib address> --contract contracts/MathLib.sol:MathLib. My library was deployed to 0xE6f95768D5BADC7561EC7Fb6BCE2459F0fF69CDc
  3. Observe the following error:
Error in plugin @matterlabs/hardhat-zksync-verify: The address provided as argument contains a contract, but its bytecode doesn't match any of your local contracts.

      Possible causes are:
        - Contract code changed after the deployment was executed. This includes code for seemingly unrelated contracts.
        - A solidity file was added, moved, deleted or renamed after the deployment was executed. This includes files for seemingly unrelated contracts.
        - Solidity compiler settings were modified after the deployment was executed (like the optimizer, target EVM, etc.).
        - The given address is wrong.
        - The selected network is wrong.
mshakeg commented 8 months ago

The Greeter contract was verified automatically as part of the deployment process, it would be great if libraries were also verified automatically as part of yarn hardhat deploy-zksync:libraries

nikola-bozin-txfusion commented 7 months ago

Thanks for the information. We are aware of this issue and we are working together with the backend verification team to resolve it. As for the automatically verifying libraries as part of yarn hardhat deploy-zksync:libraries, that would mean that our deploy plugin needs to depend on verify plugin, and we don't want that because this would introduce unnecessary dependencies between those plugins.