Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display partial & automatic verification info (#383)
Adds visuals for automatic verification and partial matching introduced in matter-labs/zksync-era#3527 Demo: <details> <summary>Unverified contract (no changes from previous behavior)</summary>  </details> <details> <summary>Fully verified contract (no changes from previous behavior)</summary>  </details> <details> <summary>Automatically verified contract</summary>  </details> <details> <summary>Partially verified contract (metadata hash mismatch)</summary>  </details> <details> <summary>Partially verified contract + automatic verification (e.g. there is a verified contract with the same bytecode but different metadata hash)</summary>  </details> Unfortunately, since this feature depends on contract verifier version that isn't deployed anywhere yet, it's not easy to test it. If you want to ~~suffer~~ reproduce it locally, you can do it as follows: <details> <summary>How to test locally</summary> 1. Use `zksync-era` repo on the most recent `main` & install `zkstack` CLI. 2. `zkstack e init --dev` 3. `zkstack contract-verifier init --zksolc-version=v1.5.7 --zkvyper-version=v1.5.4 --solc-version=0.8.26 --vyper-version=v0.3.10 --era-vm-solc-version=0.8.26-1.0.1 --only` 4. Run `zkstack explorer init` 5. Run `zkstack server --components api,tree,eth,state_keeper,housekeeper,commitment_generator,da_dispatcher,vm_runner_protective_reads,contract_verification_api` in one terminal 6. Run `zkstack contract-verifier run` in another terminal 7. Run `zkstack explorer run-backend` in third terminal 8. Configure block explorer FE to interact with dockerized explorer BE and contract verifier: change `apiUrl` port to `3002` and add `"verificationApiUrl": "http://127.0.0.1:3070"` 9. Run block explorer FE (only) 10. Use `npx zksync-cli bridge deposit`, choose dockerized setup, PK for rich wallet is `0xbe79721778b48bcc679b78edac0ce48306a8578186ffcb9f2ee455ae6efeace1` (address `0xe706e60ab5Dc512C36A4646D719b889F398cbBcB`) 11. Do `export COMPILERS=/path/to/zksync-era/etc` 12. Go to `zksync-era/core/tests/ts-integration/contracts/counter` 13. Do `$COMPILERS/zksolc-bin/v1.5.7/zksolc --solc $COMPILERS/solc-bin/zkVM-0.8.28-1.0.1/solc counter.sol --bin` 14. Deploy the bytecode with the script shown below 15. Open tx in the explorer, find the log with three topics, one of which is deployer address; the third one will contain the address of the deployed contract. 16. Verify the contract through UI Now you can do the following: - To check automatic verification, just deploy the same contract once again. Verification will not be needed - To check partial matching, change the last byte (you will corrupt the metadata hash, and it will trigger partial verification) Script ``` import { ethers, hexlify, solidityPacked } from "ethers"; import { Wallet, Provider } from "zksync-ethers"; import { CONTRACT_DEPLOYER_ADDRESS, hashBytecode } from "zksync-ethers/build/utils"; const PK = "0xbe79721778b48bcc679b78edac0ce48306a8578186ffcb9f2ee455ae6efeace1"; const BYTECODE = "0x<insert bytecode here>"; async function main() { // Create deploy transaction using zksync-ethers using bytecode // and send it to the network const provider = new Provider("http://localhost:3050"); const wallet = new Wallet(PK, provider); const bytecodeHash = hashBytecode(BYTECODE); // const contract = new ethers.Contract(CONTRACT_DEPLOYER_ADDRESS, abi, wallet); const selector = "create(bytes32,bytes32,bytes)"; const selectorHash = ethers.keccak256(ethers.toUtf8Bytes(selector)).substring(0, 10); console.log(`Selector hash: ${selectorHash}`); const calldata = selectorHash + solidityPacked(["bytes32", "bytes32", "bytes"], [new Uint8Array(32), bytecodeHash, new Uint8Array(64)]).substring(2); console.log(`Calldata: ${calldata}`); const bytecode_u8_array = ethers.getBytes(BYTECODE); const tx = await wallet.sendTransaction({ to: CONTRACT_DEPLOYER_ADDRESS, data: calldata, value: 0, customData: { factoryDeps: [bytecode_u8_array], } }); console.log(`Transaction hash: ${tx.hash}`); await tx.wait(); } main() .then(() => process.exit(0)) .catch((err) => { console.error('Error:', err.message || err); process.exit(1); }); ``` </details> Disclaimer: I don't know front-end, I hate front-end, I question myself why I thought it's a good idea to work on this.  P.S. I wanted to add Ukrainian translation as well, but looks like contract verification has no translations, so I thought that it deserves a dedicated effort to add all the missing translations when/if it would be required.
- Loading branch information