Skip to content

Commit

Permalink
feat(contracts): add deployment code for SemaphoreGatekeeper (#1588)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Jun 21, 2024
1 parent 8ab3d7d commit 149df59
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions contracts/contracts/gatekeepers/SemaphoreGatekeeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ contract SemaphoreGatekeeper is SignUpGatekeeper, Ownable(msg.sender) {
if (proof.scope != groupId) revert InvalidGroup();

// register the nullifier so it cannot be called again with the same one
// note that given the nullifier will be hash(secret, groupId), the same
// identity cannot then be registered twice for this group
registeredIdentities[proof.nullifier] = true;

// check if the proof validates
Expand Down
15 changes: 15 additions & 0 deletions contracts/deploy-config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"eventId": "69c0caaa-c65d-5345-a20c-867774f18c67",
"zupassVerifier": "0x2272cdb3596617886d0F48524DA486044E0376d6"
},
"SemaphoreGatekeeper": {
"deploy": false,
"semaphoreContract": "0x0A09FB3f63c13F1C54F2fA41AFB1e7a98cffc774",
"groupId": 0
},
"MACI": {
"stateTreeDepth": 10,
"gatekeeper": "EASGatekeeper"
Expand Down Expand Up @@ -76,6 +81,11 @@
"signer2": "7654374482676219729919246464135900991450848628968334062174564799457623790084",
"eventId": "d2ce5bb2-99a3-5a61-b7e6-1cd46d2ee00d"
},
"SemaphoreGatekeeper": {
"deploy": false,
"semaphoreContract": "0x0000000000000000000000000000000000000000",
"groupId": 0
},
"MACI": {
"stateTreeDepth": 10,
"gatekeeper": "ZupassGatekeeper"
Expand Down Expand Up @@ -133,6 +143,11 @@
"eventId": "69c0caaa-c65d-5345-a20c-867774f18c67",
"zupassVerifier": "0x2272cdb3596617886d0F48524DA486044E0376d6"
},
"SemaphoreGatekeeper": {
"deploy": false,
"semaphoreContract": "0x0000000000000000000000000000000000000000",
"groupId": 0
},
"MACI": {
"stateTreeDepth": 6,
"gatekeeper": "EASGatekeeper"
Expand Down
32 changes: 31 additions & 1 deletion contracts/tasks/deploy/maci/02-gatekeepers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@ deployment.deployTask("full:deploy-gatekeepers", "Deploy gatekeepers").then((tas
const easGatekeeperContractAddress = storage.getAddress(EContracts.EASGatekeeper, hre.network.name);
const gitcoinGatekeeperContractAddress = storage.getAddress(EContracts.GitcoinPassportGatekeeper, hre.network.name);
const zupassGatekeeperContractAddress = storage.getAddress(EContracts.ZupassGatekeeper, hre.network.name);
const semaphoreGatekeeperContractAddress = storage.getAddress(EContracts.SemaphoreGatekeeper, hre.network.name);
const deployFreeForAllGatekeeper = deployment.getDeployConfigField(EContracts.FreeForAllGatekeeper, "deploy");
const deployEASGatekeeper = deployment.getDeployConfigField(EContracts.EASGatekeeper, "deploy");
const deployGitcoinGatekeeper = deployment.getDeployConfigField(EContracts.GitcoinPassportGatekeeper, "deploy");
const deployZupassGatekeeper = deployment.getDeployConfigField(EContracts.ZupassGatekeeper, "deploy");
const deploySemaphoreGatekeeper = deployment.getDeployConfigField(EContracts.SemaphoreGatekeeper, "deploy");

const skipDeployFreeForAllGatekeeper = deployFreeForAllGatekeeper !== true;
const skipDeployEASGatekeeper = deployEASGatekeeper !== true;
const skipDeployGitcoinGatekeeper = deployGitcoinGatekeeper !== true;
const skipDeployZupassGatekeeper = deployZupassGatekeeper !== true;
const skipDeploySemaphoreGatekeeper = deploySemaphoreGatekeeper !== true;

const canSkipDeploy =
incremental &&
(freeForAllGatekeeperContractAddress || skipDeployFreeForAllGatekeeper) &&
(easGatekeeperContractAddress || skipDeployEASGatekeeper) &&
(gitcoinGatekeeperContractAddress || skipDeployGitcoinGatekeeper) &&
(zupassGatekeeperContractAddress || skipDeployZupassGatekeeper) &&
(semaphoreGatekeeperContractAddress || skipDeploySemaphoreGatekeeper) &&
(!skipDeployFreeForAllGatekeeper ||
!skipDeployEASGatekeeper ||
!skipDeployGitcoinGatekeeper ||
!skipDeployZupassGatekeeper);
!skipDeployZupassGatekeeper ||
!skipDeploySemaphoreGatekeeper);

if (canSkipDeploy) {
return;
Expand Down Expand Up @@ -151,5 +156,30 @@ deployment.deployTask("full:deploy-gatekeepers", "Deploy gatekeepers").then((tas
network: hre.network.name,
});
}

if (!skipDeploySemaphoreGatekeeper) {
const semaphoreContractAddress = deployment.getDeployConfigField<string>(
EContracts.SemaphoreGatekeeper,
"semaphoreContract",
true,
);
const groupId = deployment.getDeployConfigField<number>(EContracts.SemaphoreGatekeeper, "groupId", true);

const semaphoreGatekeeperContract = await deployment.deployContract(
{
name: EContracts.SemaphoreGatekeeper,
signer: deployer,
},
semaphoreContractAddress,
groupId,
);

await storage.register({
id: EContracts.SemaphoreGatekeeper,
contract: semaphoreGatekeeperContract,
args: [semaphoreContractAddress, groupId.toString()],
network: hre.network.name,
});
}
}),
);
1 change: 1 addition & 0 deletions contracts/tasks/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ export enum EContracts {
GitcoinPassportGatekeeper = "GitcoinPassportGatekeeper",
ZupassGatekeeper = "ZupassGatekeeper",
ZupassGroth16Verifier = "ZupassGroth16Verifier",
SemaphoreGatekeeper = "SemaphoreGatekeeper",
Verifier = "Verifier",
MACI = "MACI",
StateAq = "StateAq",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The MACI repository comes with several out-of-the-box options:
- `HatsGatekeeper` - This allows gatekeeping signups to only users who have a specific [Hat](https://www.hatsprotocol.xyz/).
- `GitcoinPassportGatekeeper` - This allows gatekeeping signups to only users who have a specific [Gitcoin Passport](https://passport.gitcoin.co/) score.
- `ZupassGatekeeper` - This allows gatekeeping signups only to users who have a valid [Zupass PCD ticket](https://github.com/proofcarryingdata/zupass).
- `SemaphoreGatekeeper` - This allows gatekeeping signups only to users who can prove they are part of a [Semaphore](https://semaphore.pse.dev/) group.

You can find all of our latest gatekeeper contracts here:
https://github.com/privacy-scaling-explorations/maci/tree/dev/contracts/contracts/gatekeepers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ It's necessary to define which gatekeeper you are going to use before deploying,
"eventId": "69c0caaa-c65d-5345-a20c-867774f18c67",
"zupassVerifier": "0x2272cdb3596617886d0F48524DA486044E0376d6"
},
"SemaphoreGatekeeper": {
"deploy": false,
"semaphoreContract": "0x0000000000000000000000000000000000000000",
"groupId": 0
},
"MACI": {
"stateTreeDepth": 10,
"gatekeeper": "EASGatekeeper"
Expand Down

0 comments on commit 149df59

Please sign in to comment.