@semaphore-protocol/contracts 0.1.0 → 2.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.
@@ -1,14 +1,14 @@
1
1
  //SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.4;
2
+ pragma solidity 0.8.4;
3
3
 
4
4
  /// @title SemaphoreNullifiers interface.
5
5
  /// @dev Interface of SemaphoreNullifiers contract.
6
6
  interface ISemaphoreNullifiers {
7
- /// @dev Emitted when a external nullifier is added.
8
- /// @param externalNullifier: External Semaphore nullifier.
9
- event ExternalNullifierAdded(uint256 externalNullifier);
7
+ /// @dev Emitted when a external nullifier is added.
8
+ /// @param externalNullifier: External Semaphore nullifier.
9
+ event ExternalNullifierAdded(uint256 externalNullifier);
10
10
 
11
- /// @dev Emitted when a external nullifier is removed.
12
- /// @param externalNullifier: External Semaphore nullifier.
13
- event ExternalNullifierRemoved(uint256 externalNullifier);
11
+ /// @dev Emitted when a external nullifier is removed.
12
+ /// @param externalNullifier: External Semaphore nullifier.
13
+ event ExternalNullifierRemoved(uint256 externalNullifier);
14
14
  }
@@ -1,76 +1,86 @@
1
1
  //SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.4;
2
+ pragma solidity 0.8.4;
3
3
 
4
4
  /// @title SemaphoreVoting interface.
5
5
  /// @dev Interface of SemaphoreVoting contract.
