Contract verification


Contract verification

What is contract verification?

When you deploy a smart contract on a network, you’re essentially deploying the bytecode produced by the Solidity compiler.

Verifying a contract entails determining whether the on-chain bytecode matches a given source code when it is compiled. If it does, we can state that we have confirmed the bytecode's source code's integrity. Hence the name – verification.

How are smart contracts verified in zkSync?

The deployed bytecode and the Solidity source code of a smart contract are compared during the verification process using zkSync. The algorithm compiles the source code to compare the generated bytecode to the deployed one.
If the two sides match in every way, the contract is verified.

Code verification requires six arguments:

  • The contract address
  • The contract name
  • The source code, including the source of all imports
  • The version of the compiler used to produce the deployed bytecode
  • Information about the number of compiler optimizations (if any)
  • The constructor arguments

If any of these pieces of information is wrong, the process of verification fails.

Source code privacy

When your smart contract is deployed on zkSync and verified on the block explorer, users can check the verified source code and interact with it.

Verifying Contracts Using the zkSync Block Explorer

To get started click the Tools tab in the top header, a dropdown will pop up and select Smart Contract Verification, after which you will be shown the following screen:

Smart Contract Verification page!

Enter contract details

To verify the contract, enter the following details;

  • Contract address: The address provided must match with the 0x address generated during contract creation.
  • Contract name: The name must be identical to the name provided in the contract.
  • Optimization: This checks whether or not optimization was used while compiling the contract. If you enabled optimization during compilation, check Yes otherwise select No
  • Solidity compiler version(Solc): This specifies the exact version of the compiler used to compile a smart contract. Click on the dropdown to specify the compiler version used. We encourage you to use version 0.8.16.
  • zkSync compiler version(Zksolc): The zkSync compiler version used, the default is set to v1.2.0.

Compiler version!


How can you obtain your constructor arguments?

Note: The easiest way to get the constructor argument data is to print it to the console while deploying.

For example, if using our tutorial, you can find the line:

const greeterContract = await deployer.deploy(artifact, [greeting]);

if you add the next line as

console.log(greeterContract.interface.encodeDeploy([greeting]));

then you will receive constructor argument data.

  • Lastly, click the Verify Smart Contract button.

If all goes well, you will see a success message.

Smart Contract Verified!