Skip to content

Commit

Permalink
chore(hardhat): v3.0.0-beta.5
Browse files Browse the repository at this point in the history
Former-commit-id: 23ec6dc
  • Loading branch information
cedoor committed Jan 4, 2023
1 parent 84aa8d0 commit 362b025
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 71 deletions.
4 changes: 2 additions & 2 deletions packages/hardhat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@semaphore-protocol/hardhat",
"version": "0.1.0",
"version": "3.0.0-beta.5",
"description": "A Semaphore Hardhat plugin to deploy verifiers and Semaphore contract.",
"license": "MIT",
"main": "dist/index.node.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@nomiclabs/hardhat-ethers": "^2.1.1",
"@semaphore-protocol/contracts": "^2.5.0",
"@semaphore-protocol/contracts": "3.0.0-beta.5",
"circomlibjs": "^0.0.8",
"ethers": "^5.7.1",
"hardhat-dependency-compiler": "^1.1.3"
Expand Down
20 changes: 2 additions & 18 deletions packages/hardhat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,11 @@ import { HardhatConfig, HardhatUserConfig } from "hardhat/types"
import "hardhat-dependency-compiler"
import "@nomiclabs/hardhat-ethers"
import "./tasks/deploy-semaphore"
import "./tasks/deploy-verifier"

extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
config.dependencyCompiler.paths = [
"@semaphore-protocol/contracts/verifiers/Verifier16.sol",
"@semaphore-protocol/contracts/verifiers/Verifier17.sol",
"@semaphore-protocol/contracts/verifiers/Verifier18.sol",
"@semaphore-protocol/contracts/verifiers/Verifier19.sol",
"@semaphore-protocol/contracts/verifiers/Verifier20.sol",
"@semaphore-protocol/contracts/verifiers/Verifier21.sol",
"@semaphore-protocol/contracts/verifiers/Verifier22.sol",
"@semaphore-protocol/contracts/verifiers/Verifier23.sol",
"@semaphore-protocol/contracts/verifiers/Verifier24.sol",
"@semaphore-protocol/contracts/verifiers/Verifier25.sol",
"@semaphore-protocol/contracts/verifiers/Verifier26.sol",
"@semaphore-protocol/contracts/verifiers/Verifier27.sol",
"@semaphore-protocol/contracts/verifiers/Verifier28.sol",
"@semaphore-protocol/contracts/verifiers/Verifier29.sol",
"@semaphore-protocol/contracts/verifiers/Verifier30.sol",
"@semaphore-protocol/contracts/verifiers/Verifier31.sol",
"@semaphore-protocol/contracts/verifiers/Verifier32.sol",
"@semaphore-protocol/contracts/base/Pairing.sol",
"@semaphore-protocol/contracts/base/SemaphoreVerifier.sol",
"@semaphore-protocol/contracts/Semaphore.sol"
]

Expand Down
127 changes: 95 additions & 32 deletions packages/hardhat/src/tasks/deploy-semaphore.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,114 @@
import { poseidon_gencontract as poseidonContract } from "circomlibjs"
import { Contract } from "ethers"
import { task, types } from "hardhat/config"

