Skip to content

Commit

Permalink
refactor(remove messageaqfactory): remove messageAqFactory; remove re…
Browse files Browse the repository at this point in the history
…dundant pollFactory dependency
  • Loading branch information
chaosma committed Jan 18, 2023
1 parent 26b08eb commit dcd1c67
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 69 deletions.
2 changes: 1 addition & 1 deletion circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"dependencies": {
"argparse": "^2.0.1",
"circomlib": "github:weijiekoh/circomlib#ac85e82c1914d47789e2032fb11ceb2cfdd38a2b",
"circomlib": "https://github.com/weijiekoh/circomlib#ac85e82c1914d47789e2032fb11ceb2cfdd38a2b",
"shelljs": "^0.8.3",
"snarkjs": "^0.5.0",
"tmp": "^0.2.1"
Expand Down
1 change: 1 addition & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"shelljs": "^0.8.4",
"snarkjs": "^0.5.0",
"source-map-support": "^0.5.19",
"typescript": "^4.2.3",
"web3": "^1.3.4",
"xmlhttprequest": "1.8.0",
"zkey-manager": "^0.1.1"
Expand Down
2 changes: 0 additions & 2 deletions cli/ts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ const create = async (args: any) => {
maciContract,
stateAqContract,
pollFactoryContract,
messageAqContract,
} = await deployMaci(
signUpGatekeeperAddress,
initialVoiceCreditProxyContractAddress,
Expand All @@ -129,7 +128,6 @@ const create = async (args: any) => {
contractAddrs['MACI'] = maciContract.address
contractAddrs['StateAq'] = stateAqContract.address
contractAddrs['PollFactory'] = pollFactoryContract.address
contractAddrs['MessageAqFactory'] = messageAqContract.address
contractAddrs['TopupCredit'] = TopupCreditContract.address
writeJSONFile(contractFilepath, contractAddrs)

Expand Down
19 changes: 3 additions & 16 deletions contracts/contracts/MACI.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {Poll, PollFactory, PollProcessorAndTallyer, MessageAqFactory} from "./Poll.sol";
import {Poll, PollFactory, PollProcessorAndTallyer} from "./Poll.sol";
import {InitialVoiceCreditProxy} from "./initialVoiceCreditProxy/InitialVoiceCreditProxy.sol";
import {SignUpGatekeeper} from "./gatekeepers/SignUpGatekeeper.sol";
import {AccQueue, AccQueueQuinaryBlankSl} from "./trees/AccQueue.sol";
Expand Down Expand Up @@ -62,7 +62,6 @@ contract MACI is IMACI, DomainObjs, Params, SnarkCommon, Ownable {
TopupCredit public topupCredit;

PollFactory public pollFactory;
MessageAqFactory public messageAqFactory;

// The state AccQueue. Represents a mapping between each user's public key
// and their voice credit balance.
Expand All @@ -84,7 +83,7 @@ contract MACI is IMACI, DomainObjs, Params, SnarkCommon, Ownable {
uint256 public signUpTimestamp;

// Events
event Init(VkRegistry _vkRegistry, MessageAqFactory _messageAqFactory);
event Init(VkRegistry _vkRegistry, TopupCredit _topupCredit);
event SignUp(
uint256 _stateIndex,
PubKey _userPubKey,
Expand Down Expand Up @@ -144,20 +143,17 @@ contract MACI is IMACI, DomainObjs, Params, SnarkCommon, Ownable {
* Initialise the various factory/helper contracts. This should only be run
* once and it must be run before deploying the first Poll.
* @param _vkRegistry The VkRegistry contract
* @param _messageAqFactory The MessageAqFactory contract
* @param _topupCredit The topupCredit contract
*/
function init(
VkRegistry _vkRegistry,
MessageAqFactory _messageAqFactory,
TopupCredit _topupCredit
) public onlyOwner {
require(!isInitialised, "MACI: already initialised");

isInitialised = true;

vkRegistry = _vkRegistry;
messageAqFactory = _messageAqFactory;
topupCredit = _topupCredit;

// Check that the factory contracts have correct access controls before
Expand All @@ -167,22 +163,13 @@ contract MACI is IMACI, DomainObjs, Params, SnarkCommon, Ownable {
"MACI: PollFactory owner incorrectly set"
);

// The PollFactory needs to store the MessageAqFactory address
pollFactory.setMessageAqFactory(messageAqFactory);

// The MessageAQFactory owner must be the PollFactory contract
require(
messageAqFactory.owner() == address(pollFactory),
"MACI: MessageAqFactory owner incorrectly set"
);

// The VkRegistry owner must be the owner of this contract
require(
vkRegistry.owner() == owner(),
"MACI: VkRegistry owner incorrectly set"
);

emit Init(_vkRegistry, _messageAqFactory);
emit Init(_vkRegistry, _topupCredit);
}

/*
Expand Down
28 changes: 2 additions & 26 deletions contracts/contracts/Poll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ import {VkRegistry} from "./VkRegistry.sol";
import {EmptyBallotRoots} from "./trees/EmptyBallotRoots.sol";
import {TopupCredit} from "./TopupCredit.sol";

contract MessageAqFactory is Ownable {
/*
* Deploys a new AccQueue contract
* @param _subDepth Subtree depth
* @return AccQueue The AccQueue contract
*/
function deploy(uint256 _subDepth) public onlyOwner returns (AccQueue) {
AccQueue aq = new AccQueueQuinaryMaci(_subDepth);
aq.transferOwnership(owner());
return aq;
}
}

contract PollDeploymentParams {
struct ExtContracts {
VkRegistry vkRegistry;
Expand Down Expand Up @@ -95,19 +82,10 @@ contract Utilities is SnarkConstants, Hasher, IPubKey, IMessage {
*/
contract PollFactory is
Params,
Utilities,
IPubKey,
Ownable,
PollDeploymentParams
{
MessageAqFactory public messageAqFactory;

function setMessageAqFactory(MessageAqFactory _messageAqFactory)
public
onlyOwner
{
messageAqFactory = _messageAqFactory;
}

/*
* Deploy a new Poll contract and AccQueue contract for messages.
*/
Expand Down Expand Up @@ -143,9 +121,7 @@ contract PollFactory is
"PollFactory: invalid _maxValues"
);

AccQueue messageAq = messageAqFactory.deploy(
_treeDepths.messageTreeSubDepth
);
AccQueue messageAq = new AccQueueQuinaryMaci(_treeDepths.messageTreeSubDepth);

ExtContracts memory extContracts;

Expand Down
2 changes: 1 addition & 1 deletion contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
settings: {
optimizer: {
enabled: true,
runs: 100
runs: 200
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"hardhat": "^2.12.2",
"hardhat-artifactor": "^0.2.0",
"hardhat-contract-sizer": "^2.0.3",
"module-alias": "^2.2.2"
"module-alias": "^2.2.2",
"typescript": "^4.2.3"
},
"devDependencies": {
"@types/jest": "^26.0.21",
Expand Down
19 changes: 2 additions & 17 deletions contracts/ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ const deployPpt = async (verifierContractAddress: string, quiet = false) => {
return await deployContract('PollProcessorAndTallyer', quiet, verifierContractAddress)
}

const deployMessageAqFactory = async (quiet = false) => {
return await deployContract('MessageAqFactory', quiet)
}

// Deploy a contract given a name and args
const deployContract = async (contractName: string, quiet: boolean = false, ...args: any) : Promise<Contract> => {
log(`Deploying ${contractName}`, quiet)
Expand Down Expand Up @@ -248,7 +244,7 @@ const deployMaci = async (
PoseidonT6Contract,
} = await deployPoseidonContracts(quiet)

const contractsToLink = ['MACI', 'PollFactory', 'MessageAqFactory']
const contractsToLink = ['MACI', 'PollFactory']

// Link Poseidon contracts to MACI
const linkedContractFactories = contractsToLink.map(async (contractName: string) => {
Expand All @@ -265,7 +261,6 @@ const deployMaci = async (
const [
maciContractFactory,
pollFactoryContractFactory,
messageAqFactory,
] = await Promise.all(linkedContractFactories)

const pollFactoryContract = await deployContractWithLinkedLibraries(
Expand All @@ -286,15 +281,7 @@ const deployMaci = async (
log('Transferring ownership of PollFactoryContract to MACI', quiet)
await transferOwnership(pollFactoryContract, maciContract.address, quiet)

const messageAqContract = await deployContractWithLinkedLibraries(
messageAqFactory,
'MessageAqFactory'
)

log('Transferring MessageAqFactory ownership to PollFactory', quiet)
await transferOwnership(messageAqContract, pollFactoryContract.address, quiet)

await initMaci(maciContract, quiet, vkRegistryContractAddress, messageAqContract.address, topupCreditContractAddress)
await initMaci(maciContract, quiet, vkRegistryContractAddress, topupCreditContractAddress)

const [ AccQueueQuinaryMaciAbi, ] = parseArtifact('AccQueue')
const stateAqContractAddress = await maciContract.stateAq()
Expand All @@ -308,7 +295,6 @@ const deployMaci = async (
maciContract,
stateAqContract,
pollFactoryContract,
messageAqContract,
}
}

Expand Down Expand Up @@ -351,7 +337,6 @@ export {
deployVerifier,
deployPollFactory,
deployPpt,
deployMessageAqFactory,
genJsonRpcDeployer,
getInitialVoiceCreditProxyAbi,
initMaci,
Expand Down
2 changes: 0 additions & 2 deletions contracts/ts/genMaciState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ const genMaciStateFromContract = async (
fromBlock: fromBlock,
})

let messageAqFactoryAddress
let vkRegistryAddress

for (const log of initLogs) {
const event = maciIface.parseLog(log)
vkRegistryAddress = event.args._vkRegistry
messageAqFactoryAddress = event.args._messageAqFactory
}

const actions: Action[] = []
Expand Down
2 changes: 0 additions & 2 deletions contracts/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
deployFreeForAllSignUpGatekeeper,
deployPollFactory,
deployPpt,
deployMessageAqFactory,
getInitialVoiceCreditProxyAbi,
abiDir,
parseArtifact,
Expand Down Expand Up @@ -40,7 +39,6 @@ export {
deployConstantInitialVoiceCreditProxy,
deployPollFactory,
deployPpt,
deployMessageAqFactory,
deployTestContracts,
getInitialVoiceCreditProxyAbi,
formatProofForVerifierContract,
Expand Down
2 changes: 1 addition & 1 deletion crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"blake-hash": "^1.1.0",
"circomlib": "git://github.com/weijiekoh/circomlib.git#24ed08eee0bb613b8c0135d66c1013bd9f78d50a",
"circomlib": "https://github.com/weijiekoh/circomlib.git#24ed08eee0bb613b8c0135d66c1013bd9f78d50a",
"ethers": "^5.0.32",
"ffjavascript": "^0.2.57",
"optimisedmt": "^0.0.7"
Expand Down

0 comments on commit dcd1c67

Please sign in to comment.