Skip to content

Commit 362b025

Browse files
committed
chore(hardhat): v3.0.0-beta.5
Former-commit-id: 23ec6dc
1 parent 84aa8d0 commit 362b025

File tree

4 files changed

+99
-71
lines changed

4 files changed

+99
-71
lines changed

packages/hardhat/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@semaphore-protocol/hardhat",
3-
"version": "0.1.0",
3+
"version": "3.0.0-beta.5",
44
"description": "A Semaphore Hardhat plugin to deploy verifiers and Semaphore contract.",
55
"license": "MIT",
66
"main": "dist/index.node.js",
@@ -38,7 +38,7 @@
3838
},
3939
"dependencies": {
4040
"@nomiclabs/hardhat-ethers": "^2.1.1",
41-
"@semaphore-protocol/contracts": "^2.5.0",
41+
"@semaphore-protocol/contracts": "3.0.0-beta.5",
4242
"circomlibjs": "^0.0.8",
4343
"ethers": "^5.7.1",
4444
"hardhat-dependency-compiler": "^1.1.3"

packages/hardhat/src/index.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,11 @@ import { HardhatConfig, HardhatUserConfig } from "hardhat/types"
44
import "hardhat-dependency-compiler"
55
import "@nomiclabs/hardhat-ethers"
66
import "./tasks/deploy-semaphore"
7-
import "./tasks/deploy-verifier"
87

98
extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
109
config.dependencyCompiler.paths = [
11-
"@semaphore-protocol/contracts/verifiers/Verifier16.sol",
12-
"@semaphore-protocol/contracts/verifiers/Verifier17.sol",
13-
"@semaphore-protocol/contracts/verifiers/Verifier18.sol",
14-
"@semaphore-protocol/contracts/verifiers/Verifier19.sol",
15-
"@semaphore-protocol/contracts/verifiers/Verifier20.sol",
16-
"@semaphore-protocol/contracts/verifiers/Verifier21.sol",
17-
"@semaphore-protocol/contracts/verifiers/Verifier22.sol",
18-
"@semaphore-protocol/contracts/verifiers/Verifier23.sol",
19-
"@semaphore-protocol/contracts/verifiers/Verifier24.sol",
20-
"@semaphore-protocol/contracts/verifiers/Verifier25.sol",
21-
"@semaphore-protocol/contracts/verifiers/Verifier26.sol",
22-
"@semaphore-protocol/contracts/verifiers/Verifier27.sol",
23-
"@semaphore-protocol/contracts/verifiers/Verifier28.sol",
24-
"@semaphore-protocol/contracts/verifiers/Verifier29.sol",
25-
"@semaphore-protocol/contracts/verifiers/Verifier30.sol",
26-
"@semaphore-protocol/contracts/verifiers/Verifier31.sol",
27-
"@semaphore-protocol/contracts/verifiers/Verifier32.sol",
10+
"@semaphore-protocol/contracts/base/Pairing.sol",
11+
"@semaphore-protocol/contracts/base/SemaphoreVerifier.sol",
2812
"@semaphore-protocol/contracts/Semaphore.sol"
2913
]
3014

Lines changed: 95 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,114 @@
11
import { poseidon_gencontract as poseidonContract } from "circomlibjs"
2-
import { Contract } from "ethers"
32
import { task, types } from "hardhat/config"
43

54
task("deploy:semaphore", "Deploy a Semaphore contract")
6-
.addParam("verifiers", "Tree depths and verifier addresses", [], types.json)
5+
.addOptionalParam<boolean>("pairing", "Pairing library address", undefined, types.string)
6+
.addOptionalParam<boolean>("semaphoreVerifier", "SemaphoreVerifier contract address", undefined, types.string)
7+
.addOptionalParam<boolean>("poseidon", "Poseidon library address", undefined, types.string)
8+
.addOptionalParam<boolean>(
9+
"incrementalBinaryTree",
10+
"IncrementalBinaryTree library address",
11+
undefined,
12+
types.string
13+
)
714
.addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
8-
.setAction(async ({ logs, verifiers }, { ethers }): Promise<Contract> => {
9-
const poseidonABI = poseidonContract.generateABI(2)
10-
const poseidonBytecode = poseidonContract.createCode(2)
15+
.setAction(
16+
async (
17+
{
18+
logs,
19+
pairing: pairingAddress,
20+
semaphoreVerifier: semaphoreVerifierAddress,
21+
poseidon: poseidonAddress,
22+
incrementalBinaryTree: incrementalBinaryTreeAddress
23+
},
24+
{ ethers }
25+
): Promise<any> => {
26+
if (!semaphoreVerifierAddress) {
27+
if (!pairingAddress) {
28+
const PairingFactory = await ethers.getContractFactory("Pairing")
29+
const pairing = await PairingFactory.deploy()
1130

12-
const [signer] = await ethers.getSigners()
31+
await pairing.deployed()
1332

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

17-
await poseidonLib.deployed()
37+
pairingAddress = pairing.address
38+
}
1839

19-
if (logs) {
20-
console.info(`Poseidon library has been deployed to: ${poseidonLib.address}`)
21-
}
40+
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier", {
41+
libraries: {
42+
Pairing: pairingAddress
43+
}
44+
})
45+
46+
const semaphoreVerifier = await SemaphoreVerifierFactory.deploy()
47+
48+
await semaphoreVerifier.deployed()
2249

23-
const IncrementalBinaryTreeLibFactory = await ethers.getContractFactory("IncrementalBinaryTree", {
24-
libraries: {
25-
PoseidonT3: poseidonLib.address
50+
if (logs) {
51+
console.info(`SemaphoreVerifier contract has been deployed to: ${semaphoreVerifier.address}`)
52+
}
53+
54+
semaphoreVerifierAddress = semaphoreVerifier.address
2655
}
27-
})
28-
const incrementalBinaryTreeLib = await IncrementalBinaryTreeLibFactory.deploy()
2956

30-
await incrementalBinaryTreeLib.deployed()
57+
if (!incrementalBinaryTreeAddress) {
58+
if (!poseidonAddress) {
59+
const poseidonABI = poseidonContract.generateABI(2)
60+
const poseidonBytecode = poseidonContract.createCode(2)
3161

32-
if (logs) {
33-
console.info(`IncrementalBinaryTree library has been deployed to: ${incrementalBinaryTreeLib.address}`)
34-
}
62+
const [signer] = await ethers.getSigners()
63+
64+
const PoseidonFactory = new ethers.ContractFactory(poseidonABI, poseidonBytecode, signer)
65+
const poseidon = await PoseidonFactory.deploy()
66+
67+
await poseidon.deployed()
68+
69+
if (logs) {
70+
console.info(`Poseidon library has been deployed to: ${poseidon.address}`)
71+
}
72+
73+
poseidonAddress = poseidon.address
74+
}
3575

36-
const SemaphoreContractFactory = await ethers.getContractFactory("Semaphore", {
37-
libraries: {
38-
IncrementalBinaryTree: incrementalBinaryTreeLib.address
76+
const IncrementalBinaryTreeFactory = await ethers.getContractFactory("IncrementalBinaryTree", {
77+
libraries: {
78+
PoseidonT3: poseidonAddress
79+
}
80+
})
81+
const incrementalBinaryTree = await IncrementalBinaryTreeFactory.deploy()
82+
83+
await incrementalBinaryTree.deployed()
84+
85+
if (logs) {
86+
console.info(`IncrementalBinaryTree library has been deployed to: ${incrementalBinaryTree.address}`)
87+
}
88+
89+
incrementalBinaryTreeAddress = incrementalBinaryTree.address
3990
}
40-
})
4191

42-
const semaphoreContract = await SemaphoreContractFactory.deploy(verifiers)
92+
const SemaphoreFactory = await ethers.getContractFactory("Semaphore", {
93+
libraries: {
94+
IncrementalBinaryTree: incrementalBinaryTreeAddress
95+
}
96+
})
4397

44-
await semaphoreContract.deployed()
98+
const semaphore = await SemaphoreFactory.deploy(semaphoreVerifierAddress)
4599

46-
if (logs) {
47-
console.info(`Semaphore contract has been deployed to: ${semaphoreContract.address}`)
48-
}
100+
await semaphore.deployed()
49101

50-
return semaphoreContract
51-
})
102+
if (logs) {
103+
console.info(`Semaphore contract has been deployed to: ${semaphore.address}`)
104+
}
105+
106+
return {
107+
semaphore,
108+
pairingAddress,
109+
semaphoreVerifierAddress,
110+
poseidonAddress,
111+
incrementalBinaryTreeAddress
112+
}
113+
}
114+
)

packages/hardhat/src/tasks/deploy-verifier.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)