@semaphore-protocol/cli-template-contracts-hardhat 3.15.1 → 4.0.0-alpha
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/.env.example +1 -0
- package/README.md +2 -2
- package/contracts/Feedback.sol +8 -7
- package/files.tgz +0 -0
- package/hardhat.config.ts +19 -20
- package/package.json +19 -32
- package/tasks/deploy.ts +2 -4
- package/test/Feedback.ts +18 -16
- package/scripts/download-snark-artifacts.ts +0 -24
package/.env.example
CHANGED
package/README.md
CHANGED
|
@@ -44,11 +44,11 @@ cp .env.example .env
|
|
|
44
44
|
3. And deploy your contract.
|
|
45
45
|
|
|
46
46
|
```bash
|
|
47
|
-
yarn deploy --semaphore <semaphore-address> --group <group-id> --network
|
|
47
|
+
yarn deploy --semaphore <semaphore-address> --group <group-id> --network sepolia
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
> **Note**
|
|
51
|
-
> Check the Semaphore contract addresses [here](https://semaphore.pse.dev/
|
|
51
|
+
> Check the Semaphore contract addresses [here](https://docs.semaphore.pse.dev/deployed-contracts#semaphore).
|
|
52
52
|
|
|
53
53
|
> **Warning**
|
|
54
54
|
> The group id is a number!
|
package/contracts/Feedback.sol
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
3
|
|
|
4
4
|
import "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";
|
|
5
5
|
|
|
@@ -8,11 +8,11 @@ contract Feedback {
|
|
|
8
8
|
|
|
9
9
|
uint256 public groupId;
|
|
10
10
|
|
|
11
|
-
constructor(
|
|
12
|
-
semaphore =
|
|
11
|
+
constructor(ISemaphore _semaphore, uint256 _groupId) {
|
|
12
|
+
semaphore = _semaphore;
|
|
13
13
|
groupId = _groupId;
|
|
14
14
|
|
|
15
|
-
semaphore.createGroup(groupId,
|
|
15
|
+
semaphore.createGroup(groupId, address(this));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function joinGroup(uint256 identityCommitment) external {
|
|
@@ -20,11 +20,12 @@ contract Feedback {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function sendFeedback(
|
|
23
|
-
uint256
|
|
23
|
+
uint256 merkleTreeDepth,
|
|
24
24
|
uint256 merkleTreeRoot,
|
|
25
|
-
uint256
|
|
25
|
+
uint256 nullifier,
|
|
26
|
+
uint256 feedback,
|
|
26
27
|
uint256[8] calldata proof
|
|
27
28
|
) external {
|
|
28
|
-
semaphore.
|
|
29
|
+
semaphore.validateProof(groupId, merkleTreeDepth, merkleTreeRoot, nullifier, feedback, groupId, proof);
|
|
29
30
|
}
|
|
30
31
|
}
|
package/files.tgz
CHANGED
|
Binary file
|
package/hardhat.config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import "@nomiclabs/hardhat-ethers"
|
|
2
1
|
import "@nomicfoundation/hardhat-chai-matchers"
|
|
2
|
+
import "@nomicfoundation/hardhat-ethers"
|
|
3
|
+
import "@nomicfoundation/hardhat-verify"
|
|
3
4
|
import "@semaphore-protocol/hardhat"
|
|
4
5
|
import "@typechain/hardhat"
|
|
5
6
|
import { config as dotenvConfig } from "dotenv"
|
|
@@ -7,7 +8,6 @@ import "hardhat-gas-reporter"
|
|
|
7
8
|
import { HardhatUserConfig } from "hardhat/config"
|
|
8
9
|
import { NetworksUserConfig } from "hardhat/types"
|
|
9
10
|
import "solidity-coverage"
|
|
10
|
-
import { config } from "./package.json"
|
|
11
11
|
import "./tasks/deploy"
|
|
12
12
|
|
|
13
13
|
dotenvConfig()
|
|
@@ -21,11 +21,6 @@ function getNetworks(): NetworksUserConfig {
|
|
|
21
21
|
const infuraApiKey = process.env.INFURA_API_KEY
|
|
22
22
|
|
|
23
23
|
return {
|
|
24
|
-
goerli: {
|
|
25
|
-
url: `https://goerli.infura.io/v3/${infuraApiKey}`,
|
|
26
|
-
chainId: 5,
|
|
27
|
-
accounts
|
|
28
|
-
},
|
|
29
24
|
sepolia: {
|
|
30
25
|
url: `https://sepolia.infura.io/v3/${infuraApiKey}`,
|
|
31
26
|
chainId: 11155111,
|
|
@@ -36,13 +31,18 @@ function getNetworks(): NetworksUserConfig {
|
|
|
36
31
|
chainId: 80001,
|
|
37
32
|
accounts
|
|
38
33
|
},
|
|
39
|
-
"optimism-
|
|
40
|
-
url: `https://optimism-
|
|
41
|
-
chainId:
|
|
34
|
+
"optimism-sepolia": {
|
|
35
|
+
url: `https://optimism-sepolia.infura.io/v3/${infuraApiKey}`,
|
|
36
|
+
chainId: 11155420,
|
|
37
|
+
accounts
|
|
38
|
+
},
|
|
39
|
+
"arbitrum-sepolia": {
|
|
40
|
+
url: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
41
|
+
chainId: 421614,
|
|
42
42
|
accounts
|
|
43
43
|
},
|
|
44
44
|
arbitrum: {
|
|
45
|
-
url:
|
|
45
|
+
url: "https://arb1.arbitrum.io/rpc",
|
|
46
46
|
chainId: 42161,
|
|
47
47
|
accounts
|
|
48
48
|
}
|
|
@@ -50,13 +50,7 @@ function getNetworks(): NetworksUserConfig {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const hardhatConfig: HardhatUserConfig = {
|
|
53
|
-
solidity:
|
|
54
|
-
paths: {
|
|
55
|
-
sources: config.paths.contracts,
|
|
56
|
-
tests: config.paths.tests,
|
|
57
|
-
cache: config.paths.cache,
|
|
58
|
-
artifacts: config.paths.build.contracts
|
|
59
|
-
},
|
|
53
|
+
solidity: "0.8.23",
|
|
60
54
|
networks: {
|
|
61
55
|
hardhat: {
|
|
62
56
|
chainId: 1337
|
|
@@ -69,8 +63,13 @@ const hardhatConfig: HardhatUserConfig = {
|
|
|
69
63
|
coinmarketcap: process.env.COINMARKETCAP_API_KEY
|
|
70
64
|
},
|
|
71
65
|
typechain: {
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
target: "ethers-v6"
|
|
67
|
+
},
|
|
68
|
+
etherscan: {
|
|
69
|
+
apiKey: process.env.ETHERSCAN_API_KEY
|
|
70
|
+
},
|
|
71
|
+
sourcify: {
|
|
72
|
+
enabled: true
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/cli-template-contracts-hardhat",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha",
|
|
4
4
|
"description": "Semaphore Hardhat template.",
|
|
5
5
|
"license": "Unlicense",
|
|
6
6
|
"files": [
|
|
@@ -20,9 +20,8 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"dev": "hardhat node & yarn compile && yarn deploy --network localhost",
|
|
22
22
|
"compile": "hardhat compile",
|
|
23
|
-
"download:snark-artifacts": "hardhat run scripts/download-snark-artifacts.ts",
|
|
24
23
|
"deploy": "yarn compile && hardhat deploy",
|
|
25
|
-
"test": "hardhat
|
|
24
|
+
"test": "hardhat test",
|
|
26
25
|
"test:report-gas": "REPORT_GAS=true hardhat test",
|
|
27
26
|
"test:coverage": "hardhat coverage",
|
|
28
27
|
"typechain": "hardhat typechain",
|
|
@@ -31,48 +30,36 @@
|
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@ethersproject/abi": "^5.4.7",
|
|
33
32
|
"@ethersproject/providers": "^5.4.7",
|
|
34
|
-
"@nomicfoundation/hardhat-chai-matchers": "^
|
|
33
|
+
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
|
|
34
|
+
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
|
35
35
|
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
|
36
|
-
"@nomicfoundation/hardhat-toolbox": "^
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@semaphore-protocol/
|
|
40
|
-
"@semaphore-protocol/
|
|
41
|
-
"@semaphore-protocol/
|
|
42
|
-
"@
|
|
43
|
-
"@typechain/
|
|
44
|
-
"@typechain/hardhat": "^6.1.2",
|
|
36
|
+
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
|
|
37
|
+
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
|
38
|
+
"@semaphore-protocol/group": "4.0.0-alpha",
|
|
39
|
+
"@semaphore-protocol/hardhat": "4.0.0-alpha",
|
|
40
|
+
"@semaphore-protocol/identity": "4.0.0-alpha",
|
|
41
|
+
"@semaphore-protocol/proof": "4.0.0-alpha",
|
|
42
|
+
"@typechain/ethers-v6": "^0.5.0",
|
|
43
|
+
"@typechain/hardhat": "^9.0.0",
|
|
45
44
|
"@types/chai": "^4.2.0",
|
|
46
|
-
"@types/download": "^8.0.1",
|
|
47
45
|
"@types/mocha": "^9.1.0",
|
|
48
|
-
"@types/node": "
|
|
46
|
+
"@types/node": "^20",
|
|
49
47
|
"chai": "^4.2.0",
|
|
50
48
|
"dotenv": "^16.0.3",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"hardhat": "^2.11.0",
|
|
49
|
+
"ethers": "^6.4.0",
|
|
50
|
+
"hardhat": "^2.19.4",
|
|
54
51
|
"hardhat-gas-reporter": "^1.0.8",
|
|
55
52
|
"solidity-coverage": "^0.8.1",
|
|
56
|
-
"ts-node": "
|
|
57
|
-
"typechain": "^8.
|
|
58
|
-
"typescript": "
|
|
53
|
+
"ts-node": "^10.9.2",
|
|
54
|
+
"typechain": "^8.3.0",
|
|
55
|
+
"typescript": "^5.3.3"
|
|
59
56
|
},
|
|
60
57
|
"dependencies": {
|
|
61
|
-
"@semaphore-protocol/contracts": "
|
|
58
|
+
"@semaphore-protocol/contracts": "4.0.0-alpha"
|
|
62
59
|
},
|
|
63
60
|
"config": {
|
|
64
61
|
"solidity": {
|
|
65
62
|
"version": "0.8.4"
|
|
66
|
-
},
|
|
67
|
-
"paths": {
|
|
68
|
-
"contracts": "./contracts",
|
|
69
|
-
"tests": "./test",
|
|
70
|
-
"cache": "./cache",
|
|
71
|
-
"build": {
|
|
72
|
-
"snark-artifacts": "./build/snark-artifacts",
|
|
73
|
-
"contracts": "./build/contracts",
|
|
74
|
-
"typechain": "./build/typechain"
|
|
75
|
-
}
|
|
76
63
|
}
|
|
77
64
|
}
|
|
78
65
|
}
|
package/tasks/deploy.ts
CHANGED
|
@@ -10,7 +10,7 @@ task("deploy", "Deploy a Feedback contract")
|
|
|
10
10
|
logs
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
semaphoreAddress = semaphore.
|
|
13
|
+
semaphoreAddress = await semaphore.getAddress()
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
if (!groupId) {
|
|
@@ -21,10 +21,8 @@ task("deploy", "Deploy a Feedback contract")
|
|
|
21
21
|
|
|
22
22
|
const feedbackContract = await FeedbackFactory.deploy(semaphoreAddress, groupId)
|
|
23
23
|
|
|
24
|
-
await feedbackContract.deployed()
|
|
25
|
-
|
|
26
24
|
if (logs) {
|
|
27
|
-
console.info(`Feedback contract has been deployed to: ${feedbackContract.
|
|
25
|
+
console.info(`Feedback contract has been deployed to: ${await feedbackContract.getAddress()}`)
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
return feedbackContract
|
package/test/Feedback.ts
CHANGED
|
@@ -2,18 +2,17 @@ import { Group } from "@semaphore-protocol/group"
|
|
|
2
2
|
import { Identity } from "@semaphore-protocol/identity"
|
|
3
3
|
import { generateProof } from "@semaphore-protocol/proof"
|
|
4
4
|
import { expect } from "chai"
|
|
5
|
-
import {
|
|
5
|
+
import { encodeBytes32String } from "ethers"
|
|
6
6
|
import { run } from "hardhat"
|
|
7
7
|
// @ts-ignore: typechain folder will be generated after contracts compilation
|
|
8
8
|
import { Feedback } from "../build/typechain"
|
|
9
|
-
import { config } from "../package.json"
|
|
10
9
|
|
|
11
10
|
describe("Feedback", () => {
|
|
12
11
|
let feedbackContract: Feedback
|
|
13
12
|
let semaphoreContract: string
|
|
14
13
|
|
|
15
14
|
const groupId = "42"
|
|
16
|
-
const group = new Group(
|
|
15
|
+
const group = new Group()
|
|
17
16
|
const users: Identity[] = []
|
|
18
17
|
|
|
19
18
|
before(async () => {
|
|
@@ -21,7 +20,7 @@ describe("Feedback", () => {
|
|
|
21
20
|
logs: false
|
|
22
21
|
})
|
|
23
22
|
|
|
24
|
-
feedbackContract = await run("deploy", { logs: false, group: groupId, semaphore: semaphore.
|
|
23
|
+
feedbackContract = await run("deploy", { logs: false, group: groupId, semaphore: await semaphore.getAddress() })
|
|
25
24
|
semaphoreContract = semaphore
|
|
26
25
|
|
|
27
26
|
users.push(new Identity())
|
|
@@ -43,27 +42,30 @@ describe("Feedback", () => {
|
|
|
43
42
|
})
|
|
44
43
|
|
|
45
44
|
describe("# sendFeedback", () => {
|
|
46
|
-
const wasmFilePath = `${config.paths.build["snark-artifacts"]}/semaphore.wasm`
|
|
47
|
-
const zkeyFilePath = `${config.paths.build["snark-artifacts"]}/semaphore.zkey`
|
|
48
|
-
|
|
49
45
|
it("Should allow users to send feedback anonymously", async () => {
|
|
50
|
-
const feedback =
|
|
46
|
+
const feedback = encodeBytes32String("Hello World")
|
|
51
47
|
|
|
52
|
-
const fullProof = await generateProof(users[1], group,
|
|
53
|
-
wasmFilePath,
|
|
54
|
-
zkeyFilePath
|
|
55
|
-
})
|
|
48
|
+
const fullProof = await generateProof(users[1], group, feedback, groupId)
|
|
56
49
|
|
|
57
50
|
const transaction = feedbackContract.sendFeedback(
|
|
58
|
-
|
|
51
|
+
fullProof.merkleTreeDepth,
|
|
59
52
|
fullProof.merkleTreeRoot,
|
|
60
|
-
fullProof.
|
|
53
|
+
fullProof.nullifier,
|
|
54
|
+
feedback,
|
|
61
55
|
fullProof.proof
|
|
62
56
|
)
|
|
63
57
|
|
|
64
58
|
await expect(transaction)
|
|
65
|
-
.to.emit(semaphoreContract, "
|
|
66
|
-
.withArgs(
|
|
59
|
+
.to.emit(semaphoreContract, "ProofValidated")
|
|
60
|
+
.withArgs(
|
|
61
|
+
groupId,
|
|
62
|
+
fullProof.merkleTreeDepth,
|
|
63
|
+
fullProof.merkleTreeRoot,
|
|
64
|
+
fullProof.nullifier,
|
|
65
|
+
fullProof.message,
|
|
66
|
+
groupId,
|
|
67
|
+
fullProof.proof
|
|
68
|
+
)
|
|
67
69
|
})
|
|
68
70
|
})
|
|
69
71
|
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import download from "download"
|
|
2
|
-
import fs from "fs"
|
|
3
|
-
import { config } from "../package.json"
|
|
4
|
-
|
|
5
|
-
async function main() {
|
|
6
|
-
const snarkArtifactsPath = config.paths.build["snark-artifacts"]
|
|
7
|
-
const url = `http://www.trusted-setup-pse.org/semaphore/${20}`
|
|
8
|
-
|
|
9
|
-
if (!fs.existsSync(snarkArtifactsPath)) {
|
|
10
|
-
fs.mkdirSync(snarkArtifactsPath, { recursive: true })
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!fs.existsSync(`${snarkArtifactsPath}/semaphore.zkey`)) {
|
|
14
|
-
await download(`${url}/semaphore.wasm`, snarkArtifactsPath)
|
|
15
|
-
await download(`${url}/semaphore.zkey`, snarkArtifactsPath)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
main()
|
|
20
|
-
.then(() => process.exit(0))
|
|
21
|
-
.catch((error) => {
|
|
22
|
-
console.error(error)
|
|
23
|
-
process.exit(1)
|
|
24
|
-
})
|