@@ -27,12 +27,13 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
27
27
_;
28
28
}
29
29
30
- /// @dev Checks if there is a verifier for the given tree depth .
31
- /// @param merkleTreeDepth: Depth of the tree .
32
- modifier onlySupportedMerkleTreeDepth (uint256 merkleTreeDepth ) {
33
- if (merkleTreeDepth < 16 || merkleTreeDepth > 32 ) {
34
- revert Semaphore__MerkleTreeDepthIsNotSupported ();
30
+ /// @dev Checks if the group exists .
31
+ /// @param groupId: Id of the group .
32
+ modifier onlyExistingGroup (uint256 groupId ) {
33
+ if (groups[groupId].admin == address ( 0 ) ) {
34
+ revert Semaphore__GroupDoesNotExist ();
35
35
}
36
+
36
37
_;
37
38
}
38
39
@@ -43,36 +44,36 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
43
44
}
44
45
45
46
/// @dev See {ISemaphore-createGroup}.
46
- function createGroup (
47
- uint256 groupId ,
48
- uint256 merkleTreeDepth ,
49
- address admin
50
- ) external override onlySupportedMerkleTreeDepth (merkleTreeDepth) {
51
- _createGroup (groupId, merkleTreeDepth);
47
+ function createGroup (uint256 groupId , address admin ) external override {
48
+ if (groups[groupId].admin != address (0 )) {
49
+ revert Semaphore__GroupAlreadyExists ();
50
+ }
52
51
53
52
groups[groupId].admin = admin;
54
53
groups[groupId].merkleTreeDuration = 1 hours ;
55
54
55
+ emit GroupCreated (groupId);
56
56
emit GroupAdminUpdated (groupId, address (0 ), admin);
57
57
}
58
58
59
59
/// @dev See {ISemaphore-createGroup}.
60
- function createGroup (
61
- uint256 groupId ,
62
- uint256 merkleTreeDepth ,
63
- address admin ,
64
- uint256 merkleTreeDuration
65
- ) external override onlySupportedMerkleTreeDepth (merkleTreeDepth) {
66
- _createGroup (groupId, merkleTreeDepth);
60
+ function createGroup (uint256 groupId , address admin , uint256 merkleTreeDuration ) external override {
61
+ if (groups[groupId].admin != address (0 )) {
62
+ revert Semaphore__GroupAlreadyExists ();
63
+ }
67
64
68
65
groups[groupId].admin = admin;
69
66
groups[groupId].merkleTreeDuration = merkleTreeDuration;
70
67
68
+ emit GroupCreated (groupId);
71
69
emit GroupAdminUpdated (groupId, address (0 ), admin);
72
70
}
73
71
74
72
/// @dev See {ISemaphore-updateGroupAdmin}.
75
- function updateGroupAdmin (uint256 groupId , address newAdmin ) external override onlyGroupAdmin (groupId) {
73
+ function updateGroupAdmin (
74
+ uint256 groupId ,
75
+ address newAdmin
76
+ ) external override onlyExistingGroup (groupId) onlyGroupAdmin (groupId) {
76
77
groups[groupId].admin = newAdmin;
77
78
78
79
emit GroupAdminUpdated (groupId, _msgSender (), newAdmin);
@@ -82,7 +83,7 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
82
83
function updateGroupMerkleTreeDuration (
83
84
uint256 groupId ,
84
85
uint256 newMerkleTreeDuration
85
- ) external override onlyGroupAdmin (groupId) {
86
+ ) external override onlyExistingGroup (groupId) onlyGroupAdmin (groupId) {
86
87
uint256 oldMerkleTreeDuration = groups[groupId].merkleTreeDuration;
87
88
88
89
groups[groupId].merkleTreeDuration = newMerkleTreeDuration;
@@ -91,7 +92,10 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
91
92
}
92
93
93
94
/// @dev See {ISemaphore-addMember}.
94
- function addMember (uint256 groupId , uint256 identityCommitment ) external override onlyGroupAdmin (groupId) {
95
+ function addMember (
96
+ uint256 groupId ,
97
+ uint256 identityCommitment
98
+ ) external override onlyExistingGroup (groupId) onlyGroupAdmin (groupId) {
95
99
_addMember (groupId, identityCommitment);
96
100
97
101
uint256 merkleTreeRoot = getMerkleTreeRoot (groupId);
@@ -103,7 +107,7 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
103
107
function addMembers (
104
108
uint256 groupId ,
105
109
uint256 [] calldata identityCommitments
106
- ) external override onlyGroupAdmin (groupId) {
110
+ ) external override onlyExistingGroup (groupId) onlyGroupAdmin (groupId) {
107
111
for (uint256 i = 0 ; i < identityCommitments.length ; ) {
108
112
_addMember (groupId, identityCommitments[i]);
109
113
@@ -122,10 +126,9 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
122
126
uint256 groupId ,
123
127
uint256 identityCommitment ,
124
128
uint256 newIdentityCommitment ,
125
- uint256 [] calldata proofSiblings ,
126
- uint8 [] calldata proofPathIndices
127
- ) external override onlyGroupAdmin (groupId) {
128
- _updateMember (groupId, identityCommitment, newIdentityCommitment, proofSiblings, proofPathIndices);
129
+ uint256 [] calldata merkleProofSiblings
130
+ ) external override onlyExistingGroup (groupId) onlyGroupAdmin (groupId) {
131
+ _updateMember (groupId, identityCommitment, newIdentityCommitment, merkleProofSiblings);
129
132
130
133
uint256 merkleTreeRoot = getMerkleTreeRoot (groupId);
131
134
@@ -136,10 +139,9 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
136
139
function removeMember (
137
140
uint256 groupId ,
138
141
uint256 identityCommitment ,
139
- uint256 [] calldata proofSiblings ,
140
- uint8 [] calldata proofPathIndices
141
- ) external override onlyGroupAdmin (groupId) {
142
- _removeMember (groupId, identityCommitment, proofSiblings, proofPathIndices);
142
+ uint256 [] calldata merkleProofSiblings
143
+ ) external override onlyExistingGroup (groupId) onlyGroupAdmin (groupId) {
144
+ _removeMember (groupId, identityCommitment, merkleProofSiblings);
143
145
144
146
uint256 merkleTreeRoot = getMerkleTreeRoot (groupId);
145
147
@@ -150,15 +152,15 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
150
152
function verifyProof (
151
153
uint256 groupId ,
152
154
uint256 merkleTreeRoot ,
153
- uint256 signal ,
154
- uint256 nullifierHash ,
155
- uint256 externalNullifier ,
155
+ uint256 message ,
156
+ uint256 nullifier ,
157
+ uint256 scope ,
156
158
uint256 [8 ] calldata proof
157
- ) external override {
159
+ ) external override onlyExistingGroup (groupId) {
158
160
uint256 merkleTreeDepth = getMerkleTreeDepth (groupId);
159
161
160
162
if (merkleTreeDepth == 0 ) {
161
- revert Semaphore__GroupDoesNotExist ();
163
+ revert Semaphore__GroupHasNoMembers ();
162
164
}
163
165
164
166
uint256 currentMerkleTreeRoot = getMerkleTreeRoot (groupId);
@@ -178,14 +180,14 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
178
180
}
179
181
}
180
182
181
- if (groups[groupId].nullifierHashes[nullifierHash ]) {
183
+ if (groups[groupId].nullifiers[nullifier ]) {
182
184
revert Semaphore__YouAreUsingTheSameNillifierTwice ();
183
185
}
184
186
185
- verifier.verifyProof (merkleTreeRoot, nullifierHash, signal, externalNullifier , proof, merkleTreeDepth );
187
+ verifier.verifyProof (merkleTreeRoot, nullifier, message, scope , proof);
186
188
187
- groups[groupId].nullifierHashes[nullifierHash ] = true ;
189
+ groups[groupId].nullifiers[nullifier ] = true ;
188
190
189
- emit ProofVerified (groupId, merkleTreeRoot, nullifierHash, externalNullifier, signal );
191
+ emit ProofVerified (groupId, merkleTreeRoot, nullifier, scope, message, proof );
190
192
}
191
193
}
0 commit comments