Skip to content
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

DONOTSUBMIT: example of running verifier on L2 #83

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.idea
tools/target
tools/data/Verifier.sol
tools/data/Verifier.sol

ethereum/.yarn
ethereum/artifacts-zk
ethereum/cache-zk
1 change: 1 addition & 0 deletions ethereum/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
14 changes: 9 additions & 5 deletions ethereum/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/ta
import { task } from "hardhat/config";
import "solidity-coverage";
import { getNumberFromEnv } from "./scripts/utils";
import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";

// If no network is specified, use the default config
if (!process.env.CHAIN_ETH_NETWORK) {
Expand Down Expand Up @@ -101,11 +103,13 @@ export default {
url: process.env.ETH_CLIENT_WEB3_URL?.split(",")[0],
},
hardhat: {
allowUnlimitedContractSize: false,
forking: {
url: "https://eth-goerli.g.alchemy.com/v2/" + process.env.ALCHEMY_KEY,
enabled: process.env.TEST_CONTRACTS_FORK === "1",
},
zksync: true,
},
localhost: {
// era-test-node default url
url: "http://127.0.0.1:8011",
ethNetwork: "http://127.0.0.1:8011",
zksync: true,
},
},
etherscan: {
Expand Down
1 change: 1 addition & 0 deletions ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"devDependencies": {
"@matterlabs/eslint-config-typescript": "^1.1.2",
"@matterlabs/hardhat-zksync-deploy": "^0.6.5",
"@matterlabs/prettier-config": "^1.0.3",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
Expand Down
55 changes: 36 additions & 19 deletions ethereum/test/unit_tests/verifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { VerifierTestFactory } from "../../typechain";
import { getCallRevertReason } from "./utils";
import { ethers } from "hardhat";
import { Provider, Wallet } from "zksync-web3";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

describe("Verifier test", function () {
const Q_MOD = "21888242871839275222246405745257275088696311157297823662689037894645226208583";
Expand Down Expand Up @@ -60,28 +62,43 @@
recursiveAggregationInput: [],
};
let verifier: VerifierTest;
const richAccount = {
address: "0x36615Cf349d7F6344891B1e7CA7C72883F5dc049",
privateKey: "0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110",
};
const provider = new Provider(hardhat.config.networks.localhost.url);
const wallet = new Wallet(richAccount.privateKey, provider);

// To execute:
// run era-test-node on a separate terminal: (in era-test-node repo:

Check failure on line 73 in ethereum/test/unit_tests/verifier.spec.ts

View workflow job for this annotation

GitHub Actions / lint-l1

Delete `·`
// cargo run --release -- run
// run the test:
// CONTRACT_TESTS=1 yarn hardhat test test/unit_tests/verifier.spec.ts --network localhost

before(async function () {
const verifierFactory = await hardhat.ethers.getContractFactory("VerifierTest");
const verifierContract = await verifierFactory.deploy();
const deployer = new Deployer(hardhat, wallet);
const verifierContract = await deployer.deploy(await deployer.loadArtifact("VerifierTest"));

//const verifierFactory = await hardhat.ethers.getContractFactory("VerifierTest");
//const verifierContract = await verifierFactory.deploy();
verifier = VerifierTestFactory.connect(verifierContract.address, verifierContract.signer);
});

it("Should verify proof", async () => {
// Call the verifier directly (though the call, not static call) to add the save the consumed gas into the statistic.
const calldata = verifier.interface.encodeFunctionData("verify", [
PROOF.publicInputs,
PROOF.serializedProof,
PROOF.recursiveAggregationInput,
]);
await verifier.fallback({ data: calldata });
//const calldata = verifier.interface.encodeFunctionData("verify", [
// PROOF.publicInputs,
// PROOF.serializedProof,
// PROOF.recursiveAggregationInput,
//]);
//await verifier.fallback({ data: calldata });

// Check that proof is verified
const result = await verifier.verify(PROOF.publicInputs, PROOF.serializedProof, PROOF.recursiveAggregationInput);
expect(result, "proof verification failed").true;
});

describe("Should verify valid proof with fields values in non standard format", function () {
xdescribe("Should verify valid proof with fields values in non standard format", function () {
it("Public input with dirty bits over Fr mask", async () => {
const validProof = JSON.parse(JSON.stringify(PROOF));
// Fill dirty bits
Expand Down Expand Up @@ -122,7 +139,7 @@
});
});

describe("Should revert on invalid input", function () {
xdescribe("Should revert on invalid input", function () {
it("More than 1 public inputs", async () => {
const invalidProof = JSON.parse(JSON.stringify(PROOF));
// Add one more public input to proof
Expand Down Expand Up @@ -179,20 +196,20 @@
});
});

it("Should failed with invalid public input", async () => {
xit("Should failed with invalid public input", async () => {
const revertReason = await getCallRevertReason(
verifier.verify([ethers.constants.HashZero], PROOF.serializedProof, PROOF.recursiveAggregationInput)
);
expect(revertReason).equal("invalid quotient evaluation");
});

it("Should return correct Verification key hash", async () => {
xit("Should return correct Verification key hash", async () => {
const vksHash = await verifier.verificationKeyHash();
expect(vksHash).equal("0x6625fa96781746787b58306d414b1e25bd706d37d883a9b3acf57b2bd5e0de52");
});
});

describe("Verifier with recursive part test", function () {
xdescribe("Verifier with recursive part test", function () {
const Q_MOD = "21888242871839275222246405745257275088696311157297823662689037894645226208583";
const R_MOD = "21888242871839275222246405745257275088548364400416034343698204186575808495617";

Expand Down Expand Up @@ -259,7 +276,7 @@
verifier = VerifierTestFactory.connect(verifierContract.address, verifierContract.signer);
});

it("Should verify proof", async () => {
xit("Should verify proof", async () => {
// Call the verifier directly (though the call, not static call) to add the save the consumed gas into the statistic.
const calldata = verifier.interface.encodeFunctionData("verify", [
PROOF.publicInputs,
Expand All @@ -273,7 +290,7 @@
expect(result, "proof verification failed").true;
});

describe("Should verify valid proof with fields values in non standard format", function () {
xdescribe("Should verify valid proof with fields values in non standard format", function () {
it("Public input with dirty bits over Fr mask", async () => {
const validProof = JSON.parse(JSON.stringify(PROOF));
// Fill dirty bits
Expand Down Expand Up @@ -314,7 +331,7 @@
});
});

describe("Should revert on invalid input", function () {
xdescribe("Should revert on invalid input", function () {
it("More than 1 public inputs", async () => {
const invalidProof = JSON.parse(JSON.stringify(PROOF));
// Add one more public input to proof
Expand Down Expand Up @@ -376,21 +393,21 @@
});
});

it("Should failed with invalid public input", async () => {
xit("Should failed with invalid public input", async () => {
const revertReason = await getCallRevertReason(
verifier.verify([ethers.constants.HashZero], PROOF.serializedProof, PROOF.recursiveAggregationInput)
);
expect(revertReason).equal("invalid quotient evaluation");
});

it("Should failed with invalid recursive aggregative input", async () => {
xit("Should failed with invalid recursive aggregative input", async () => {
const revertReason = await getCallRevertReason(
verifier.verify(PROOF.publicInputs, PROOF.serializedProof, [1, 2, 1, 2])
);
expect(revertReason).equal("finalPairing: pairing failure");
});

it("Should return correct Verification key hash", async () => {
xit("Should return correct Verification key hash", async () => {
const vksHash = await verifier.verificationKeyHash();
expect(vksHash).equal("0x88b3ddc4ed85974c7e14297dcad4097169440305c05fdb6441ca8dfd77cd7fa7");
});
Expand Down
Loading
Loading