@semaphore-protocol/contracts 4.0.0-alpha → 4.0.0-alpha.2

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 CHANGED
@@ -10,7 +10,7 @@
10
10
  <img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
11
11
  </a>
12
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">
13
+ <img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fcontracts?style=flat-square">
14
14
  </a>
15
15
  <a href="https://www.npmjs.com/package/@semaphore-protocol/contracts">
16
16
  <img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/contracts?style=flat-square" />
package/Semaphore.sol CHANGED
@@ -102,36 +102,34 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
102
102
 
103
103
  function validateProof(
104
104
  uint256 groupId,
105
- uint256 merkleTreeDepth,
106
- uint256 merkleTreeRoot,
107
- uint256 nullifier,
108
- uint256 message,
109
- uint256 scope,
110
- uint256[8] calldata proof
105
+ SemaphoreProof calldata proof
111
106
  ) external override onlyExistingGroup(groupId) {
112
- if (groups[groupId].nullifiers[nullifier]) {
107
+ if (groups[groupId].nullifiers[proof.nullifier]) {
113
108
  revert Semaphore__YouAreUsingTheSameNullifierTwice();
114
109
  }
115
110
 
116
- if (!verifyProof(groupId, merkleTreeDepth, merkleTreeRoot, nullifier, message, scope, proof)) {
111
+ if (!verifyProof(groupId, proof)) {
117
112
  revert Semaphore__InvalidProof();
118
113
  }
119
114
 
120
- groups[groupId].nullifiers[nullifier] = true;
121
-
122
- emit ProofValidated(groupId, merkleTreeDepth, merkleTreeRoot, nullifier, message, scope, proof);
115
+ groups[groupId].nullifiers[proof.nullifier] = true;
116
+
117
+ emit ProofValidated(
118
+ groupId,
119
+ proof.merkleTreeDepth,
120
+ proof.merkleTreeRoot,
121
+ proof.nullifier,
122
+ proof.message,
123
+ proof.scope,
124
+ proof.points
125
+ );
123
126
  }
124
127
 
125
128
  function verifyProof(
126
129
  uint256 groupId,
127
- uint256 merkleTreeDepth,
128
- uint256 merkleTreeRoot,
129
- uint256 nullifier,
130
- uint256 message,
131
- uint256 scope,
132
- uint256[8] calldata proof
130
+ SemaphoreProof calldata proof
133
131
  ) public view override onlyExistingGroup(groupId) returns (bool) {
134
- if (merkleTreeDepth < 1 || merkleTreeDepth > 12) {
132
+ if (proof.merkleTreeDepth < 1 || proof.merkleTreeDepth > 12) {
135
133
  revert Semaphore__MerkleTreeDepthIsNotSupported();
136
134
  }
137
135
 
@@ -145,8 +143,8 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
145
143
 
146
144
  // A proof could have used an old Merkle tree root.
147
145
  // https://github.com/semaphore-protocol/semaphore/issues/98
148
- if (merkleTreeRoot != currentMerkleTreeRoot) {
149
- uint256 merkleRootCreationDate = groups[groupId].merkleRootCreationDates[merkleTreeRoot];
146
+ if (proof.merkleTreeRoot != currentMerkleTreeRoot) {
147
+ uint256 merkleRootCreationDate = groups[groupId].merkleRootCreationDates[proof.merkleTreeRoot];
150
148
  uint256 merkleTreeDuration = groups[groupId].merkleTreeDuration;
151
149
 
152
150
  if (merkleRootCreationDate == 0) {
@@ -160,11 +158,11 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
160
158
 
161
159
  return
162
160
  verifier.verifyProof(
163
- [proof[0], proof[1]],
164
- [[proof[2], proof[3]], [proof[4], proof[5]]],
165
- [proof[6], proof[7]],
166
- [merkleTreeRoot, nullifier, _hash(message), _hash(scope)],
167
- merkleTreeDepth
161
+ [proof.points[0], proof.points[1]],
162
+ [[proof.points[2], proof.points[3]], [proof.points[4], proof.points[5]]],
163
+ [proof.points[6], proof.points[7]],
164
+ [proof.merkleTreeRoot, proof.nullifier, _hash(proof.message), _hash(proof.scope)],
165
+ proof.merkleTreeDepth
168
166
  );
169
167
  }
170
168
 
@@ -123,6 +123,11 @@ abstract contract SemaphoreGroups is ISemaphoreGroups {
123
123
  emit MemberRemoved(groupId, index, identityCommitment, merkleTreeRoot);
124
124
  }
125
125
 
126
+ /// @dev See {ISemaphoreGroups-getGroupAdmin}.
127
+ function getGroupAdmin(uint256 groupId) public view virtual override returns (address) {
128
+ return admins[groupId];
129
+ }
130
+
126
131
  /// @dev See {ISemaphoreGroups-hasMember}.
127
132
  function hasMember(uint256 groupId, uint256 identityCommitment) public view virtual override returns (bool) {
128
133
  return merkleTrees[groupId]._has(identityCommitment);
@@ -17,6 +17,16 @@ interface ISemaphore {
17
17
  mapping(uint256 => bool) nullifiers;
18
18
  }
19
19
 
20
+ /// It defines all the group parameters used by Semaphore.sol.
21
+ struct SemaphoreProof {
22
+ uint256 merkleTreeDepth;
23
+ uint256 merkleTreeRoot;
24
+ uint256 nullifier;
25
+ uint256 message;
26
+ uint256 scope;
27
+ uint256[8] points;
28
+ }
29
+
20
30
  /// @dev Emitted when the Merkle tree duration of a group is updated.
21
31
  /// @param groupId: Id of the group.
22
32
  /// @param oldMerkleTreeDuration: Old Merkle tree duration of the group.
@@ -34,7 +44,7 @@ interface ISemaphore {
34
44
  /// @param nullifier: Nullifier.
35
45
  /// @param message: Semaphore message.
36
46
  /// @param scope: Scope.
37
- /// @param proof: Zero-knowledge proof.
47
+ /// @param points: Zero-knowledge points.
38
48
  event ProofValidated(
39
49
  uint256 indexed groupId,
40
50
  uint256 merkleTreeDepth,
@@ -42,7 +52,7 @@ interface ISemaphore {
42
52
  uint256 nullifier,
43
53
  uint256 message,
44
54
  uint256 indexed scope,
45
- uint256[8] proof
55
+ uint256[8] points
46
56
  );
47
57
 
48
58
  /// @dev See {SemaphoreGroups-_createGroup}.
@@ -82,37 +92,11 @@ interface ISemaphore {
82
92
  /// @dev Saves the nullifier hash to avoid double signaling and emits an event
83
93
  /// if the zero-knowledge proof is valid.
84
94
  /// @param groupId: Id of the group.
85
- /// @param merkleTreeDepth: Depth of the Merkle tree.
86
- /// @param merkleTreeRoot: Root of the Merkle tree.
87
- /// @param nullifier: Nullifier.
88
- /// @param message: Semaphore message.
89
- /// @param scope: Scope.
90
95
  /// @param proof: Zero-knowledge proof.
91
- function validateProof(
92
- uint256 groupId,
93
- uint256 merkleTreeDepth,
94
- uint256 merkleTreeRoot,
95
- uint256 nullifier,
96
- uint256 message,
97
- uint256 scope,
98
- uint256[8] calldata proof
99
- ) external;
96
+ function validateProof(uint256 groupId, SemaphoreProof calldata proof) external;
100
97
 
101
98
  /// @dev Verifies a zero-knowledge proof by returning true or false.
102
99
  /// @param groupId: Id of the group.
103
- /// @param merkleTreeDepth: Depth of the Merkle tree.
104
- /// @param merkleTreeRoot: Root of the Merkle tree.
105
- /// @param nullifier: Nullifier.
106
- /// @param message: Semaphore message.
107
- /// @param scope: Scope.
108
100
  /// @param proof: Zero-knowledge proof.
109
- function verifyProof(
110
- uint256 groupId,
111
- uint256 merkleTreeDepth,
112
- uint256 merkleTreeRoot,
113
- uint256 nullifier,
114
- uint256 message,
115
- uint256 scope,
116
- uint256[8] calldata proof
117
- ) external view returns (bool);
101
+ function verifyProof(uint256 groupId, SemaphoreProof calldata proof) external view returns (bool);
118
102
  }
@@ -57,6 +57,11 @@ interface ISemaphoreGroups {
57
57
  /// @param merkleTreeRoot: New root hash of the tree.
58
58
  event MemberRemoved(uint256 indexed groupId, uint256 index, uint256 identityCommitment, uint256 merkleTreeRoot);
59
59
 
60
+ /// @dev Returns the address of the group admin.
61
+ /// @param groupId: Id of the group.
62
+ /// @return Address of the group admin.
63
+ function getGroupAdmin(uint256 groupId) external view returns (address);
64
+
60
65
  /// @dev Returns true if a member exists in a group.
61
66
  /// @param groupId: Id of the group.
62
67
  /// @param identityCommitment: Identity commitment.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semaphore-protocol/contracts",
3
- "version": "4.0.0-alpha",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Semaphore contracts to manage groups and broadcast anonymous signals.",
5
5
  "license": "MIT",
6
6
  "files": [