Skip to content

Commit

Permalink
refactor(deploy-tasks): added recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
Crisgarner committed Jun 5, 2024
1 parent 3cc00dc commit 76c5652
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 46 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;
// Base field size
Expand Down
3 changes: 2 additions & 1 deletion contracts/deploy-config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"deploy": false,
"signer1": "13908133709081944902758389525983124100292637002438232157513257158004852609027",
"signer2": "7654374482676219729919246464135900991450848628968334062174564799457623790084",
"eventId": "69c0caaa-c65d-5345-a20c-867774f18c67"
"eventId": "69c0caaa-c65d-5345-a20c-867774f18c67",
"zupassVerifier": "0x2272cdb3596617886d0F48524DA486044E0376d6"
},
"MACI": {
"stateTreeDepth": 10,
Expand Down
11 changes: 5 additions & 6 deletions contracts/tasks/deploy/maci/02-gatekeepers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ESupportedChains } from "../../helpers/constants";
import { ContractStorage } from "../../helpers/ContractStorage";
import { Deployment } from "../../helpers/Deployment";
import { uuidToBigInt } from "../../helpers/NumericRepresentation";
import { uuidToBigInt } from "../../helpers/numericRepresentation";
import { EContracts, IDeployParams } from "../../helpers/types";

const deployment = Deployment.getInstance();
Expand Down Expand Up @@ -124,17 +124,16 @@ deployment.deployTask("full:deploy-gatekeepers", "Deploy gatekeepers").then((tas
const validEventId = uuidToBigInt(eventId);
const validSigner1 = deployment.getDeployConfigField<string>(EContracts.ZupassGatekeeper, "signer1", true);
const validSigner2 = deployment.getDeployConfigField<string>(EContracts.ZupassGatekeeper, "signer2", true);
let verifier: string | undefined = deployment.getDeployConfigField<string>(
EContracts.ZupassGatekeeper,
"zupassVerifier",
);
let verifier = deployment.getDeployConfigField<string | undefined>(EContracts.ZupassGatekeeper, "zupassVerifier");

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

const ZupassGatekeeperContract = await deployment.deployContract(
{
name: EContracts.ZupassGatekeeper,
Expand Down
34 changes: 3 additions & 31 deletions contracts/tasks/helpers/NumericRepresentation.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
import { parse as uuidParse, stringify as uuidStringify } from "uuid";

/**
* Converts a byte array to a hex string. Opposite of fromHexString().
*/
export function toHexString(bytes: Uint8Array): string {
return Buffer.from(bytes).toString("hex");
}

/**
* Converts a hex string to a byte-array. Opposite of toHexString().
*/
export function fromHexString(hexString: string): Buffer {
return Buffer.from(hexString, "hex");
}

/**
* Converts a number (as decimal string) to a UUID (as string) in the
* format of uuid.stringify.
*/
export function decStringToBigIntToUuid(value: string): string {
let hexStr = BigInt(value).toString(16);
while (hexStr.length < 32) {
hexStr = `0${hexStr}`;
}
const buf = Buffer.from(hexStr, "hex");
return uuidStringify(buf);
}
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: Uint8Array = uuidParse(v);
const hex = `0x${Buffer.from(bytes).toString("hex")}`;
return BigInt(hex);
const bytes = uuidParse(v);
return BigInt(`0x${Buffer.from(bytes).toString("hex")}`);
}
2 changes: 1 addition & 1 deletion contracts/tasks/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export enum EContracts {
EASGatekeeper = "EASGatekeeper",
GitcoinPassportGatekeeper = "GitcoinPassportGatekeeper",
ZupassGatekeeper = "ZupassGatekeeper",
Groth16Verifier = "Groth16Verifier",
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

0 comments on commit 76c5652

Please sign in to comment.