Skip to content

Commit

Permalink
Merge pull request #11 from bobanetwork/split
Browse files Browse the repository at this point in the history
split verifier and verifying key contracts
  • Loading branch information
kitounliu committed Mar 20, 2024
2 parents 59e4a2b + 99ae3da commit 9d7518a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
RPC_URL=http://localhost:7545
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
THRESHOLD=3
NUMBER_OF_MEMBERS=5
DEGREE=18
DEPLOY_NO_HELPERS=false # optional
HALO2V=0x26Aa5a7c4CA7D0F81943ea9CbDf97D80c560D6Fa # optional
HALO2VK=0x63311f167b6B07fd0D3d83310c16512701B4Cb2d # optional
GPP=0xbB9a8f4c3662b6EF4b512E5f358289d1Db63fc81 # optional
PSRAND=0xAecFC1cc68dD9664F2fCF5f2958d5277c5385123 # optional
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ To deploy the Zkdvrf contracts on-chain-
RPC_URL = <rpc of network to deploy on>
PRIVATE_KEY = <deployer pk>
DEPLOY_NO_HELPERS = <true/false> # optional
HALO2V = <Halo2VerifyingKey-3-5-18-g2 address> # optional
HALO2V = <Halo2Verifier address> # optional
HALO2VK = <Halo2VerifyingKey-3-5-18-g2 address> # optional
GPP = <GlobalPublicParam address> # optional
PSRAND = <PseudoRand address> # optional
```
Expand Down
12 changes: 7 additions & 5 deletions contracts/zkdvrf.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Halo2Verifier} from "./Halo2Verifier-3-5-g2.sol";
import {Halo2Verifier} from "./Halo2Verifier.sol";
import {GlobalPublicParams} from "./GlobalPublicParams.sol";
import {Pairing} from "./libs/Pairing.sol";
import {IPseudoRand} from "./IPseudoRand.sol";
Expand Down Expand Up @@ -51,6 +51,7 @@ contract zkdvrf is Ownable {

Status public contractPhase;
address public halo2Verifier;
address public halo2VerifyingKey;
address public globalPublicParams;
address public pseudoRand;

Expand All @@ -62,12 +63,13 @@ contract zkdvrf is Ownable {
mapping (uint256 => uint32) public roundSubmissionCount;
mapping (uint256 => IPseudoRand.PseudoRandom) public roundToRandom;

constructor(address halo2VerifierAddress, address globalPublicParamsAddress, address pseudoRandAddress, uint256 minDeposit) Ownable(msg.sender) {
constructor(uint32 thresholdValue, uint32 numberValue, address halo2VerifierAddress, address halo2VerifyingKeyAddress, address globalPublicParamsAddress, address pseudoRandAddress, uint256 minDeposit) Ownable(msg.sender) {
require (halo2VerifierAddress != address(0) && globalPublicParamsAddress != address(0) && pseudoRandAddress != address(0), "Cannot be zero addresses");
memberCount = 5;
threshold = 3;
memberCount = numberValue;
threshold = thresholdValue;
ppLength = 7 * memberCount + 14;
halo2Verifier = halo2VerifierAddress;
halo2VerifyingKey = halo2VerifyingKeyAddress;
globalPublicParams = globalPublicParamsAddress;
pseudoRand = pseudoRandAddress;
minNodeDeposit = minDeposit;
Expand Down Expand Up @@ -121,7 +123,7 @@ contract zkdvrf is Ownable {
require(contractPhase == Status.Nidkg, "Contract not in NIDKG phase");
require(!addrToNode[msg.sender].statusPP, "Node already submitted");
require(checkPublicParams(pp), "Invalid public parameters");
require(Halo2Verifier(halo2Verifier).verifyProof(zkProof, pp), "SNARK proof verification failed");
require(Halo2Verifier(halo2Verifier).verifyProof(halo2VerifyingKey, zkProof, pp), "SNARK proof verification failed");

addrToNode[msg.sender].statusPP = true;

Expand Down
18 changes: 15 additions & 3 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@ async function main() {
const netprovider = new providers.JsonRpcProvider(process.env.RPC_URL)
const accPrivateKey = process.env.PRIVATE_KEY ?? ''
const deployerWallet = new Wallet(accPrivateKey, netprovider)
const threshold = process.env.THRESHOLD
const numberOfMembers = process.env.NUMBER_OF_MEMBERS
const degree = process.env.DEGREE
const minDeposit = process.env.MIN_DEPOSIT ?? '0'
const deployNoHelpers = process.env.DEPLOY_NO_HELPERS === 'true'

let halo2VerifierAddress
let halo2VerifyingKeyAddress
let globalPublicParamsAddress
let pseudoRandAddress

if (deployNoHelpers) {
halo2VerifierAddress = process.env.HALO2V
halo2VerifierAddress = process.env.HALO2V
halo2VerifyingKeyAddress = process.env.HALO2VK
globalPublicParamsAddress = process.env.GPP
pseudoRandAddress = process.env.PSRAND
} else {
const Halo2Verifier = await ethers.getContractFactory('contracts/Halo2Verifier-3-5-g2.sol:Halo2Verifier')
const Halo2VerifyingKey = await ethers.getContractFactory(`contracts/Halo2VerifyingKey-${threshold}-${numberOfMembers}-${degree}-g2.sol:Halo2VerifyingKey`)
const halo2VerifyingKey = await Halo2VerifyingKey.connect(deployerWallet).deploy()
await halo2VerifyingKey.deployed()

console.log("Halo2VerifyingKey deployed at", halo2VerifyingKey.address)

const Halo2Verifier = await ethers.getContractFactory('contracts/Halo2Verifier.sol:Halo2Verifier')
const halo2Verifier = await Halo2Verifier.connect(deployerWallet).deploy()
await halo2Verifier.deployed()

Expand All @@ -35,13 +46,14 @@ async function main() {

console.log("PseudoRand deployed at", pseudoRand.address)

halo2VerifyingKeyAddress = halo2VerifyingKey.address
halo2VerifierAddress = halo2Verifier.address
globalPublicParamsAddress = globalPublicParams.address
pseudoRandAddress = pseudoRand.address
}

const Zkdvrf = await ethers.getContractFactory('zkdvrf')
const zkdvrf = await Zkdvrf.connect(deployerWallet).deploy(halo2VerifierAddress, globalPublicParamsAddress, pseudoRandAddress, minDeposit)
const zkdvrf = await Zkdvrf.connect(deployerWallet).deploy(threshold, numberOfMembers, halo2VerifierAddress, halo2VerifyingKeyAddress, globalPublicParamsAddress, pseudoRandAddress, minDeposit)
await zkdvrf.deployed()

console.log("Zkdvrf deployed at", zkdvrf.address)
Expand Down
6 changes: 4 additions & 2 deletions test/zkdvrf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ chai.use(solidity);

let Zkdvrf: Contract
let Halo2Verifier: Contract
let Halo2VerifyingKey: Contract
let GlobalPublicParams: Contract
let PseudoRand: Contract

Expand Down Expand Up @@ -82,12 +83,13 @@ const local_provider = new providers.JsonRpcProvider(cfg['url'])

describe('ZKDVRF on-chain tests', async () => {
before(async () => {
Halo2Verifier = await(await ethers.getContractFactory('contracts/Halo2Verifier-3-5-18-g2.sol:Halo2Verifier')).deploy()
Halo2Verifier = await(await ethers.getContractFactory('contracts/Halo2Verifier.sol:Halo2Verifier')).deploy()
Halo2VerifyingKey = await(await ethers.getContractFactory('contracts/Halo2VerifyingKey-3-5-18-g2.sol:Halo2VerifyingKey')).deploy()
GlobalPublicParams = await(await ethers.getContractFactory('GlobalPublicParams')).deploy()
PseudoRand = await(await ethers.getContractFactory('PseudoRand')).deploy()
Zkdvrf = await (
await ethers.getContractFactory('zkdvrf')
).deploy(Halo2Verifier.address, GlobalPublicParams.address, PseudoRand.address, minDeposit)
).deploy(3, 5, Halo2Verifier.address, Halo2VerifyingKey.address, GlobalPublicParams.address, PseudoRand.address, minDeposit)

account1 = (await ethers.getSigners())[0]
account2 = (await ethers.getSigners())[1]
Expand Down

0 comments on commit 9d7518a

Please sign in to comment.