Skip to content

Commit 0ec9abb

Browse files
committed
perf(contracts): merge verifiers
1 parent 0964eda commit 0ec9abb

17 files changed

+398
-2313
lines changed

packages/contracts/contracts/Semaphore.sol

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity 0.8.23;
33

44
import {ISemaphore} from "./interfaces/ISemaphore.sol";
55
import {ISemaphoreVerifier} from "./interfaces/ISemaphoreVerifier.sol";
6-
import {SemaphoreGroups} from "./SemaphoreGroups.sol";
6+
import {SemaphoreGroups} from "./base/SemaphoreGroups.sol";
77

88
/// @title Semaphore
99
/// @dev This contract uses the Semaphore base contracts to provide a complete service
@@ -13,15 +13,15 @@ import {SemaphoreGroups} from "./SemaphoreGroups.sol";
1313
/// generated with a new root a duration (or an expiry) within which the proofs generated with that root
1414
/// can be validated.
1515
contract Semaphore is ISemaphore, SemaphoreGroups {
16-
ISemaphoreVerifier[] public verifiers;
16+
ISemaphoreVerifier public verifier;
1717

1818
/// @dev Gets a group id and returns the group parameters.
1919
mapping(uint256 => Group) public groups;
2020

21-
/// @dev Initializes the Semaphore verifiers used to verify the user's ZK proofs.
22-
/// @param _verifiers: Semaphore verifier addresses.
23-
constructor(ISemaphoreVerifier[] memory _verifiers) {
24-
verifiers = _verifiers;
21+
/// @dev Initializes the Semaphore verifier used to verify the user's ZK proofs.
22+
/// @param _verifier: Semaphore verifier addresse.
23+
constructor(ISemaphoreVerifier _verifier) {
24+
verifier = _verifier;
2525
}
2626

2727
/// @dev See {SemaphoreGroups-_createGroup}.
@@ -131,7 +131,7 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
131131
uint256 scope,
132132
uint256[8] calldata proof
133133
) public view override onlyExistingGroup(groupId) returns (bool) {
134-
if (merkleTreeDepth < 1 || merkleTreeDepth > verifiers.length) {
134+
if (merkleTreeDepth < 1 || merkleTreeDepth > 12) {
135135
revert Semaphore__MerkleTreeDepthIsNotSupported();
136136
}
137137

@@ -159,11 +159,12 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
159159
}
160160

161161
return
162-
verifiers[merkleTreeDepth - 1].verifyProof(
162+
verifier.verifyProof(
163163
[proof[0], proof[1]],
164164
[[proof[2], proof[3]], [proof[4], proof[5]]],
165165
[proof[6], proof[7]],
166-
[merkleTreeRoot, nullifier, _hash(message), _hash(scope)]
166+
[merkleTreeRoot, nullifier, _hash(message), _hash(scope)],
167+
merkleTreeDepth
167168
);
168169
}
169170

packages/contracts/contracts/SemaphoreGroups.sol renamed to packages/contracts/contracts/base/SemaphoreGroups.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//SPDX-License-Identifier: MIT
22
pragma solidity 0.8.23;
33

4-
import {ISemaphoreGroups} from "./interfaces/ISemaphoreGroups.sol";
4+
import {ISemaphoreGroups} from "../interfaces/ISemaphoreGroups.sol";
55
import {InternalLeanIMT, LeanIMTData} from "@zk-kit/imt.sol/internal/InternalLeanIMT.sol";
66

77
/// @title Semaphore groups contract.

packages/contracts/contracts/base/SemaphoreVerifier.sol

Lines changed: 367 additions & 0 deletions
Large diffs are not rendered by default.

packages/contracts/contracts/interfaces/ISemaphoreVerifier.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface ISemaphoreVerifier {
77
uint[2] calldata _pA,
88
uint[2][2] calldata _pB,
99
uint[2] calldata _pC,
10-
uint[4] calldata _pubSignals
10+
uint[4] calldata _pubSignals,
11+
uint merkleTreeDepth
1112
) external view returns (bool);
1213
}

packages/contracts/contracts/verifiers/Verifier1.sol

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)