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

Improve verify_circuit_proof method #110

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MUMBAI_PRIVATE_KEY=""
MUMBAI_ALCHEMY_KEY=""
SEPOLIA_PRIVATE_KEY=""
SEPOLIA_ALCHEMY_KEY=""
PRODUCTION_PRIVATE_KEY=""
PRODUCTION_ALCHEMY_KEY=""
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# EVM Placeholder proof system verifier
# EVM Placeholder proof system verifier

[![Discord](https://img.shields.io/discord/969303013749579846.svg?logo=discord&style=flat-square)](https://discord.gg/KmTAEjbmM3)
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=flat-square&logo=telegram&logoColor=dark)](https://t.me/nilfoundation)
Expand Down Expand Up @@ -53,6 +53,13 @@ cd evm-placeholder-verification
npm i
```

## Configure Environment Variables
Before deploying or verifying on-chain, configure your .env for RPC URLs and Private Key. Copy the evm.example file to .env and update it with your details:
```bash
cp env.example .env
# Edit .env to include your private key and RPC URLs
```

## Compile contracts

```bash
Expand Down
8 changes: 8 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ require("hardhat-deploy");
require('hardhat-deploy-ethers');
require('hardhat-contract-sizer');

import "dotenv/config";
import './tasks/modular-test'

const DEFAULT_PRIVATE_KEY = "0x" + "0".repeat(64); // 32 bytes of zeros placeholder to pass config validation

const MUMBAI_PRIVATE_KEY = process.env.MUMBAI_PRIVATE_KEY || DEFAULT_PRIVATE_KEY;
const MUMBAI_ALCHEMY_KEY = process.env.MUMBAI_ALCHEMY_KEY || "";

const SEPOLIA_PRIVATE_KEY = process.env.SEPOLIA_PRIVATE_KEY || DEFAULT_PRIVATE_KEY;
const SEPOLIA_ALCHEMY_KEY = process.env.SEPOLIA_ALCHEMY_KEY || "";

Expand Down Expand Up @@ -47,6 +51,10 @@ module.exports = {
},
localhost: {
url: "http://127.0.0.1:8545",
},
mumbai: {
url: `https://polygon-mumbai.g.alchemy.com/v2/${MUMBAI_ALCHEMY_KEY}`,
accounts: [MUMBAI_PRIVATE_KEY]
}
},
etherscan: {
Expand Down
58 changes: 34 additions & 24 deletions tasks/modular-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,43 @@ const verify_circuit_proof = async (modular_path: string, circuit: string) => {
console.log("Wrong public input format!");
return null;
}
let receipt = await (await verifier_contract.verify(proof, public_input, {gasLimit: 30_500_000})).wait();
console.log("⛽Gas used: ", receipt.gasUsed.toNumber());
console.log("Events received:");
const get_verification_event_result = (event): boolean | null => {
if (event.event == 'VerificationResult') {
return BigInt(event.data) != 0n;
}
return null;
};
const event_to_string = (event) => {
const verification_result = get_verification_event_result(event);
if (verification_result !== null) {
return verification_result ? '✅ProofVerified' : '🛑ProofVerificationFailed';
}
return '🤔' + event.event;
};
try {
let txResponse = await verifier_contract.verify(proof, public_input, {
gasLimit: 15_000_000,
//gasPrice: ethers.utils.parseUnits('10', 'gwei')
});
console.log("Transaction Hash:", txResponse.hash);

let receipt = await txResponse.wait();
console.log("Block Number:", receipt.blockNumber);
console.log("⛽ Gas used: ", receipt.gasUsed.toNumber());
const get_verification_event_result = (event): boolean | null => {
if (event.event == 'VerificationResult') {
return BigInt(event.data) != 0n;
}
return null;
};
const event_to_string = (event) => {
const verification_result = get_verification_event_result(event);
if (verification_result !== null) {
return verification_result ? '✅ ProofVerified' : '🛑 ProofVerificationFailed';
}
return '🤔' + event.event;
};

let verification_result = null;
for (const e of receipt.events) {
const result = get_verification_event_result(e);
if (result !== null) {
verification_result = result;
let verification_result = null;
for (const e of receipt.events) {
const result = get_verification_event_result(e);
if (result !== null) {
verification_result = result;
}
console.log(event_to_string(e));
}
console.log(event_to_string(e));
console.log("====================================");
return verification_result;
} catch (error) {
console.error("Error during transaction:", error.message);
}
console.log("====================================");
return verification_result;
}

task("verify-circuit-proof-all")
Expand Down
Loading