6
6
  interface ISemaphoreVoting {
7
- enum PollState {
8
- Created,
9
- Ongoing,
10
- Ended
11
- }
7
+ error Semaphore__CallerIsNotThePollCoordinator();
8
+ error Semaphore__MerkleTreeDepthIsNotSupported();
9
+ error Semaphore__PollHasAlreadyBeenStarted();
10
+ error Semaphore__PollIsNotOngoing();
12
11
 
13
- struct Poll {
14
- address coordinator;
15
- PollState state;
16
- }
12
+ enum PollState {
13
+ Created,
14
+ Ongoing,
15
+ Ended
16
+ }
17
17
 
18
- /// @dev Emitted when a new poll is created.
19
- /// @param pollId: Id of the poll.
20
- /// @param coordinator: Coordinator of the poll.
21
- event PollCreated(uint256 pollId, address indexed coordinator);
18
+ struct Verifier {
19
+ address contractAddress;
20
+ uint256 merkleTreeDepth;
21
+ }
22
22
 
23
- /// @dev Emitted when a poll is started.
24
- /// @param pollId: Id of the poll.
25
- /// @param coordinator: Coordinator of the poll.
26
- /// @param encryptionKey: Key to encrypt the poll votes.
27
- event PollStarted(uint256 pollId, address indexed coordinator, uint256 encryptionKey);
23
+ struct Poll {
24
+ address coordinator;
25
+ PollState state;
26
+ }
28
27
 
29
- /// @dev Emitted when a user votes on a poll.
30
- /// @param pollId: Id of the poll.
31
- /// @param vote: User encrypted vote.
32
- event VoteAdded(uint256 indexed pollId, bytes32 vote);
28
+ /// @dev Emitted when a new poll is created.
29
+ /// @param pollId: Id of the poll.
30
+ /// @param coordinator: Coordinator of the poll.
31
+ event PollCreated(uint256 pollId, address indexed coordinator);
33
32
 
34
- /// @dev Emitted when a poll is ended.
35
- /// @param pollId: Id of the poll.
36
- /// @param coordinator: Coordinator of the poll.
37
- /// @param decryptionKey: Key to decrypt the poll votes.
38
- event PollEnded(uint256 pollId, address indexed coordinator, uint256 decryptionKey);
33
+ /// @dev Emitted when a poll is started.
34
+ /// @param pollId: Id of the poll.
35
+ /// @param coordinator: Coordinator of the poll.
36
+ /// @param encryptionKey: Key to encrypt the poll votes.
37
+ event PollStarted(uint256 pollId, address indexed coordinator, uint256 encryptionKey);
39
38
 
40
- /// @dev Creates a poll and the associated Merkle tree/group.
41
- /// @param pollId: Id of the poll.
42
- /// @param coordinator: Coordinator of the poll.
43
- /// @param depth: Depth of the tree.
44
- function createPoll(
45
- uint256 pollId,
46
- address coordinator,
47
- uint8 depth
48
- ) external;
39
+ /// @dev Emitted when a user votes on a poll.
40
+ /// @param pollId: Id of the poll.
41
+ /// @param vote: User encrypted vote.
42
+ event VoteAdded(uint256 indexed pollId, bytes32 vote);
49
43
 
50
- /// @dev Adds a voter to a poll.
51
- /// @param pollId: Id of the poll.
52
- /// @param identityCommitment: Identity commitment of the group member.
53
- function addVoter(uint256 pollId, uint256 identityCommitment) external;
44
+ /// @dev Emitted when a poll is ended.
45
+ /// @param pollId: Id of the poll.
46
+ /// @param coordinator: Coordinator of the poll.
47
+ /// @param decryptionKey: Key to decrypt the poll votes.
48
+ event PollEnded(uint256 pollId, address indexed coordinator, uint256 decryptionKey);
54
49
 
55
- /// @dev Starts a pull and publishes the key to encrypt the votes.
56
- /// @param pollId: Id of the poll.
57
- /// @param encryptionKey: Key to encrypt poll votes.
58
- function startPoll(uint256 pollId, uint256 encryptionKey) external;
50
+ /// @dev Creates a poll and the associated Merkle tree/group.
51
+ /// @param pollId: Id of the poll.
52
+ /// @param coordinator: Coordinator of the poll.
53
+ /// @param merkleTreeDepth: Depth of the tree.
54
+ function createPoll(
55
+ uint256 pollId,
56
+ address coordinator,
57
+ uint256 merkleTreeDepth
58
+ ) external;
59
59
 
60
- /// @dev Casts an anonymous vote in a poll.
61
- /// @param vote: Encrypted vote.
62
- /// @param nullifierHash: Nullifier hash.
63
- /// @param pollId: Id of the poll.
64
- /// @param proof: Private zk-proof parameters.
65
- function castVote(
66
- bytes32 vote,
67
- uint256 nullifierHash,
68
- uint256 pollId,
69
- uint256[8] calldata proof
70
- ) external;
60
+ /// @dev Adds a voter to a poll.
61
+ /// @param pollId: Id of the poll.
62
+ /// @param identityCommitment: Identity commitment of the group member.
63
+ function addVoter(uint256 pollId, uint256 identityCommitment) external;
71
64
 
72
- /// @dev Ends a pull and publishes the key to decrypt the votes.
73
- /// @param pollId: Id of the poll.
74
- /// @param decryptionKey: Key to decrypt poll votes.
75
- function endPoll(uint256 pollId, uint256 decryptionKey) external;
65
+ /// @dev Starts a pull and publishes the key to encrypt the votes.
66
+ /// @param pollId: Id of the poll.
67
+ /// @param encryptionKey: Key to encrypt poll votes.
68
+ function startPoll(uint256 pollId, uint256 encryptionKey) external;
69
+
70
+ /// @dev Casts an anonymous vote in a poll.
71
+ /// @param vote: Encrypted vote.
72
+ /// @param nullifierHash: Nullifier hash.
73
+ /// @param pollId: Id of the poll.
74
+ /// @param proof: Private zk-proof parameters.
75
+ function castVote(
76
+ bytes32 vote,
77
+ uint256 nullifierHash,
78
+ uint256 pollId,
79
+ uint256[8] calldata proof
80
+ ) external;
81
+
82
+ /// @dev Ends a pull and publishes the key to decrypt the votes.
83
+ /// @param pollId: Id of the poll.
84
+ /// @param decryptionKey: Key to decrypt poll votes.
85
+ function endPoll(uint256 pollId, uint256 decryptionKey) external;
76
86
  }
@@ -1,55 +1,63 @@
1
1
  //SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.4;
2
+ pragma solidity 0.8.4;
3
3
 
4
4
  /// @title SemaphoreWhistleblowing interface.
5
5
  /// @dev Interface of SemaphoreWhistleblowing contract.
