diff --git a/packages/contracts/contracts/Semaphore.sol b/packages/contracts/contracts/Semaphore.sol index e25c638f1..bc1636372 100644 --- a/packages/contracts/contracts/Semaphore.sol +++ b/packages/contracts/contracts/Semaphore.sol @@ -27,6 +27,14 @@ contract Semaphore is ISemaphore, SemaphoreGroups { verifier = _verifier; } + /// @dev See {SemaphoreGroups-_createGroup}. + function createGroup() external override returns (uint256 groupId) { + groupId = groupCounter++; + _createGroup(groupId, msg.sender); + + groups[groupId].merkleTreeDuration = 1 hours; + } + /// @dev See {SemaphoreGroups-_createGroup}. function createGroup(address admin) external override returns (uint256 groupId) { groupId = groupCounter++; diff --git a/packages/contracts/contracts/interfaces/ISemaphore.sol b/packages/contracts/contracts/interfaces/ISemaphore.sol index 71edfe6ae..e2c425e13 100644 --- a/packages/contracts/contracts/interfaces/ISemaphore.sol +++ b/packages/contracts/contracts/interfaces/ISemaphore.sol @@ -55,6 +55,9 @@ interface ISemaphore { uint256[8] points ); + /// @dev See {SemaphoreGroups-_createGroup}. + function createGroup() external returns (uint256); + /// @dev See {SemaphoreGroups-_createGroup}. function createGroup(address admin) external returns (uint256); diff --git a/packages/contracts/test/Semaphore.ts b/packages/contracts/test/Semaphore.ts index 817fa103c..8d5607ef6 100644 --- a/packages/contracts/test/Semaphore.ts +++ b/packages/contracts/test/Semaphore.ts @@ -54,6 +54,17 @@ describe("Semaphore", () => { .to.emit(semaphoreContract, "GroupAdminUpdated") .withArgs(groupId, ZeroAddress, accountAddresses[0]) }) + + it("Should create a group without any parameters", async () => { + const groupId = 2 + + const transaction = await semaphoreContract["createGroup()"]() + + await expect(transaction).to.emit(semaphoreContract, "GroupCreated").withArgs(groupId) + await expect(transaction) + .to.emit(semaphoreContract, "GroupAdminUpdated") + .withArgs(groupId, ZeroAddress, accountAddresses[0]) + }) }) describe("# updateGroupMerkleTreeDuration", () => { @@ -132,7 +143,7 @@ describe("Semaphore", () => { }) it("Should add new members to an existing group", async () => { - const groupId = 2 + const groupId = 3 const members = [BigInt(1), BigInt(2), BigInt(3)] const group = new Group() @@ -161,7 +172,7 @@ describe("Semaphore", () => { }) it("Should update a member from an existing group", async () => { - const groupId = 3 + const groupId = 4 const members = [BigInt(1), BigInt(2), BigInt(3)] const group = new Group() @@ -195,7 +206,7 @@ describe("Semaphore", () => { }) it("Should remove a member from an existing group", async () => { - const groupId = 4 + const groupId = 5 const members = [BigInt(1), BigInt(2), BigInt(3)] const group = new Group() @@ -229,7 +240,7 @@ describe("Semaphore", () => { }) describe("# verifyProof", () => { - const groupId = 5 + const groupId = 6 const message = 2 const identity = new Identity("0") @@ -301,7 +312,7 @@ describe("Semaphore", () => { }) it("Should not verify a proof if the group has no members", async () => { - const groupId = 6 + const groupId = 7 await semaphoreContract["createGroup(address)"](accountAddresses[0]) const transaction = semaphoreContract.verifyProof(groupId, proof) @@ -313,7 +324,7 @@ describe("Semaphore", () => { describe("# validateProof", () => { const message = 2 const identity = new Identity("0") - const groupOneMemberId = 6 + const groupOneMemberId = 7 const group = new Group() const groupOneMember = new Group()