task("deploy:semaphore", "Deploy a Semaphore contract")
.addParam("verifiers", "Tree depths and verifier addresses", [], types.json)
.addOptionalParam<boolean>("pairing", "Pairing library address", undefined, types.string)
.addOptionalParam<boolean>("semaphoreVerifier", "SemaphoreVerifier contract address", undefined, types.string)
.addOptionalParam<boolean>("poseidon", "Poseidon library address", undefined, types.string)
.addOptionalParam<boolean>(
"incrementalBinaryTree",
"IncrementalBinaryTree library address",
undefined,
types.string
)
.addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
.setAction(async ({ logs, verifiers }, { ethers }): Promise<Contract> => {
const poseidonABI = poseidonContract.generateABI(2)
const poseidonBytecode = poseidonContract.createCode(2)
.setAction(
async (
{
logs,
pairing: pairingAddress,
semaphoreVerifier: semaphoreVerifierAddress,
poseidon: poseidonAddress,
incrementalBinaryTree: incrementalBinaryTreeAddress
},
{ ethers }
): Promise<any> => {
if (!semaphoreVerifierAddress) {
if (!pairingAddress) {
const PairingFactory = await ethers.getContractFactory("Pairing")
const pairing = await PairingFactory.deploy()

const [signer] = await ethers.getSigners()
await pairing.deployed()

const PoseidonLibFactory = new ethers.ContractFactory(poseidonABI, poseidonBytecode, signer)
const poseidonLib = await PoseidonLibFactory.deploy()
if (logs) {
console.info(`Pairing library has been deployed to: ${pairing.address}`)
}

await poseidonLib.deployed()
pairingAddress = pairing.address
}

if (logs) {
console.info(`Poseidon library has been deployed to: ${poseidonLib.address}`)
}
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier", {
libraries: {
Pairing: pairingAddress
}
})

const semaphoreVerifier = await SemaphoreVerifierFactory.deploy()

await semaphoreVerifier.deployed()

const IncrementalBinaryTreeLibFactory = await ethers.getContractFactory("IncrementalBinaryTree", {
libraries: {
PoseidonT3: poseidonLib.address
if (logs) {
console.info(`SemaphoreVerifier contract has been deployed to: ${semaphoreVerifier.address}`)
}

semaphoreVerifierAddress = semaphoreVerifier.address
}
})
const incrementalBinaryTreeLib = await IncrementalBinaryTreeLibFactory.deploy()

await incrementalBinaryTreeLib.deployed()
if (!incrementalBinaryTreeAddress) {
if (!poseidonAddress) {
const poseidonABI = poseidonContract.generateABI(2)
const poseidonBytecode = poseidonContract.createCode(2)

if (logs) {
console.info(`IncrementalBinaryTree library has been deployed to: ${incrementalBinaryTreeLib.address}`)
}
const [signer] = await ethers.getSigners()

const PoseidonFactory = new ethers.ContractFactory(poseidonABI, poseidonBytecode, signer)
const poseidon = await PoseidonFactory.deploy()

await poseidon.deployed()

if (logs) {
console.info(`Poseidon library has been deployed to: ${poseidon.address}`)
}

poseidonAddress = poseidon.address
}

const SemaphoreContractFactory = await ethers.getContractFactory("Semaphore", {
libraries: {
IncrementalBinaryTree: incrementalBinaryTreeLib.address
const IncrementalBinaryTreeFactory = await ethers.getContractFactory("IncrementalBinaryTree", {
libraries: {
PoseidonT3: poseidonAddress
}
})
const incrementalBinaryTree = await IncrementalBinaryTreeFactory.deploy()

await incrementalBinaryTree.deployed()

if (logs) {
console.info(`IncrementalBinaryTree library has been deployed to: ${incrementalBinaryTree.address}`)
}

incrementalBinaryTreeAddress = incrementalBinaryTree.address
}
})

const semaphoreContract = await SemaphoreContractFactory.deploy(verifiers)
const SemaphoreFactory = await ethers.getContractFactory("Semaphore", {
libraries: {
IncrementalBinaryTree: incrementalBinaryTreeAddress
}
})

await semaphoreContract.deployed()
const semaphore = await SemaphoreFactory.deploy(semaphoreVerifierAddress)

if (logs) {
console.info(`Semaphore contract has been deployed to: ${semaphoreContract.address}`)
}
await semaphore.deployed()

return semaphoreContract
})
if (logs) {
console.info(`Semaphore contract has been deployed to: ${semaphore.address}`)
}

return {
semaphore,
pairingAddress,
semaphoreVerifierAddress,
poseidonAddress,
incrementalBinaryTreeAddress
}
}
)
19 changes: 0 additions & 19 deletions packages/hardhat/src/tasks/deploy-verifier.ts

This file was deleted.

0 comments on commit 362b025

Please sign in to comment.