6
6
  interface ISemaphoreWhistleblowing {
7
- /// @dev Emitted when a new entity is created.
8
- /// @param entityId: Id of the entity.
9
- /// @param editor: Editor of the entity.
10
- event EntityCreated(uint256 entityId, address indexed editor);
11
-
12
- /// @dev Emitted when a whistleblower publish a new leak.
13
- /// @param entityId: Id of the entity.
14
- /// @param leak: News leak.
15
- event LeakPublished(uint256 indexed entityId, bytes32 leak);
16
-
17
- /// @dev Creates an entity and the associated Merkle tree/group.
18
- /// @param entityId: Id of the entity.
19
- /// @param editor: Editor of the entity.
20
- /// @param depth: Depth of the tree.
21
- function createEntity(
22
- uint256 entityId,
23
- address editor,
24
- uint8 depth
25
- ) external;
26
-
27
- /// @dev Adds a whistleblower to an entity.
28
- /// @param entityId: Id of the entity.
29
- /// @param identityCommitment: Identity commitment of the group member.
30
- function addWhistleblower(uint256 entityId, uint256 identityCommitment) external;
31
-
32
- /// @dev Removes a whistleblower from an entity.
33
- /// @param entityId: Id of the entity.
34
- /// @param identityCommitment: Identity commitment of the group member.
35
- /// @param proofSiblings: Array of the sibling nodes of the proof of membership.
36
- /// @param proofPathIndices: Path of the proof of membership.
37
- function removeWhistleblower(
38
- uint256 entityId,
39
- uint256 identityCommitment,
40
- uint256[] calldata proofSiblings,
41
- uint8[] calldata proofPathIndices
42
- ) external;
43
-
44
- /// @dev Allows whistleblowers to publish leaks anonymously.
45
- /// @param leak: News leak.
46
- /// @param nullifierHash: Nullifier hash.
47
- /// @param entityId: Id of the entity.
48
- /// @param proof: Private zk-proof parameters.
49
- function publishLeak(
50
- bytes32 leak,
51
- uint256 nullifierHash,
52
- uint256 entityId,
53
- uint256[8] calldata proof
54
- ) external;
7
+ error Semaphore__CallerIsNotTheEditor();
8
+ error Semaphore__MerkleTreeDepthIsNotSupported();
9
+
10
+ struct Verifier {
11
+ address contractAddress;
12
+ uint256 merkleTreeDepth;
13
+ }
14
+
15
+ /// @dev Emitted when a new entity is created.
16
+ /// @param entityId: Id of the entity.
17
+ /// @param editor: Editor of the entity.
18
+ event EntityCreated(uint256 entityId, address indexed editor);
19
+
20
+ /// @dev Emitted when a whistleblower publish a new leak.
21
+ /// @param entityId: Id of the entity.
22
+ /// @param leak: News leak.
23
+ event LeakPublished(uint256 indexed entityId, bytes32 leak);
24
+
25
+ /// @dev Creates an entity and the associated Merkle tree/group.
26
+ /// @param entityId: Id of the entity.
27
+ /// @param editor: Editor of the entity.
28
+ /// @param merkleTreeDepth: Depth of the tree.
29
+ function createEntity(
30
+ uint256 entityId,
31
+ address editor,
32
+ uint256 merkleTreeDepth
33
+ ) external;
34
+
35
+ /// @dev Adds a whistleblower to an entity.
36
+ /// @param entityId: Id of the entity.
37
+ /// @param identityCommitment: Identity commitment of the group member.
38
+ function addWhistleblower(uint256 entityId, uint256 identityCommitment) external;
39
+
40
+ /// @dev Removes a whistleblower from an entity.
41
+ /// @param entityId: Id of the entity.
42
+ /// @param identityCommitment: Identity commitment of the group member.
43
+ /// @param proofSiblings: Array of the sibling nodes of the proof of membership.
44
+ /// @param proofPathIndices: Path of the proof of membership.
45
+ function removeWhistleblower(
46
+ uint256 entityId,
47
+ uint256 identityCommitment,
48
+ uint256[] calldata proofSiblings,
49
+ uint8[] calldata proofPathIndices
50
+ ) external;
51
+
52
+ /// @dev Allows whistleblowers to publish leaks anonymously.
53
+ /// @param leak: News leak.
54
+ /// @param nullifierHash: Nullifier hash.
55
+ /// @param entityId: Id of the entity.
56
+ /// @param proof: Private zk-proof parameters.
57
+ function publishLeak(
58
+ bytes32 leak,
59
+ uint256 nullifierHash,
60
+ uint256 entityId,
61
+ uint256[8] calldata proof
62
+ ) external;
55
63
  }
@@ -1,13 +1,13 @@
1
1
  //SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.4;
2
+ pragma solidity 0.8.4;
3
3
 
4
4
  /// @title Verifier interface.
