@semaphore-protocol/cli-template-contracts-hardhat 3.15.2 → 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 CHANGED
@@ -1,4 +1,5 @@
1
1
  INFURA_API_KEY=
2
2
  ETHEREUM_PRIVATE_KEY=
3
3
  REPORT_GAS=false
4
+ ETHERSCAN_API_KEY=
4
5
  COINMARKETCAP_API_KEY=
package/README.md CHANGED
@@ -44,7 +44,7 @@ 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 goerli
47
+ yarn deploy --semaphore <semaphore-address> --group <group-id> --network sepolia
48
48
  ```
49
49
 
50
50
  > **Note**
@@ -1,5 +1,5 @@
1
1
  //SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.4;
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(address semaphoreAddress, uint256 _groupId) {
12
- semaphore = ISemaphore(semaphoreAddress);
11
+ constructor(ISemaphore _semaphore, uint256 _groupId) {
12
+ semaphore = _semaphore;
13
13
  groupId = _groupId;
14
14
 
15
- semaphore.createGroup(groupId, 20, address(this));
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 feedback,
23
+ uint256 merkleTreeDepth,
24
24
  uint256 merkleTreeRoot,
25
- uint256 nullifierHash,
25
+ uint256 nullifier,
26
+ uint256 feedback,
26
27
  uint256[8] calldata proof
27
28
  ) external {
28
- semaphore.verifyProof(groupId, merkleTreeRoot, feedback, nullifierHash, groupId, proof);
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-goerli": {
40
- url: `https://optimism-goerli.infura.io/v3/${infuraApiKey}`,
41
- chainId: 420,
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: `https://arbitrum-mainnet.infura.io/v3/${infuraApiKey}`,
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: config.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
- outDir: config.paths.build.typechain,
73
- target: "ethers-v5"
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.15.2",
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 run scripts/download-snark-artifacts.ts && hardhat test",
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": "^1.0.0",
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": "^2.0.0",
37
- "@nomiclabs/hardhat-ethers": "^2.0.0",
38
- "@nomiclabs/hardhat-etherscan": "^3.0.0",
39
- "@semaphore-protocol/group": "3.15.2",
40
- "@semaphore-protocol/hardhat": "3.15.2",
41
- "@semaphore-protocol/identity": "3.15.2",
42
- "@semaphore-protocol/proof": "3.15.2",
43
- "@typechain/ethers-v5": "^10.1.0",
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": ">=12.0.0",
46
+ "@types/node": "^20",
49
47
  "chai": "^4.2.0",
50
48
  "dotenv": "^16.0.3",
51
- "download": "^8.0.0",
52
- "ethers": "^5.4.7",
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": ">=8.0.0",
57
- "typechain": "^8.1.0",
58
- "typescript": ">=4.5.0"
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": "3.15.2"
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.address
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.address}`)
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 { formatBytes32String } from "ethers/lib/utils"
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(groupId)
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.address })
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 = formatBytes32String("Hello World")
46
+ const feedback = encodeBytes32String("Hello World")
51
47
 
52
- const fullProof = await generateProof(users[1], group, groupId, feedback, {
53
- wasmFilePath,
54
- zkeyFilePath
55
- })
48
+ const fullProof = await generateProof(users[1], group, feedback, groupId)
56
49
 
57
50
  const transaction = feedbackContract.sendFeedback(
58
- feedback,
51
+ fullProof.merkleTreeDepth,
59
52
  fullProof.merkleTreeRoot,
60
- fullProof.nullifierHash,
53
+ fullProof.nullifier,
54
+ feedback,
61
55
  fullProof.proof
62
56
  )
63
57
 
64
58
  await expect(transaction)
65
- .to.emit(semaphoreContract, "ProofVerified")
66
- .withArgs(groupId, fullProof.merkleTreeRoot, fullProof.nullifierHash, groupId, fullProof.signal)
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
- })