-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(contract-verifier): Partial matching & automatic verification #3527
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2a0083d
to
44aac98
Compare
44aac98
to
514900f
Compare
popzxc
commented
Jan 24, 2025
popzxc
commented
Jan 27, 2025
slowli
reviewed
Jan 27, 2025
core/lib/types/src/contract_verification/contract_identifier.rs
Outdated
Show resolved
Hide resolved
core/lib/types/src/contract_verification/contract_identifier.rs
Outdated
Show resolved
Hide resolved
core/lib/types/src/contract_verification/contract_identifier.rs
Outdated
Show resolved
Hide resolved
core/lib/types/src/contract_verification/contract_identifier.rs
Outdated
Show resolved
Hide resolved
core/lib/types/src/contract_verification/contract_identifier.rs
Outdated
Show resolved
Hide resolved
popzxc
commented
Jan 28, 2025
perekopskiy
reviewed
Jan 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach with indexing hashes is nit!
core/lib/dal/migrations/20250122102800_contract-verifier-new-schema.up.sql
Outdated
Show resolved
Hide resolved
perekopskiy
previously approved these changes
Jan 28, 2025
slowli
reviewed
Jan 28, 2025
slowli
reviewed
Jan 29, 2025
slowli
approved these changes
Jan 30, 2025
otani88
approved these changes
Jan 30, 2025
This was referenced Jan 30, 2025
popzxc
added a commit
to matter-labs/block-explorer
that referenced
this pull request
Feb 7, 2025
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> ![image](https://github.com/user-attachments/assets/d0872c9d-c9ec-4e00-afef-25e1e9e6a1d4) </details> <details> <summary>Fully verified contract (no changes from previous behavior)</summary> ![image](https://github.com/user-attachments/assets/68f90165-46af-44ac-8ce8-b595fb2a6450) </details> <details> <summary>Automatically verified contract</summary> ![image](https://github.com/user-attachments/assets/3536d7be-5da7-4364-b5e7-a32ba184afb1) </details> <details> <summary>Partially verified contract (metadata hash mismatch)</summary> ![image](https://github.com/user-attachments/assets/7cdb4daa-9b59-433b-9a15-f5d833c15e3f) </details> <details> <summary>Partially verified contract + automatic verification (e.g. there is a verified contract with the same bytecode but different metadata hash)</summary> ![image](https://github.com/user-attachments/assets/e1883ede-9fbd-474a-8bc9-401b2e050f06) </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. ![i_have_no_idea_what_im_doing_meme_640_07](https://github.com/user-attachments/assets/27f7053d-42b3-4ece-a69b-631c3e28e84c) 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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3190
Fixes #3309
I still have to test the migration logic (want to make sure that Era mainnet data can be migrated correctly & quickly), but the PR is reviewable otherwise.
This one is much bigger than I indended it to be, sorry 🥲
zksolc
used in contract verifier tests to 1.5.10 (old one didn't haveipfs
metadata hash support).Yul
bytecode extraction).