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

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/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
 
@@ -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
  }
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.1",
4
4
  "description": "Semaphore contracts to manage groups and broadcast anonymous signals.",
5
5
  "license": "MIT",
6
6
  "files": [