Skip to content

Conversation

@popzxc
Copy link
Member

@popzxc popzxc commented Jan 24, 2025

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 🥲

  • Changes zksolc used in contract verifier tests to 1.5.10 (old one didn't have ipfs metadata hash support).
  • Fixes problems that occured with newer compilers (e.g. Yul bytecode extraction).
  • Makes it easier to run contract verifier tests locally (pins compiler versions, so that if you have a lot of compilers locally, tests don't crash).
  • Introduces partial matching for contracts
  • Reworks the schema so that contracts with matching bytecode can be "automatically" verified.
  • Adds a migration to the new table.

@popzxc popzxc force-pushed the popzxc-contract-verifier branch 4 times, most recently from 2a0083d to 44aac98 Compare January 24, 2025 12:39
@popzxc popzxc force-pushed the popzxc-contract-verifier branch from 44aac98 to 514900f Compare January 24, 2025 13:22
@popzxc popzxc marked this pull request as ready for review January 24, 2025 14:01
@popzxc popzxc requested a review from a team as a code owner January 24, 2025 14:01
@popzxc popzxc requested a review from perekopskiy January 28, 2025 13:24
perekopskiy
perekopskiy previously approved these changes Jan 28, 2025
@popzxc popzxc requested a review from slowli January 30, 2025 07:40
@popzxc popzxc enabled auto-merge January 30, 2025 12:31
@popzxc popzxc added this pull request to the merge queue Jan 30, 2025
Merged via the queue into main with commit bf9fe85 Jan 30, 2025
42 checks passed
@popzxc popzxc deleted the popzxc-contract-verifier branch January 30, 2025 14:33
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.
github-merge-queue bot pushed a commit that referenced this pull request Feb 12, 2025
🤖 I have created a release *beep* *boop*
---


##
[26.3.0](core-v26.2.1...core-v26.3.0)
(2025-02-12)


### Features

* **contract-verifier:** Do not allow verification requests for verified
contracts
([#3578](#3578))
([6a1f1b8](6a1f1b8))
* **contract-verifier:** Partial matching & automatic verification
([#3527](#3527))
([bf9fe85](bf9fe85))
* **contract-verifier:** Support missing options for EVM in API
([#3592](#3592))
([309fdf4](309fdf4))
* **en:** better EN default req entities limit, improved documentation
for API limits
([#3546](#3546))
([e7eb716](e7eb716))
* make `zksync_types` thinner
([#3574](#3574))
([e7f93e4](e7f93e4))
* new da_dispatcher metrics
([#3464](#3464))
([75a7c08](75a7c08))
* update FFLONK protocol version
([#3572](#3572))
([a352852](a352852))
* **vm:** Allow caching signature verification
([#3505](#3505))
([7bb5ed3](7bb5ed3))
* **vm:** Support missed storage invocation limit in fast VM
([#3548](#3548))
([ef67694](ef67694))


### Bug Fixes

* Add debug information to object store retries
([#3576](#3576))
([036315c](036315c))
* allow configuring NoDA client via ENV
([#3599](#3599))
([a72ab63](a72ab63))
* **api:** Change `contractAddress` assignment for transaction receipts
([#3452](#3452))
([4179711](4179711))
* **api:** Improve estimation for gas_per_pubdata_limit
([#3475](#3475))
([bda1b25](bda1b25))
* Avail gas relay decoding issues
([#3547](#3547))
([a171433](a171433))
* **ci:** commenting out getFilterChanges test until fix is ready
([#3582](#3582))
([99c3905](99c3905))
* Support newer versions of foundry-zksync
([#3556](#3556))
([d39fb6d](d39fb6d))
* **vm:** Fix VM divergences related to validation
([#3567](#3567))
([170d194](170d194))


### Performance Improvements

* **db:** Remove `events.tx_initiator_address` writes and index
([#3559](#3559))
([298abd2](298abd2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: zksync-era-bot <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Mar 4, 2025
🤖 I have created a release *beep* *boop*
---


##
[19.0.0](prover-v18.0.0...prover-v19.0.0)
(2025-03-04)


### ⚠ BREAKING CHANGES

* Combine GPU and simple Scaler into single Scaler
([#3621](#3621))

### Features

* add custom DA support in external node
([#3445](#3445))
([1a8546d](1a8546d))
* **contract-verifier:** Partial matching & automatic verification
([#3527](#3527))
([bf9fe85](bf9fe85))
* make `zksync_types` thinner
([#3574](#3574))
([e7f93e4](e7f93e4))
* preparation for new precompiles
([#3535](#3535))
([3c1f3fb](3c1f3fb))
* **prover:** Add gpu_checker binary
([#3573](#3573))
([51b9a03](51b9a03))
* Refactor WG DAL
([#3560](#3560))
([d1ede36](d1ede36))
* Rework prover job handling
([#3561](#3561))
([ddc4243](ddc4243))
* Updating information about keys & commitments for releases
([#3486](#3486))
([cd21c9e](cd21c9e))
* **vm:** Allow caching signature verification
([#3505](#3505))
([7bb5ed3](7bb5ed3))


### Bug Fixes

* Add autoscaler_queue metric back
([#3668](#3668))
([7f36ed9](7f36ed9))
* Allow witness_generator to use Prometheus push gateway in continuous
mode ([#3555](#3555))
([0f1a5e0](0f1a5e0))
* Simplify prover_jobs_fri indices
([#3577](#3577))
([559edc3](559edc3))


### Performance Improvements

* Add prover jobs as one multi-insert for Witness Generator
([#3587](#3587))
([d150dca](d150dca))


### Code Refactoring

* Combine GPU and simple Scaler into single Scaler
([#3621](#3621))
([8e24403](8e24403))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: zksync-era-bot <[email protected]>
zkzoomer pushed a commit that referenced this pull request Jun 21, 2025
…3527)

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 🥲 

- Changes `zksolc` used in contract verifier tests to 1.5.10 (old one
didn't have `ipfs` metadata hash support).
- Fixes problems that occured with newer compilers (e.g. `Yul` bytecode
extraction).
- Makes it easier to run contract verifier tests locally (pins compiler
versions, so that if you have a lot of compilers locally, tests don't
crash).
- Introduces partial matching for contracts
- Reworks the schema so that contracts with matching bytecode can be
"automatically" verified.
- Adds a migration to the new table.
zkzoomer pushed a commit that referenced this pull request Jun 21, 2025
🤖 I have created a release *beep* *boop*
---


##
[26.3.0](core-v26.2.1...core-v26.3.0)
(2025-02-12)


### Features

* **contract-verifier:** Do not allow verification requests for verified
contracts
([#3578](#3578))
([6a1f1b8](6a1f1b8))
* **contract-verifier:** Partial matching & automatic verification
([#3527](#3527))
([b94d1ad](b94d1ad))
* **contract-verifier:** Support missing options for EVM in API
([#3592](#3592))
([309fdf4](309fdf4))
* **en:** better EN default req entities limit, improved documentation
for API limits
([#3546](#3546))
([e7eb716](e7eb716))
* make `zksync_types` thinner
([#3574](#3574))
([292e731](292e731))
* new da_dispatcher metrics
([#3464](#3464))
([75a7c08](75a7c08))
* update FFLONK protocol version
([#3572](#3572))
([a352852](a352852))
* **vm:** Allow caching signature verification
([#3505](#3505))
([7bb5ed3](7bb5ed3))
* **vm:** Support missed storage invocation limit in fast VM
([#3548](#3548))
([ef67694](ef67694))


### Bug Fixes

* Add debug information to object store retries
([#3576](#3576))
([036315c](036315c))
* allow configuring NoDA client via ENV
([#3599](#3599))
([a72ab63](a72ab63))
* **api:** Change `contractAddress` assignment for transaction receipts
([#3452](#3452))
([4179711](4179711))
* **api:** Improve estimation for gas_per_pubdata_limit
([#3475](#3475))
([bda1b25](bda1b25))
* Avail gas relay decoding issues
([#3547](#3547))
([a171433](a171433))
* **ci:** commenting out getFilterChanges test until fix is ready
([#3582](#3582))
([99c3905](99c3905))
* Support newer versions of foundry-zksync
([#3556](#3556))
([d39fb6d](d39fb6d))
* **vm:** Fix VM divergences related to validation
([#3567](#3567))
([170d194](170d194))


### Performance Improvements

* **db:** Remove `events.tx_initiator_address` writes and index
([#3559](#3559))
([298abd2](298abd2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: zksync-era-bot <[email protected]>
dutterbutter pushed a commit to dutterbutter/zkstack-cli that referenced this pull request Jul 3, 2025
🤖 I have created a release *beep* *boop*
---


##
[26.3.0](matter-labs/zksync-era@core-v26.2.1...core-v26.3.0)
(2025-02-12)


### Features

* **contract-verifier:** Do not allow verification requests for verified
contracts
([#3578](matter-labs/zksync-era#3578))
([6a1f1b8](matter-labs/zksync-era@6a1f1b8))
* **contract-verifier:** Partial matching & automatic verification
([#3527](matter-labs/zksync-era#3527))
([a0b7ca1](matter-labs/zksync-era@a0b7ca1))
* **contract-verifier:** Support missing options for EVM in API
([#3592](matter-labs/zksync-era#3592))
([309fdf4](matter-labs/zksync-era@309fdf4))
* **en:** better EN default req entities limit, improved documentation
for API limits
([#3546](matter-labs/zksync-era#3546))
([e7eb716](matter-labs/zksync-era@e7eb716))
* make `zksync_types` thinner
([#3574](matter-labs/zksync-era#3574))
([fc84832](matter-labs/zksync-era@fc84832))
* new da_dispatcher metrics
([#3464](matter-labs/zksync-era#3464))
([75a7c08](matter-labs/zksync-era@75a7c08))
* update FFLONK protocol version
([#3572](matter-labs/zksync-era#3572))
([a352852](matter-labs/zksync-era@a352852))
* **vm:** Allow caching signature verification
([#3505](matter-labs/zksync-era#3505))
([7bb5ed3](matter-labs/zksync-era@7bb5ed3))
* **vm:** Support missed storage invocation limit in fast VM
([#3548](matter-labs/zksync-era#3548))
([ef67694](matter-labs/zksync-era@ef67694))


### Bug Fixes

* Add debug information to object store retries
([#3576](matter-labs/zksync-era#3576))
([036315c](matter-labs/zksync-era@036315c))
* allow configuring NoDA client via ENV
([#3599](matter-labs/zksync-era#3599))
([a72ab63](matter-labs/zksync-era@a72ab63))
* **api:** Change `contractAddress` assignment for transaction receipts
([#3452](matter-labs/zksync-era#3452))
([4179711](matter-labs/zksync-era@4179711))
* **api:** Improve estimation for gas_per_pubdata_limit
([#3475](matter-labs/zksync-era#3475))
([bda1b25](matter-labs/zksync-era@bda1b25))
* Avail gas relay decoding issues
([#3547](matter-labs/zksync-era#3547))
([a171433](matter-labs/zksync-era@a171433))
* **ci:** commenting out getFilterChanges test until fix is ready
([#3582](matter-labs/zksync-era#3582))
([99c3905](matter-labs/zksync-era@99c3905))
* Support newer versions of foundry-zksync
([#3556](matter-labs/zksync-era#3556))
([d39fb6d](matter-labs/zksync-era@d39fb6d))
* **vm:** Fix VM divergences related to validation
([#3567](matter-labs/zksync-era#3567))
([170d194](matter-labs/zksync-era@170d194))


### Performance Improvements

* **db:** Remove `events.tx_initiator_address` writes and index
([#3559](matter-labs/zksync-era#3559))
([298abd2](matter-labs/zksync-era@298abd2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: zksync-era-bot <[email protected]>
GillLeonard added a commit to GillLeonard/zenith-lab that referenced this pull request Sep 26, 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(contract-verifier): Auto-verify the same bytecode Support partial matches in contract verifier

4 participants