Skip to content

Commit

Permalink
Merge pull request #1531 from privacy-scaling-explorations/feat/zupas…
Browse files Browse the repository at this point in the history
…s-gatekeeper-deployer

feat(deploy-task): added zupass gatekeeper to the deploy tasks
  • Loading branch information
crisgarner authored Jun 5, 2024
2 parents dbeddbd + 9a09a8b commit f0b482d
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 11 deletions.
10 changes: 5 additions & 5 deletions contracts/contracts/gatekeepers/zupass/ZupassGatekeeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

import { SignUpGatekeeper } from "../SignUpGatekeeper.sol";

import { Groth16Verifier } from "./Groth16Verifier.sol";
import { ZupassGroth16Verifier } from "./ZupassGroth16Verifier.sol";

/// @title ZupassGatekeeper
/// @notice This contract allows to gatekeep MACI signups
Expand All @@ -18,8 +18,8 @@ contract ZupassGatekeeper is SignUpGatekeeper, Ownable(msg.sender) {
uint256 public immutable validSigner1;
uint256 public immutable validSigner2;

/// @notice the Groth16Verifier contract address
Groth16Verifier public immutable verifier;
/// @notice the ZupassGroth16Verifier contract address
ZupassGroth16Verifier public immutable verifier;

/// @notice the reference to the MACI contract
address public maci;
Expand All @@ -40,12 +40,12 @@ contract ZupassGatekeeper is SignUpGatekeeper, Ownable(msg.sender) {
/// @param _validEventId Zupass event UUID converted to bigint
/// @param _validSigner1 Zupass event signer[0] converted to bigint
/// @param _validSigner2 Zupass event signer[1] converted to bigint
/// @param _verifier The Groth16Verifier contract address
/// @param _verifier The ZupassGroth16Verifier contract address
constructor(uint256 _validEventId, uint256 _validSigner1, uint256 _validSigner2, address _verifier) payable {
validEventId = _validEventId;
validSigner1 = _validSigner1;
validSigner2 = _validSigner2;
verifier = Groth16Verifier(_verifier);
verifier = ZupassGroth16Verifier(_verifier);
}

/// @notice Adds an uninitialised MACI instance to allow for token signups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

pragma solidity ^0.8.20;

contract Groth16Verifier {
contract ZupassGroth16Verifier {
// Scalar field size
uint256 private constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;

Check warning on line 25 in contracts/contracts/gatekeepers/zupass/ZupassGroth16Verifier.sol

View workflow job for this annotation

GitHub Actions / check (lint:sol)

Constant name must be in capitalized SNAKE_CASE
// Base field size
Expand Down
7 changes: 7 additions & 0 deletions contracts/deploy-config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"decoderAddress": "0xe53C60F8069C2f0c3a84F9B3DB5cf56f3100ba56",
"passingScore": 5
},
"ZupassGatekeeper": {
"deploy": false,
"signer1": "13908133709081944902758389525983124100292637002438232157513257158004852609027",
"signer2": "7654374482676219729919246464135900991450848628968334062174564799457623790084",
"eventId": "69c0caaa-c65d-5345-a20c-867774f18c67",
"zupassVerifier": "0x2272cdb3596617886d0F48524DA486044E0376d6"
},
"MACI": {
"stateTreeDepth": 10,
"gatekeeper": "EASGatekeeper"
Expand Down
4 changes: 3 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"maci-core": "1.2.2",
"maci-crypto": "1.2.2",
"maci-domainobjs": "1.2.2",
"solidity-docgen": "^0.6.0-beta.36"
"solidity-docgen": "^0.6.0-beta.36",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/chai": "^4.3.11",
Expand All @@ -93,6 +94,7 @@
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.12",
"@types/snarkjs": "^0.7.8",
"@types/uuid": "^9.0.2",
"chai": "^4.3.10",
"dotenv": "^16.4.5",
"hardhat-artifactor": "^0.2.0",
Expand Down
43 changes: 42 additions & 1 deletion contracts/tasks/deploy/maci/02-gatekeepers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ESupportedChains } from "../../helpers/constants";
import { ContractStorage } from "../../helpers/ContractStorage";
import { Deployment } from "../../helpers/Deployment";
import { uuidToBigInt } from "../../helpers/numericParser";
import { EContracts, IDeployParams } from "../../helpers/types";

const deployment = Deployment.getInstance();
Expand All @@ -17,20 +18,27 @@ deployment.deployTask("full:deploy-gatekeepers", "Deploy gatekeepers").then((tas
const freeForAllGatekeeperContractAddress = storage.getAddress(EContracts.FreeForAllGatekeeper, hre.network.name);
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 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 skipDeployFreeForAllGatekeeper = deployFreeForAllGatekeeper !== true;
const skipDeployEASGatekeeper = deployEASGatekeeper !== true;
const skipDeployGitcoinGatekeeper = deployGitcoinGatekeeper !== true;
const skipDeployZupassGatekeeper = deployZupassGatekeeper !== true;

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

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

if (!skipDeployZupassGatekeeper) {
const eventId = deployment.getDeployConfigField<string>(EContracts.ZupassGatekeeper, "eventId", true);
const validEventId = uuidToBigInt(eventId);
const validSigner1 = deployment.getDeployConfigField<string>(EContracts.ZupassGatekeeper, "signer1", true);
const validSigner2 = deployment.getDeployConfigField<string>(EContracts.ZupassGatekeeper, "signer2", true);
let verifier = deployment.getDeployConfigField<string | undefined>(EContracts.ZupassGatekeeper, "zupassVerifier");

if (!verifier) {
const verifierContract = await deployment.deployContract({
name: EContracts.ZupassGroth16Verifier,
signer: deployer,
});
verifier = await verifierContract.getAddress();
}

const ZupassGatekeeperContract = await deployment.deployContract(
{
name: EContracts.ZupassGatekeeper,
signer: deployer,
},
validEventId,
validSigner1,
validSigner2,
verifier,
);
await storage.register({
id: EContracts.ZupassGatekeeper,
contract: ZupassGatekeeperContract,
args: [validEventId.toString(), validSigner1, validSigner2, verifier],
network: hre.network.name,
});
}
}),
);
9 changes: 8 additions & 1 deletion contracts/tasks/deploy/maci/08-maci.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EASGatekeeper, GitcoinPassportGatekeeper, MACI } from "../../../typechain-types";
import type { EASGatekeeper, GitcoinPassportGatekeeper, ZupassGatekeeper, MACI } from "../../../typechain-types";

import { ContractStorage } from "../../helpers/ContractStorage";
import { Deployment } from "../../helpers/Deployment";
Expand Down Expand Up @@ -81,6 +81,13 @@ deployment.deployTask("full:deploy-maci", "Deploy MACI contract").then((task) =>
});
const maciInstanceAddress = await maciContract.getAddress();

