-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [x] Add deploy vk registry task - [x] Add deploy poll task - [x] Simplify deploy runner
- Loading branch information
Showing
16 changed files
with
480 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ MNEMONIC= | |
ETHERSCAN_API_KEY= | ||
INFURA_KEY= | ||
OP_RPC_URL= | ||
GAS_PRICE= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { extractVk } from "maci-circuits"; | ||
import { VerifyingKey } from "maci-domainobjs"; | ||
|
||
import type { IVerifyingKeyStruct } from "../../../ts"; | ||
import type { BaseContract, BaseContractMethod, BigNumberish, TransactionResponse } from "ethers"; | ||
|
||
import { ContractStorage } from "../../helpers/ContractStorage"; | ||
import { Deployment } from "../../helpers/Deployment"; | ||
import { EContracts, IDeployParams } from "../../helpers/types"; | ||
|
||
// Add type manually because typechain is not available during compilation | ||
interface VkRegistry extends BaseContract { | ||
setVerifyingKeys: BaseContractMethod< | ||
[BigNumberish, BigNumberish, BigNumberish, BigNumberish, BigNumberish, IVerifyingKeyStruct, IVerifyingKeyStruct], | ||
TransactionResponse | ||
>; | ||
setSubsidyKeys: BaseContractMethod< | ||
[BigNumberish, BigNumberish, BigNumberish, IVerifyingKeyStruct], | ||
TransactionResponse | ||
>; | ||
} | ||
|
||
const deployment = Deployment.getInstance(); | ||
const storage = ContractStorage.getInstance(); | ||
|
||
/** | ||
* Deploy step registration and task itself | ||
*/ | ||
deployment | ||
.deployTask("full:deploy-vk-registry", "Deploy Vk Registry and set keys") | ||
.setAction(async ({ incremental }: IDeployParams, hre) => { | ||
deployment.setHre(hre); | ||
const deployer = await deployment.getDeployer(); | ||
|
||
const vkRegistryContractAddress = storage.getAddress(EContracts.VkRegistry, hre.network.name); | ||
|
||
if (incremental && vkRegistryContractAddress) { | ||
return; | ||
} | ||
|
||
const stateTreeDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "stateTreeDepth"); | ||
const intStateTreeDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "intStateTreeDepth"); | ||
const messageTreeDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "messageTreeDepth"); | ||
const messageBatchDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "messageBatchDepth"); | ||
const voteOptionTreeDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "voteOptionTreeDepth"); | ||
const processMessagesZkeyPath = deployment.getDeployConfigField<string>( | ||
EContracts.VkRegistry, | ||
"processMessagesZkey", | ||
); | ||
const tallyVotesZkeyPath = deployment.getDeployConfigField<string>(EContracts.VkRegistry, "tallyVotesZkey"); | ||
const subsidyZkeyPath = deployment.getDeployConfigField<string | null>(EContracts.VkRegistry, "subsidyZkey"); | ||
|
||
const [processVk, tallyVk, subsidyVk] = await Promise.all([ | ||
extractVk(processMessagesZkeyPath), | ||
extractVk(tallyVotesZkeyPath), | ||
subsidyZkeyPath && extractVk(subsidyZkeyPath), | ||
]).then((vks) => vks.map((vk) => (vk ? VerifyingKey.fromObj(vk) : null))); | ||
|
||
const vkRegistryContract = await deployment.deployContract<VkRegistry>(EContracts.VkRegistry, deployer); | ||
|
||
await vkRegistryContract | ||
.setVerifyingKeys( | ||
stateTreeDepth, | ||
intStateTreeDepth, | ||
messageTreeDepth, | ||
voteOptionTreeDepth, | ||
5 ** messageBatchDepth, | ||
processVk!.asContractParam() as IVerifyingKeyStruct, | ||
tallyVk!.asContractParam() as IVerifyingKeyStruct, | ||
) | ||
.then((tx) => tx.wait()); | ||
|
||
if (subsidyVk) { | ||
await vkRegistryContract | ||
.setSubsidyKeys( | ||
stateTreeDepth, | ||
intStateTreeDepth, | ||
voteOptionTreeDepth, | ||
subsidyVk.asContractParam() as IVerifyingKeyStruct, | ||
) | ||
.then((tx) => tx.wait()); | ||
} | ||
|
||
await storage.register({ | ||
id: EContracts.VkRegistry, | ||
contract: vkRegistryContract, | ||
args: [], | ||
network: hre.network.name, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* eslint-disable no-console */ | ||
import { BaseContract, BaseContractMethod, BigNumberish, TransactionResponse } from "ethers"; | ||
import { IG1ContractParams, PubKey } from "maci-domainobjs"; | ||
|
||
import { parseArtifact } from "../../../ts/abi"; | ||
import { ContractStorage } from "../../helpers/ContractStorage"; | ||
import { Deployment } from "../../helpers/Deployment"; | ||
import { EContracts } from "../../helpers/types"; | ||
|
||
const deployment = Deployment.getInstance(); | ||
const storage = ContractStorage.getInstance(); | ||
|
||
// Add type manually because typechain is not available during compilation | ||
type TDeployPollParams = [ | ||
BigNumberish, | ||
{ | ||
intStateTreeDepth: BigNumberish; | ||
messageTreeSubDepth: BigNumberish; | ||
messageTreeDepth: BigNumberish; | ||
voteOptionTreeDepth: BigNumberish; | ||
}, | ||
IG1ContractParams, | ||
string, | ||
string, | ||
boolean, | ||
]; | ||
|
||
interface MACI extends BaseContract { | ||
nextPollId: () => Promise<bigint>; | ||
stateAq: () => Promise<string>; | ||
deployPoll: BaseContractMethod<TDeployPollParams, TransactionResponse & [string]>; | ||
} | ||
|
||
interface StateAq extends BaseContract { | ||
treeMerged: () => Promise<boolean>; | ||
} | ||
|
||
interface Poll extends BaseContract { | ||
maxValues: () => Promise<[BigNumberish, BigNumberish]>; | ||
extContracts: () => Promise<[string, string, string]>; | ||
} | ||
|
||
/** | ||
* Deploy step registration and task itself | ||
*/ | ||
deployment.deployTask("poll:deploy-poll", "Deploy poll").setAction(async (_, hre) => { | ||
deployment.setHre(hre); | ||
const deployer = await deployment.getDeployer(); | ||
|
||
const maciContractAddress = storage.getAddress(EContracts.MACI, hre.network.name); | ||
const verifierContractAddress = storage.getAddress(EContracts.Verifier, hre.network.name); | ||
const vkRegistryContractAddress = storage.getAddress(EContracts.VkRegistry, hre.network.name); | ||
|
||
if (!maciContractAddress) { | ||
throw new Error("Need to deploy MACI contract first"); | ||
} | ||
|
||
if (!verifierContractAddress) { | ||
throw new Error("Need to deploy Verifier contract first"); | ||
} | ||
|
||
if (!vkRegistryContractAddress) { | ||
throw new Error("Need to deploy VkRegistry contract first"); | ||
} | ||
|
||
const [maciAbi] = parseArtifact("MACI"); | ||
const maciContract = new BaseContract(maciContractAddress, maciAbi, deployer) as MACI; | ||
const pollId = await maciContract.nextPollId(); | ||
const stateAqContractAddress = await maciContract.stateAq(); | ||
|
||
const [stateAqAbi] = parseArtifact("AccQueue"); | ||
const stateAq = new BaseContract(stateAqContractAddress, stateAqAbi, deployer) as StateAq; | ||
const isTreeMerged = await stateAq.treeMerged(); | ||
|
||
if (pollId > 0n && !isTreeMerged) { | ||
console.log("Previous poll is not completed"); | ||
return; | ||
} | ||
|
||
const coordinatorPubkey = deployment.getDeployConfigField<string>(EContracts.Poll, "coordinatorPubkey"); | ||
const pollDuration = deployment.getDeployConfigField<number>(EContracts.Poll, "pollDuration"); | ||
const intStateTreeDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "intStateTreeDepth"); | ||
const messageTreeSubDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "messageBatchDepth"); | ||
const messageTreeDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "messageTreeDepth"); | ||
const voteOptionTreeDepth = deployment.getDeployConfigField<number>(EContracts.VkRegistry, "voteOptionTreeDepth"); | ||
const subsidyEnabled = deployment.getDeployConfigField<boolean | null>(EContracts.Poll, "subsidyEnabled") ?? false; | ||
const unserializedKey = PubKey.deserialize(coordinatorPubkey); | ||
|
||
const deployPollParams: TDeployPollParams = [ | ||
pollDuration, | ||
{ | ||
intStateTreeDepth, | ||
messageTreeSubDepth, | ||
messageTreeDepth, | ||
voteOptionTreeDepth, | ||
}, | ||
unserializedKey.asContractParam(), | ||
verifierContractAddress, | ||
vkRegistryContractAddress, | ||
subsidyEnabled, | ||
]; | ||
|
||
const [pollAddress] = await maciContract.deployPoll.staticCall(...deployPollParams); | ||
const tx = await maciContract.deployPoll(...deployPollParams); | ||
const receipt = await tx.wait(); | ||
|
||
if (receipt?.status !== 1) { | ||
throw new Error("Deploy poll transaction is failed"); | ||
} | ||
|
||
const [pollAbi] = parseArtifact("Poll"); | ||
const pollContract = new BaseContract(pollAddress, pollAbi, deployer) as Poll; | ||
const [maxValues, extContracts] = await Promise.all([pollContract.maxValues(), pollContract.extContracts()]); | ||
|
||
await storage.register({ | ||
id: EContracts.Poll, | ||
key: pollId, | ||
contract: pollContract, | ||
args: [ | ||
pollDuration, | ||
maxValues.map((value) => value.toString()), | ||
{ | ||
intStateTreeDepth, | ||
messageTreeSubDepth, | ||
messageTreeDepth, | ||
voteOptionTreeDepth, | ||
}, | ||
unserializedKey.asContractParam(), | ||
extContracts, | ||
], | ||
network: hre.network.name, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.