Skip to content

Commit

Permalink
perf(contracts): merge verifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Jan 23, 2024
1 parent 0964eda commit 0ec9abb
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 2,313 deletions.
19 changes: 10 additions & 9 deletions packages/contracts/contracts/Semaphore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.23;

import {ISemaphore} from "./interfaces/ISemaphore.sol";
import {ISemaphoreVerifier} from "./interfaces/ISemaphoreVerifier.sol";
import {SemaphoreGroups} from "./SemaphoreGroups.sol";
import {SemaphoreGroups} from "./base/SemaphoreGroups.sol";

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

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

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

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

Expand Down Expand Up @@ -159,11 +159,12 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
}

return
verifiers[merkleTreeDepth - 1].verifyProof(
verifier.verifyProof(
[proof[0], proof[1]],
[[proof[2], proof[3]], [proof[4], proof[5]]],
[proof[6], proof[7]],
[merkleTreeRoot, nullifier, _hash(message), _hash(scope)]
[merkleTreeRoot, nullifier, _hash(message), _hash(scope)],
merkleTreeDepth
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

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

/// @title Semaphore groups contract.
Expand Down
367 changes: 367 additions & 0 deletions packages/contracts/contracts/base/SemaphoreVerifier.sol

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface ISemaphoreVerifier {
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[4] calldata _pubSignals
uint[4] calldata _pubSignals,
uint merkleTreeDepth
) external view returns (bool);
}
190 changes: 0 additions & 190 deletions packages/contracts/contracts/verifiers/Verifier1.sol

This file was deleted.

Loading

0 comments on commit 0ec9abb

Please sign in to comment.