5
5
  /// @dev Interface of Verifier contract.
6
6
  interface IVerifier {
7
- function verifyProof(
8
- uint256[2] memory a,
9
- uint256[2][2] memory b,
10
- uint256[2] memory c,
11
- uint256[4] memory input
12
- ) external view;
7
+ function verifyProof(
8
+ uint256[2] memory a,
9
+ uint256[2][2] memory b,
10
+ uint256[2] memory c,
11
+ uint256[4] memory input
12
+ ) external view;
13
13
  }
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
1
  {
2
- "name": "@semaphore-protocol/contracts",
3
- "version": "0.1.0",
4
- "description": "A privacy gadget for creating anonymous proof of membership on Ethereum.",
5
- "license": "MIT",
6
- "files": [
7
- "**/*.sol"
8
- ],
9
- "keywords": [
10
- "blockchain",
11
- "ethereum",
12
- "hardhat",
13
- "smart-contracts",
14
- "semaphore",
15
- "identity",
16
- "solidity",
17
- "zero-knowledge",
18
- "zk-snarks",
19
- "zero-knowledge-proofs",
20
- "circom",
21
- "proof-of-membership"
22
- ],
23
- "homepage": "https://github.com/appliedzkp/semaphore.git#readme",
24
- "repository": {
25
- "type": "git",
26
- "url": "git+https://github.com/appliedzkp/semaphore.git.git"
27
- },
28
- "bugs": {
29
- "url": "https://github.com/appliedzkp/semaphore.git/issues"
30
- },
31
- "publishConfig": {
32
- "access": "public"
33
- },
34
- "dependencies": {
35
- "@openzeppelin/contracts": "^4.4.2",
36
- "@zk-kit/incremental-merkle-tree.sol": "^0.3.1"
37
- }
2
+ "name": "@semaphore-protocol/contracts",
3
+ "version": "2.1.0",
4
+ "description": "Semaphore contracts to manage groups and broadcast anonymous signals.",
5
+ "license": "MIT",
6
+ "files": [
7
+ "**/*.sol"
8
+ ],
9
+ "keywords": [
10
+ "blockchain",
11
+ "ethereum",
12
+ "hardhat",
13
+ "smart-contracts",
14
+ "semaphore",
15
+ "identity",
16
+ "solidity",
17
+ "zero-knowledge",
18
+ "zk-snarks",
19
+ "zero-knowledge-proofs",
20
+ "circom",
21
+ "proof-of-membership"
22
+ ],
23
+ "homepage": "https://github.com/semaphore-protocol/semaphore.git#readme",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/semaphore-protocol/semaphore.git.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/semaphore-protocol/semaphore.git/issues"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "dependencies": {
35
+ "@openzeppelin/contracts": "4.4.2",
36
+ "@zk-kit/incremental-merkle-tree.sol": "1.3.0"
37
+ }
38
38
  }
@@ -130,7 +130,7 @@ library Pairing {
130
130
  }
131
131
  }
132
132
 