await gatekeeperContract.setMaciInstance(maciInstanceAddress).then((tx) => tx.wait());
} else if (gatekeeper === EContracts.ZupassGatekeeper) {
const gatekeeperContract = await deployment.getContract<ZupassGatekeeper>({
name: EContracts.ZupassGatekeeper,
address: gatekeeperContractAddress,
});
const maciInstanceAddress = await maciContract.getAddress();
await gatekeeperContract.setMaciInstance(maciInstanceAddress).then((tx) => tx.wait());
}

Expand Down
10 changes: 10 additions & 0 deletions contracts/tasks/helpers/numericParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { parse as uuidParse } from "uuid";

/**
* Converts a UUID string into a bigint.
*/
export function uuidToBigInt(v: string): bigint {
// a uuid is just a particular representation of 16 bytes
const bytes = uuidParse(v);
return BigInt(`0x${Buffer.from(bytes).toString("hex")}`);
}
2 changes: 2 additions & 0 deletions contracts/tasks/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ export enum EContracts {
FreeForAllGatekeeper = "FreeForAllGatekeeper",
EASGatekeeper = "EASGatekeeper",
GitcoinPassportGatekeeper = "GitcoinPassportGatekeeper",
ZupassGatekeeper = "ZupassGatekeeper",
ZupassGroth16Verifier = "ZupassGroth16Verifier",
Verifier = "Verifier",
MACI = "MACI",
StateAq = "StateAq",
Expand Down
2 changes: 1 addition & 1 deletion contracts/tests/ZupassGatekeeper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Zupass Gatekeeper", () => {

before(async () => {
signer = await getDefaultSigner();
const verifier = await deployContract("Groth16Verifier", signer, true);
const verifier = await deployContract("ZupassGroth16Verifier", signer, true);
const verifierAddress = await verifier.getAddress();
signerAddress = await signer.getAddress();
zupassGatekeeper = await deployContract(
Expand Down
11 changes: 10 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f0b482d

Please sign in to comment.