matter-labs / hardhat-zksync

Apache License 2.0
282 stars 227 forks source link

Issue with Verifying Contracts on zkSync When Deployed via External Library #519

Open mshakeg opened 9 months ago

mshakeg commented 9 months ago

🐛 Bug Report for hardhat-zksync plugins

💥 Plugin name

@matterlabs/hardhat-zksync-verify@^0.2.1

📝 Description

I am experiencing a problem verifying contracts on the zkSync network when they are deployed through an external library. Specifically, the issue arises when a factory contract uses a library to deploy a child contract, instead of deploying it directly. This setup seems to cause verification failures despite following standard verification procedures.

🔄 Reproduction Steps

  1. Setup: I have set up a Hardhat zksync project using the zksync-cli template containing the contracts in question: a factory contract (DeployerFactory2WithConstructorAndLibrary), a deployment library (ChildDeployer), and a child contract (ChildWithConstructorAndLibrary).

  2. Deployment: The DeployerFactory2WithConstructorAndLibrary contract uses the ChildDeployer library to deploy instances of ChildWithConstructorAndLibrary using the CREATE2 opcode for deterministic address generation.

  3. Verification Attempt: After deploying the ChildWithConstructorAndLibrary contract using the factory and library, I attempted to verify it on zkSync using Hardhat's verification command with the appropriate constructor arguments in arguments.js

yarn hardhat verify <ChildWithConstructorAndLibrary> --contract contracts/ChildWithConstructorAndLibrary.sol:ChildWithConstructorAndLibrary --constructor-args arguments.js
  1. Failure: The verification process fails with 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.

🤔 Expected Behavior

The ChildWithConstructorAndLibrary contract, deployed via the factory and library, should be verifiable on the zkSync network using standard verification procedures.

😯 Current Behavior

Verification fails, indicating a mismatch in bytecode or other related issues, despite the deployment process completing successfully.

NOTE: I have been able to verify child contracts created in numerous other ways by a factory contract as outlined here

🖥️ Environment

nikola-bozin-txfusion commented 9 months ago

Currently, our backend verification system does not allow verifying contracts that are deployed from another contract. But we are working to support this feature and we will let you know once this is implemented.