133
- contract Verifier {
133
+ contract Verifier16 {
134
134
  using Pairing for *;
135
135
 
136
136
  struct VerifyingKey {
@@ -154,69 +154,56 @@ contract Verifier {
154
154
  );
155
155
 
156
156
  vk.beta2 = Pairing.G2Point(
157
- [
158
- 4252822878758300859123897981450591353533073413197771768651442665752259397132,
159
- 6375614351688725206403948262868962793625744043794305715222011528459656738731
160
- ],
161
- [
162
- 21847035105528745403288232691147584728191162732299865338377159692350059136679,
163
- 10505242626370262277552901082094356697409835680220590971873171140371331206856
164
- ]
157
+ [4252822878758300859123897981450591353533073413197771768651442665752259397132, 6375614351688725206403948262868962793625744043794305715222011528459656738731],
158
+ [21847035105528745403288232691147584728191162732299865338377159692350059136679, 10505242626370262277552901082094356697409835680220590971873171140371331206856]
165
159
  );
166
- vk.gamma2 = Pairing.G2Point(
167
- [
168
- 11559732032986387107991004021392285783925812861821192530917403151452391805634,
169
- 10857046999023057135944570762232829481370756359578518086990519993285655852781
170
- ],
171
- [
172
- 4082367875863433681332203403145435568316851327593401208105741076214120093531,
173
- 8495653923123431417604973247489272438418190587263600148770280649306958101930
174
- ]
175
- );
176
- vk.delta2 = Pairing.G2Point(
177
- [
178
- 12599857379517512478445603412764121041984228075771497593287716170335433683702,
179
- 7912208710313447447762395792098481825752520616755888860068004689933335666613
180
- ],
181
- [
182
- 11502426145685875357967720478366491326865907869902181704031346886834786027007,
183
- 21679208693936337484429571887537508926366191105267550375038502782696042114705
184
- ]
185
- );
186
- vk.IC = new Pairing.G1Point[](5);
187
160
 
188
- vk.IC[0] = Pairing.G1Point(
189
- 19918517214839406678907482305035208173510172567546071380302965459737278553528,
190
- 7151186077716310064777520690144511885696297127165278362082219441732663131220
191
- );
192
-
193
- vk.IC[1] = Pairing.G1Point(
194
- 690581125971423619528508316402701520070153774868732534279095503611995849608,
195
- 21271996888576045810415843612869789314680408477068973024786458305950370465558
161
+ vk.gamma2 = Pairing.G2Point(
162
+ [11559732032986387107991004021392285783925812861821192530917403151452391805634, 10857046999023057135944570762232829481370756359578518086990519993285655852781],
163
+ [4082367875863433681332203403145435568316851327593401208105741076214120093531, 8495653923123431417604973247489272438418190587263600148770280649306958101930]
196
164
  );
197
165
 
198
- vk.IC[2] = Pairing.G1Point(
199
- 16461282535702132833442937829027913110152135149151199860671943445720775371319,
200
- 2814052162479976678403678512565563275428791320557060777323643795017729081887
166
+ vk.delta2 = Pairing.G2Point(
167
+ [13406811599156507528361773763681356312643537981039994686313383243831956396116, 16243966861079634958125511652590761846958471358623040426599000904006426210032],
168
+ [11781596534582143578120404722739278517564025497573071755253972265891888117374, 15688083679237922164673518758181461582601853873216319711156397437601833996222]
201
169
  );
202
170
 
203
- vk.IC[3] = Pairing.G1Point(
204
- 4319780315499060392574138782191013129592543766464046592208884866569377437627,
205
- 13920930439395002698339449999482247728129484070642079851312682993555105218086
206
- );
171
+ vk.IC = new Pairing.G1Point[](5);
207
172
 
208
- vk.IC[4] = Pairing.G1Point(
209
- 3554830803181375418665292545416227334138838284686406179598687755626325482686,
210
- 5951609174746846070367113593675211691311013364421437923470787371738135276998
211
- );
173
+
174
+ vk.IC[0] = Pairing.G1Point(
175
+ 1964404930528116823793003656764176108669615750422202377358993070935069307720,
176
+ 2137714996673694828207437580381836490878070731768805974506391024595988817424
177
+ );
178
+
179
+ vk.IC[1] = Pairing.G1Point(
180
+ 19568893707760843340848992184233194433177372925415116053368211122719346671126,
181
+ 11639469568629189918046964192305250472192697612201524135560178632824282818614
182
+ );
183
+
184
+ vk.IC[2] = Pairing.G1Point(
185
+ 5317268879687484957437879782519918549127939892210247573193613900261494313825,
186
+ 528174394975085006443543773707702838726735933116136102590448357278717993744
187
+ );
188
+
189
+ vk.IC[3] = Pairing.G1Point(
190
+ 14865918005176722116473730206622066845866539143554731094374354951675249722731,
191
+ 3197770568483953664363740385883457803041685902965668289308665954510373380344
192
+ );
193
+
194
+ vk.IC[4] = Pairing.G1Point(
195
+ 6863358721495494421022713667808247652425178970453300712435830652679038918987,
196
+ 15025816433373311798308762709072064417001390853103872064614174594927359131281
197
+ );
198
+
212
199
  }
213
200
 
214
201
  /// @dev Verifies a Semaphore proof. Reverts with InvalidProof if the proof is invalid.
215
202
  function verifyProof(
216
- uint256[2] memory a,
217
- uint256[2][2] memory b,
218
- uint256[2] memory c,
219
- uint256[4] memory input
203
+ uint[2] memory a,
204
+ uint[2][2] memory b,
205
+ uint[2] memory c,
206
+ uint[4] memory input
220
207
  ) public view {
221
208
  // If the values are not in the correct range, the Pairing contract will revert.
222
209
  Proof memory proof;