@semaphore-protocol/hardhat 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -0
- package/dist/index.mjs +194 -0
- package/dist/index.node.js +196 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/tasks/deploy-semaphore.d.ts +1 -0
- package/dist/types/tasks/deploy-verifier.d.ts +1 -0
- package/package.json +46 -0
- package/src/index.ts +34 -0
- package/src/tasks/deploy-semaphore.ts +51 -0
- package/src/tasks/deploy-verifier.ts +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center">
|
|
3
|
+
Semaphore Hardhat plugin
|
|
4
|
+
</h1>
|
|
5
|
+
<p align="center">A Semaphore Hardhat plugin to deploy verifiers and Semaphore contracts.</p>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://github.com/semaphore-protocol">
|
|
10
|
+
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
|
13
|
+
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/@semaphore-protocol/hardhat">
|
|
16
|
+
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/hardhat?style=flat-square" />
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://npmjs.org/package/@semaphore-protocol/hardhat">
|
|
19
|
+
<img alt="Downloads" src="https://img.shields.io/npm/dm/@semaphore-protocol/hardhat.svg?style=flat-square" />
|
|
20
|
+
</a>
|
|
21
|
+
<a href="https://eslint.org/">
|
|
22
|
+
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" />
|
|
23
|
+
</a>
|
|
24
|
+
<a href="https://prettier.io/">
|
|
25
|
+
<img alt="Code style prettier" src="https://img.shields.io/badge/code%20style-prettier-f8bc45?style=flat-square&logo=prettier" />
|
|
26
|
+
</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<div align="center">
|
|
30
|
+
<h4>
|
|
31
|
+
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/CONTRIBUTING.md">
|
|
32
|
+
👥 Contributing
|
|
33
|
+
</a>
|
|
34
|
+
<span> | </span>
|
|
35
|
+
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/CODE_OF_CONDUCT.md">
|
|
36
|
+
🤝 Code of conduct
|
|
37
|
+
</a>
|
|
38
|
+
<span> | </span>
|
|
39
|
+
<a href="https://github.com/semaphore-protocol/semaphore/contribute">
|
|
40
|
+
🔎 Issues
|
|
41
|
+
</a>
|
|
42
|
+
<span> | </span>
|
|
43
|
+
<a href="https://discord.gg/6mSdGHnstH">
|
|
44
|
+
🗣️ Chat & Support
|
|
45
|
+
</a>
|
|
46
|
+
</h4>
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
| This Hardhat plugin provides two simple tasks that can be used to deploy verifiers and Semaphore contracts without any additional configuration. |
|
|
50
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
51
|
+
|
|
52
|
+
## 🛠 Install
|
|
53
|
+
|
|
54
|
+
### npm or yarn
|
|
55
|
+
|
|
56
|
+
Install the `@semaphore-protocol/hardhat` package with npm:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm i @semaphore-protocol/hardhat
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
or yarn:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
yarn add @semaphore-protocol/hardhat
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 📜 Usage
|
|
69
|
+
|
|
70
|
+
Import the plugin in your `hardhat.config.ts` file:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import "@semaphore-protocol/hardhat"
|
|
74
|
+
import "./tasks/deploy"
|
|
75
|
+
|
|
76
|
+
const hardhatConfig: HardhatUserConfig = {
|
|
77
|
+
solidity: "0.8.4"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default hardhatConfig
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
And use its tasks to create your own `deploy` task and deploy your contract with a Semaphore address.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { task, types } from "hardhat/config"
|
|
87
|
+
|
|
88
|
+
task("deploy", "Deploy a Greeter contract")
|
|
89
|
+
.addOptionalParam("logs", "Print the logs", true, types.boolean)
|
|
90
|
+
.setAction(async ({ logs }, { ethers, run }) => {
|
|
91
|
+
const { address: verifierAddress } = await run("deploy:verifier", { logs, merkleTreeDepth: 20 })
|
|
92
|
+
|
|
93
|
+
const { address: semaphoreAddress } = await run("deploy:semaphore", {
|
|
94
|
+
logs,
|
|
95
|
+
verifiers: [
|
|
96
|
+
{
|
|
97
|
+
merkleTreeDepth: 20,
|
|
98
|
+
contractAddress: verifierAddress
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const Greeter = await ethers.getContractFactory("Greeter")
|
|
104
|
+
|
|
105
|
+
const greeter = await Greeter.deploy(semaphoreAddress)
|
|
106
|
+
|
|
107
|
+
await greeter.deployed()
|
|
108
|
+
|
|
109
|
+
if (logs) {
|
|
110
|
+
console.log(`Greeter contract has been deployed to: ${greeter.address}`)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return greeter
|
|
114
|
+
})
|
|
115
|
+
```
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/hardhat
|
|
3
|
+
* @version 0.1.0
|
|
4
|
+
* @file A Semaphore Hardhat plugin to deploy verifiers and Semaphore contract.
|
|
5
|
+
* @copyright Ethereum Foundation 2022
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/hardhat}
|
|
8
|
+
*/
|
|
9
|
+
import { task, types, extendConfig } from 'hardhat/config';
|
|
10
|
+
import 'hardhat-dependency-compiler';
|
|
11
|
+
import '@nomiclabs/hardhat-ethers';
|
|
12
|
+
import { poseidon_gencontract } from 'circomlibjs';
|
|
13
|
+
|
|
14
|
+
/******************************************************************************
|
|
15
|
+
Copyright (c) Microsoft Corporation.
|
|
16
|
+
|
|
17
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
18
|
+
purpose with or without fee is hereby granted.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
21
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
22
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
23
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
24
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
25
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
26
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
27
|
+
***************************************************************************** */
|
|
28
|
+
|
|
29
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function __generator(thisArg, body) {
|
|
40
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
41
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
42
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
43
|
+
function step(op) {
|
|
44
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
45
|
+
while (_) try {
|
|
46
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
47
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
48
|
+
switch (op[0]) {
|
|
49
|
+
case 0: case 1: t = op; break;
|
|
50
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
51
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
52
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
53
|
+
default:
|
|
54
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
55
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
56
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
57
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
58
|
+
if (t[2]) _.ops.pop();
|
|
59
|
+
_.trys.pop(); continue;
|
|
60
|
+
}
|
|
61
|
+
op = body.call(thisArg, _);
|
|
62
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
63
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function __spreadArray(to, from, pack) {
|
|
68
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
69
|
+
if (ar || !(i in from)) {
|
|
70
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
71
|
+
ar[i] = from[i];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
78
|
+
.addParam("verifiers", "Tree depths and verifier addresses", [], types.json)
|
|
79
|
+
.addOptionalParam("logs", "Print the logs", true, types.boolean)
|
|
80
|
+
.setAction(function (_a, _b) {
|
|
81
|
+
var logs = _a.logs, verifiers = _a.verifiers;
|
|
82
|
+
var ethers = _b.ethers;
|
|
83
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
84
|
+
var poseidonABI, poseidonBytecode, signer, PoseidonLibFactory, poseidonLib, IncrementalBinaryTreeLibFactory, incrementalBinaryTreeLib, SemaphoreContractFactory, semaphoreContract;
|
|
85
|
+
return __generator(this, function (_c) {
|
|
86
|
+
switch (_c.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
poseidonABI = poseidon_gencontract.generateABI(2);
|
|
89
|
+
poseidonBytecode = poseidon_gencontract.createCode(2);
|
|
90
|
+
return [4 /*yield*/, ethers.getSigners()];
|
|
91
|
+
case 1:
|
|
92
|
+
signer = (_c.sent())[0];
|
|
93
|
+
PoseidonLibFactory = new ethers.ContractFactory(poseidonABI, poseidonBytecode, signer);
|
|
94
|
+
return [4 /*yield*/, PoseidonLibFactory.deploy()];
|
|
95
|
+
case 2:
|
|
96
|
+
poseidonLib = _c.sent();
|
|
97
|
+
return [4 /*yield*/, poseidonLib.deployed()];
|
|
98
|
+
case 3:
|
|
99
|
+
_c.sent();
|
|
100
|
+
if (logs) {
|
|
101
|
+
console.info("Poseidon library has been deployed to: ".concat(poseidonLib.address));
|
|
102
|
+
}
|
|
103
|
+
return [4 /*yield*/, ethers.getContractFactory("IncrementalBinaryTree", {
|
|
104
|
+
libraries: {
|
|
105
|
+
PoseidonT3: poseidonLib.address
|
|
106
|
+
}
|
|
107
|
+
})];
|
|
108
|
+
case 4:
|
|
109
|
+
IncrementalBinaryTreeLibFactory = _c.sent();
|
|
110
|
+
return [4 /*yield*/, IncrementalBinaryTreeLibFactory.deploy()];
|
|
111
|
+
case 5:
|
|
112
|
+
incrementalBinaryTreeLib = _c.sent();
|
|
113
|
+
return [4 /*yield*/, incrementalBinaryTreeLib.deployed()];
|
|
114
|
+
case 6:
|
|
115
|
+
_c.sent();
|
|
116
|
+
if (logs) {
|
|
117
|
+
console.info("IncrementalBinaryTree library has been deployed to: ".concat(incrementalBinaryTreeLib.address));
|
|
118
|
+
}
|
|
119
|
+
return [4 /*yield*/, ethers.getContractFactory("Semaphore", {
|
|
120
|
+
libraries: {
|
|
121
|
+
IncrementalBinaryTree: incrementalBinaryTreeLib.address
|
|
122
|
+
}
|
|
123
|
+
})];
|
|
124
|
+
case 7:
|
|
125
|
+
SemaphoreContractFactory = _c.sent();
|
|
126
|
+
return [4 /*yield*/, SemaphoreContractFactory.deploy(verifiers)];
|
|
127
|
+
case 8:
|
|
128
|
+
semaphoreContract = _c.sent();
|
|
129
|
+
return [4 /*yield*/, semaphoreContract.deployed()];
|
|
130
|
+
case 9:
|
|
131
|
+
_c.sent();
|
|
132
|
+
if (logs) {
|
|
133
|
+
console.info("Semaphore contract has been deployed to: ".concat(semaphoreContract.address));
|
|
134
|
+
}
|
|
135
|
+
return [2 /*return*/, semaphoreContract];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
task("deploy:verifier", "Deploy a Verifier contract")
|
|
142
|
+
.addParam("merkleTreeDepth", "Merkle tree depth", undefined, types.int)
|
|
143
|
+
.addOptionalParam("logs", "Print the logs", true, types.boolean)
|
|
144
|
+
.setAction(function (_a, _b) {
|
|
145
|
+
var merkleTreeDepth = _a.merkleTreeDepth, logs = _a.logs;
|
|
146
|
+
var ethers = _b.ethers;
|
|
147
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
148
|
+
var VerifierContractFactory, verifierContract;
|
|
149
|
+
return __generator(this, function (_c) {
|
|
150
|
+
switch (_c.label) {
|
|
151
|
+
case 0: return [4 /*yield*/, ethers.getContractFactory("Verifier".concat(merkleTreeDepth))];
|
|
152
|
+
case 1:
|
|
153
|
+
VerifierContractFactory = _c.sent();
|
|
154
|
+
return [4 /*yield*/, VerifierContractFactory.deploy()];
|
|
155
|
+
case 2:
|
|
156
|
+
verifierContract = _c.sent();
|
|
157
|
+
return [4 /*yield*/, verifierContract.deployed()];
|
|
158
|
+
case 3:
|
|
159
|
+
_c.sent();
|
|
160
|
+
if (logs) {
|
|
161
|
+
console.info("Verifier".concat(merkleTreeDepth, " contract has been deployed to: ").concat(verifierContract.address));
|
|
162
|
+
}
|
|
163
|
+
return [2 /*return*/, verifierContract];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
extendConfig(function (config, userConfig) {
|
|
170
|
+
var _a;
|
|
171
|
+
config.dependencyCompiler.paths = [
|
|
172
|
+
"@semaphore-protocol/contracts/verifiers/Verifier16.sol",
|
|
173
|
+
"@semaphore-protocol/contracts/verifiers/Verifier17.sol",
|
|
174
|
+
"@semaphore-protocol/contracts/verifiers/Verifier18.sol",
|
|
175
|
+
"@semaphore-protocol/contracts/verifiers/Verifier19.sol",
|
|
176
|
+
"@semaphore-protocol/contracts/verifiers/Verifier20.sol",
|
|
177
|
+
"@semaphore-protocol/contracts/verifiers/Verifier21.sol",
|
|
178
|
+
"@semaphore-protocol/contracts/verifiers/Verifier22.sol",
|
|
179
|
+
"@semaphore-protocol/contracts/verifiers/Verifier23.sol",
|
|
180
|
+
"@semaphore-protocol/contracts/verifiers/Verifier24.sol",
|
|
181
|
+
"@semaphore-protocol/contracts/verifiers/Verifier25.sol",
|
|
182
|
+
"@semaphore-protocol/contracts/verifiers/Verifier26.sol",
|
|
183
|
+
"@semaphore-protocol/contracts/verifiers/Verifier27.sol",
|
|
184
|
+
"@semaphore-protocol/contracts/verifiers/Verifier28.sol",
|
|
185
|
+
"@semaphore-protocol/contracts/verifiers/Verifier29.sol",
|
|
186
|
+
"@semaphore-protocol/contracts/verifiers/Verifier30.sol",
|
|
187
|
+
"@semaphore-protocol/contracts/verifiers/Verifier31.sol",
|
|
188
|
+
"@semaphore-protocol/contracts/verifiers/Verifier32.sol",
|
|
189
|
+
"@semaphore-protocol/contracts/Semaphore.sol"
|
|
190
|
+
];
|
|
191
|
+
if ((_a = userConfig.dependencyCompiler) === null || _a === void 0 ? void 0 : _a.paths) {
|
|
192
|
+
config.dependencyCompiler.paths = __spreadArray(__spreadArray([], config.dependencyCompiler.paths, true), userConfig.dependencyCompiler.paths, true);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @semaphore-protocol/hardhat
|
|
3
|
+
* @version 0.1.0
|
|
4
|
+
* @file A Semaphore Hardhat plugin to deploy verifiers and Semaphore contract.
|
|
5
|
+
* @copyright Ethereum Foundation 2022
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/hardhat}
|
|
8
|
+
*/
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var config = require('hardhat/config');
|
|
12
|
+
require('hardhat-dependency-compiler');
|
|
13
|
+
require('@nomiclabs/hardhat-ethers');
|
|
14
|
+
var circomlibjs = require('circomlibjs');
|
|
15
|
+
|
|
16
|
+
/******************************************************************************
|
|
17
|
+
Copyright (c) Microsoft Corporation.
|
|
18
|
+
|
|
19
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
20
|
+
purpose with or without fee is hereby granted.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
23
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
24
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
25
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
26
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
27
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
29
|
+
***************************************************************************** */
|
|
30
|
+
|
|
31
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
32
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __generator(thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (_) try {
|
|
48
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function __spreadArray(to, from, pack) {
|
|
70
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
71
|
+
if (ar || !(i in from)) {
|
|
72
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
73
|
+
ar[i] = from[i];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
config.task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
80
|
+
.addParam("verifiers", "Tree depths and verifier addresses", [], config.types.json)
|
|
81
|
+
.addOptionalParam("logs", "Print the logs", true, config.types.boolean)
|
|
82
|
+
.setAction(function (_a, _b) {
|
|
83
|
+
var logs = _a.logs, verifiers = _a.verifiers;
|
|
84
|
+
var ethers = _b.ethers;
|
|
85
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
+
var poseidonABI, poseidonBytecode, signer, PoseidonLibFactory, poseidonLib, IncrementalBinaryTreeLibFactory, incrementalBinaryTreeLib, SemaphoreContractFactory, semaphoreContract;
|
|
87
|
+
return __generator(this, function (_c) {
|
|
88
|
+
switch (_c.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
poseidonABI = circomlibjs.poseidon_gencontract.generateABI(2);
|
|
91
|
+
poseidonBytecode = circomlibjs.poseidon_gencontract.createCode(2);
|
|
92
|
+
return [4 /*yield*/, ethers.getSigners()];
|
|
93
|
+
case 1:
|
|
94
|
+
signer = (_c.sent())[0];
|
|
95
|
+
PoseidonLibFactory = new ethers.ContractFactory(poseidonABI, poseidonBytecode, signer);
|
|
96
|
+
return [4 /*yield*/, PoseidonLibFactory.deploy()];
|
|
97
|
+
case 2:
|
|
98
|
+
poseidonLib = _c.sent();
|
|
99
|
+
return [4 /*yield*/, poseidonLib.deployed()];
|
|
100
|
+
case 3:
|
|
101
|
+
_c.sent();
|
|
102
|
+
if (logs) {
|
|
103
|
+
console.info("Poseidon library has been deployed to: ".concat(poseidonLib.address));
|
|
104
|
+
}
|
|
105
|
+
return [4 /*yield*/, ethers.getContractFactory("IncrementalBinaryTree", {
|
|
106
|
+
libraries: {
|
|
107
|
+
PoseidonT3: poseidonLib.address
|
|
108
|
+
}
|
|
109
|
+
})];
|
|
110
|
+
case 4:
|
|
111
|
+
IncrementalBinaryTreeLibFactory = _c.sent();
|
|
112
|
+
return [4 /*yield*/, IncrementalBinaryTreeLibFactory.deploy()];
|
|
113
|
+
case 5:
|
|
114
|
+
incrementalBinaryTreeLib = _c.sent();
|
|
115
|
+
return [4 /*yield*/, incrementalBinaryTreeLib.deployed()];
|
|
116
|
+
case 6:
|
|
117
|
+
_c.sent();
|
|
118
|
+
if (logs) {
|
|
119
|
+
console.info("IncrementalBinaryTree library has been deployed to: ".concat(incrementalBinaryTreeLib.address));
|
|
120
|
+
}
|
|
121
|
+
return [4 /*yield*/, ethers.getContractFactory("Semaphore", {
|
|
122
|
+
libraries: {
|
|
123
|
+
IncrementalBinaryTree: incrementalBinaryTreeLib.address
|
|
124
|
+
}
|
|
125
|
+
})];
|
|
126
|
+
case 7:
|
|
127
|
+
SemaphoreContractFactory = _c.sent();
|
|
128
|
+
return [4 /*yield*/, SemaphoreContractFactory.deploy(verifiers)];
|
|
129
|
+
case 8:
|
|
130
|
+
semaphoreContract = _c.sent();
|
|
131
|
+
return [4 /*yield*/, semaphoreContract.deployed()];
|
|
132
|
+
case 9:
|
|
133
|
+
_c.sent();
|
|
134
|
+
if (logs) {
|
|
135
|
+
console.info("Semaphore contract has been deployed to: ".concat(semaphoreContract.address));
|
|
136
|
+
}
|
|
137
|
+
return [2 /*return*/, semaphoreContract];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
config.task("deploy:verifier", "Deploy a Verifier contract")
|
|
144
|
+
.addParam("merkleTreeDepth", "Merkle tree depth", undefined, config.types.int)
|
|
145
|
+
.addOptionalParam("logs", "Print the logs", true, config.types.boolean)
|
|
146
|
+
.setAction(function (_a, _b) {
|
|
147
|
+
var merkleTreeDepth = _a.merkleTreeDepth, logs = _a.logs;
|
|
148
|
+
var ethers = _b.ethers;
|
|
149
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
150
|
+
var VerifierContractFactory, verifierContract;
|
|
151
|
+
return __generator(this, function (_c) {
|
|
152
|
+
switch (_c.label) {
|
|
153
|
+
case 0: return [4 /*yield*/, ethers.getContractFactory("Verifier".concat(merkleTreeDepth))];
|
|
154
|
+
case 1:
|
|
155
|
+
VerifierContractFactory = _c.sent();
|
|
156
|
+
return [4 /*yield*/, VerifierContractFactory.deploy()];
|
|
157
|
+
case 2:
|
|
158
|
+
verifierContract = _c.sent();
|
|
159
|
+
return [4 /*yield*/, verifierContract.deployed()];
|
|
160
|
+
case 3:
|
|
161
|
+
_c.sent();
|
|
162
|
+
if (logs) {
|
|
163
|
+
console.info("Verifier".concat(merkleTreeDepth, " contract has been deployed to: ").concat(verifierContract.address));
|
|
164
|
+
}
|
|
165
|
+
return [2 /*return*/, verifierContract];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
config.extendConfig(function (config, userConfig) {
|
|
172
|
+
var _a;
|
|
173
|
+
config.dependencyCompiler.paths = [
|
|
174
|
+
"@semaphore-protocol/contracts/verifiers/Verifier16.sol",
|
|
175
|
+
"@semaphore-protocol/contracts/verifiers/Verifier17.sol",
|
|
176
|
+
"@semaphore-protocol/contracts/verifiers/Verifier18.sol",
|
|
177
|
+
"@semaphore-protocol/contracts/verifiers/Verifier19.sol",
|
|
178
|
+
"@semaphore-protocol/contracts/verifiers/Verifier20.sol",
|
|
179
|
+
"@semaphore-protocol/contracts/verifiers/Verifier21.sol",
|
|
180
|
+
"@semaphore-protocol/contracts/verifiers/Verifier22.sol",
|
|
181
|
+
"@semaphore-protocol/contracts/verifiers/Verifier23.sol",
|
|
182
|
+
"@semaphore-protocol/contracts/verifiers/Verifier24.sol",
|
|
183
|
+
"@semaphore-protocol/contracts/verifiers/Verifier25.sol",
|
|
184
|
+
"@semaphore-protocol/contracts/verifiers/Verifier26.sol",
|
|
185
|
+
"@semaphore-protocol/contracts/verifiers/Verifier27.sol",
|
|
186
|
+
"@semaphore-protocol/contracts/verifiers/Verifier28.sol",
|
|
187
|
+
"@semaphore-protocol/contracts/verifiers/Verifier29.sol",
|
|
188
|
+
"@semaphore-protocol/contracts/verifiers/Verifier30.sol",
|
|
189
|
+
"@semaphore-protocol/contracts/verifiers/Verifier31.sol",
|
|
190
|
+
"@semaphore-protocol/contracts/verifiers/Verifier32.sol",
|
|
191
|
+
"@semaphore-protocol/contracts/Semaphore.sol"
|
|
192
|
+
];
|
|
193
|
+
if ((_a = userConfig.dependencyCompiler) === null || _a === void 0 ? void 0 : _a.paths) {
|
|
194
|
+
config.dependencyCompiler.paths = __spreadArray(__spreadArray([], config.dependencyCompiler.paths, true), userConfig.dependencyCompiler.paths, true);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@semaphore-protocol/hardhat",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A Semaphore Hardhat plugin to deploy verifiers and Semaphore contract.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.node.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"import": "./dist/index.mjs",
|
|
9
|
+
"require": "./dist/index.node.js"
|
|
10
|
+
},
|
|
11
|
+
"types": "dist/types/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/",
|
|
14
|
+
"src/",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"repository": "https://github.com/semaphore-protocol/semaphore",
|
|
19
|
+
"homepage": "https://github.com/semaphore-protocol/semaphore/tree/main/packages/hardhat",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/semaphore-protocol/semaphore.git/issues"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
|
25
|
+
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
|
26
|
+
"prepublishOnly": "yarn build"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"hardhat": "^2.0.0",
|
|
33
|
+
"rollup-plugin-cleanup": "^3.2.1",
|
|
34
|
+
"rollup-plugin-typescript2": "^0.31.2"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"hardhat": "^2.0.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@nomiclabs/hardhat-ethers": "^2.1.1",
|
|
41
|
+
"@semaphore-protocol/contracts": "^2.5.0",
|
|
42
|
+
"circomlibjs": "^0.0.8",
|
|
43
|
+
"ethers": "^5.7.1",
|
|
44
|
+
"hardhat-dependency-compiler": "^1.1.3"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { extendConfig } from "hardhat/config"
|
|
2
|
+
import { HardhatConfig, HardhatUserConfig } from "hardhat/types"
|
|
3
|
+
|
|
4
|
+
import "hardhat-dependency-compiler"
|
|
5
|
+
import "@nomiclabs/hardhat-ethers"
|
|
6
|
+
import "./tasks/deploy-semaphore"
|
|
7
|
+
import "./tasks/deploy-verifier"
|
|
8
|
+
|
|
9
|
+
extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
|
|
10
|
+
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",
|
|
28
|
+
"@semaphore-protocol/contracts/Semaphore.sol"
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
if (userConfig.dependencyCompiler?.paths) {
|
|
32
|
+
config.dependencyCompiler.paths = [...config.dependencyCompiler.paths, ...userConfig.dependencyCompiler.paths]
|
|
33
|
+
}
|
|
34
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { poseidon_gencontract as poseidonContract } from "circomlibjs"
|
|
2
|
+
import { Contract } from "ethers"
|
|
3
|
+
import { task, types } from "hardhat/config"
|
|
4
|
+
|
|
5
|
+
task("deploy:semaphore", "Deploy a Semaphore contract")
|
|
6
|
+
.addParam("verifiers", "Tree depths and verifier addresses", [], types.json)
|
|
7
|
+
.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)
|
|
11
|
+
|
|
12
|
+
const [signer] = await ethers.getSigners()
|
|
13
|
+
|
|
14
|
+
const PoseidonLibFactory = new ethers.ContractFactory(poseidonABI, poseidonBytecode, signer)
|
|
15
|
+
const poseidonLib = await PoseidonLibFactory.deploy()
|
|
16
|
+
|
|
17
|
+
await poseidonLib.deployed()
|
|
18
|
+
|
|
19
|
+
if (logs) {
|
|
20
|
+
console.info(`Poseidon library has been deployed to: ${poseidonLib.address}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const IncrementalBinaryTreeLibFactory = await ethers.getContractFactory("IncrementalBinaryTree", {
|
|
24
|
+
libraries: {
|
|
25
|
+
PoseidonT3: poseidonLib.address
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
const incrementalBinaryTreeLib = await IncrementalBinaryTreeLibFactory.deploy()
|
|
29
|
+
|
|
30
|
+
await incrementalBinaryTreeLib.deployed()
|
|
31
|
+
|
|
32
|
+
if (logs) {
|
|
33
|
+
console.info(`IncrementalBinaryTree library has been deployed to: ${incrementalBinaryTreeLib.address}`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const SemaphoreContractFactory = await ethers.getContractFactory("Semaphore", {
|
|
37
|
+
libraries: {
|
|
38
|
+
IncrementalBinaryTree: incrementalBinaryTreeLib.address
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const semaphoreContract = await SemaphoreContractFactory.deploy(verifiers)
|
|
43
|
+
|
|
44
|
+
await semaphoreContract.deployed()
|
|
45
|
+
|
|
46
|
+
if (logs) {
|
|
47
|
+
console.info(`Semaphore contract has been deployed to: ${semaphoreContract.address}`)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return semaphoreContract
|
|
51
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Contract } from "ethers"
|
|
2
|
+
import { task, types } from "hardhat/config"
|
|
3
|
+
|
|
4
|
+
task("deploy:verifier", "Deploy a Verifier contract")
|
|
5
|
+
.addParam<number>("merkleTreeDepth", "Merkle tree depth", undefined, types.int)
|
|
6
|
+
.addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
|
|
7
|
+
.setAction(async ({ merkleTreeDepth, logs }, { ethers }): Promise<Contract> => {
|
|
8
|
+
const VerifierContractFactory = await ethers.getContractFactory(`Verifier${merkleTreeDepth}`)
|
|
9
|
+
|
|
10
|
+
const verifierContract = await VerifierContractFactory.deploy()
|
|
11
|
+
|
|
12
|
+
await verifierContract.deployed()
|
|
13
|
+
|
|
14
|
+
if (logs) {
|
|
15
|
+
console.info(`Verifier${merkleTreeDepth} contract has been deployed to: ${verifierContract.address}`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return verifierContract
|
|
19
|
+
})
|