Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contracts): added message processor and tally addresses to the maci contract #1715

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cli/tests/ceremony-params/ceremonyParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ describe("Stress tests with ceremony params (6,9,2,3)", function test() {
...verifyArgs(),
tallyData: tallyFileData,
maciAddress: tallyFileData.maci,
tallyAddress: tallyFileData.tallyAddress,
signer,
});
});
Expand Down Expand Up @@ -348,7 +347,6 @@ describe("Stress tests with ceremony params (6,9,2,3)", function test() {
...verifyArgs(),
tallyData: tallyFileData,
maciAddress: tallyFileData.maci,
tallyAddress: tallyFileData.tallyAddress,
signer,
});
});
Expand Down
1 change: 0 additions & 1 deletion cli/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export const verifyArgs = (): Omit<VerifyArgs, "signer"> => {
pollId: 0n,
tallyData,
maciAddress: tallyData.maci,
tallyAddress: tallyData.tallyAddress,
};
};

Expand Down
1 change: 0 additions & 1 deletion cli/tests/e2e/e2e.nonQv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ describe("e2e tests with non quadratic voting", function test() {
...verifyArgs(),
tallyData: tallyFileData,
maciAddress: tallyFileData.maci,
tallyAddress: tallyFileData.tallyAddress,
signer,
});
});
Expand Down
40 changes: 15 additions & 25 deletions cli/tests/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
isRegisteredUser,
getGatekeeperTrait,
} from "../../ts/commands";
import { DeployedContracts, GatekeeperTrait, GenProofsArgs, PollContracts } from "../../ts/utils";
import { DeployedContracts, GatekeeperTrait, GenProofsArgs } from "../../ts/utils";
import {
deployPollArgs,
checkVerifyingKeysArgs,
Expand Down Expand Up @@ -68,7 +68,6 @@ describe("e2e tests", function test() {
this.timeout(900000);

let maciAddresses: DeployedContracts;
let pollAddresses: PollContracts;
let signer: Signer;

const genProofsArgs: Omit<GenProofsArgs, "signer"> = {
Expand Down Expand Up @@ -110,7 +109,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer, useQuadraticVoting: true });
await deployPoll({ ...deployPollArgs, signer, useQuadraticVoting: true });
});

it("should get the correct gatekeeper trait", async () => {
Expand Down Expand Up @@ -162,7 +161,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup one user", async () => {
Expand Down Expand Up @@ -195,7 +194,6 @@ describe("e2e tests", function test() {
...verifyArgs(),
tallyData: tallyFileData,
maciAddress: tallyFileData.maci,
tallyAddress: tallyFileData.tallyAddress,
signer,
});
});
Expand All @@ -212,7 +210,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup four users", async () => {
Expand Down Expand Up @@ -353,7 +351,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup nine users", async () => {
Expand Down Expand Up @@ -400,7 +398,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup eight users (same pub key)", async () => {
Expand Down Expand Up @@ -449,7 +447,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup thirty users", async () => {
Expand Down Expand Up @@ -546,7 +544,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
// signup
await signup({ maciAddress: maciAddresses.maciAddress, maciPubKey: user.pubKey.serialize(), signer });
// publish
Expand Down Expand Up @@ -574,7 +572,7 @@ describe("e2e tests", function test() {
});

it("should deploy a new poll", async () => {
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should publish a new message", async () => {
Expand Down Expand Up @@ -613,7 +611,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
// signup
await signup({ maciAddress: maciAddresses.maciAddress, maciPubKey: users[0].pubKey.serialize(), signer });
// publish
Expand Down Expand Up @@ -644,7 +642,7 @@ describe("e2e tests", function test() {
});

it("should deploy a new poll", async () => {
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup four new users", async () => {
Expand Down Expand Up @@ -705,8 +703,6 @@ describe("e2e tests", function test() {
new Keypair(),
];

let secondPollAddresses: PollContracts;

after(() => {
clean();
});
Expand All @@ -718,7 +714,7 @@ describe("e2e tests", function test() {

it("should run the first poll", async () => {
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });

// signup
// eslint-disable-next-line @typescript-eslint/prefer-for-of
Expand Down Expand Up @@ -764,8 +760,8 @@ describe("e2e tests", function test() {

it("should deploy two more polls", async () => {
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
secondPollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should publish messages to the second poll", async () => {
Expand Down Expand Up @@ -859,16 +855,13 @@ describe("e2e tests", function test() {
...proveOnChainArgs,
pollId: 1n,
maciAddress: maciAddresses.maciAddress,
messageProcessorAddress: pollAddresses.messageProcessor,
tallyAddress: pollAddresses.tally,
signer,
});
await verify({
...verifyArgs(),
pollId: 1n,
tallyData,
maciAddress: maciAddresses.maciAddress,
tallyAddress: pollAddresses.tally,
signer,
});
clean();
Expand All @@ -882,16 +875,13 @@ describe("e2e tests", function test() {
...proveOnChainArgs,
pollId: 2n,
maciAddress: maciAddresses.maciAddress,
messageProcessorAddress: secondPollAddresses.messageProcessor,
tallyAddress: secondPollAddresses.tally,
signer,
});
await verify({
...verifyArgs(),
pollId: 2n,
tallyData,
maciAddress: maciAddresses.maciAddress,
tallyAddress: secondPollAddresses.tally,
signer,
});
});
Expand All @@ -914,7 +904,7 @@ describe("e2e tests", function test() {
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
pollAddresses = await deployPoll({ ...deployPollArgs, signer });
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup one user", async () => {
Expand Down
6 changes: 3 additions & 3 deletions cli/ts/commands/genLocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export const genLocalState = async ({
const coordinatorKeypair = new Keypair(coordinatorMaciPrivKey);

const maciContract = MACIFactory.connect(maciContractAddress, signer);
const pollAddr = await maciContract.polls(pollId);
const pollContracts = await maciContract.polls(pollId);

if (!(await contractExists(signer.provider!, pollAddr))) {
if (!(await contractExists(signer.provider!, pollContracts.poll))) {
logError("Poll contract does not exist");
}
const pollContract = PollFactory.connect(pollAddr, signer);
const pollContract = PollFactory.connect(pollContracts.poll, signer);

const [{ messageAq }, { messageTreeDepth }] = await Promise.all([
pollContract.extContracts(),
Expand Down
12 changes: 4 additions & 8 deletions cli/ts/commands/genProofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const genProofs = async ({
blocksPerBatch,
endBlock,
signer,
tallyAddress,
useQuadraticVoting = true,
quiet = true,
}: GenProofsArgs): Promise<TallyData> => {
Expand Down Expand Up @@ -144,12 +143,12 @@ export const genProofs = async ({
}

const maciContract = MACIFactory.connect(maciContractAddress, signer);
const pollAddr = await maciContract.polls(pollId);
const pollContracts = await maciContract.polls(pollId);

if (!(await contractExists(signer.provider!, pollAddr))) {
if (!(await contractExists(signer.provider!, pollContracts.poll))) {
logError("Poll contract does not exist");
}
const pollContract = PollFactory.connect(pollAddr, signer);
const pollContract = PollFactory.connect(pollContracts.poll, signer);

const extContracts = await pollContract.extContracts();
const messageAqContractAddr = extContracts.messageAq;
Expand Down Expand Up @@ -356,9 +355,6 @@ export const genProofs = async ({
BigInt(asHex(tallyCircuitInputs!.newSpentVoiceCreditSubtotalSalt as BigNumberish)),
);

// get the tally contract address
const tallyContractAddress = tallyAddress || readContractAddress(`Tally-${pollId}`, network?.name);

let newPerVOSpentVoiceCreditsCommitment: bigint | undefined;
let newTallyCommitment: bigint;

Expand All @@ -369,7 +365,7 @@ export const genProofs = async ({
network: network?.name,
chainId: network?.chainId.toString(),
isQuadratic: useQuadraticVoting,
tallyAddress: tallyContractAddress,
tallyAddress: pollContracts.tally,
newTallyCommitment: asHex(tallyCircuitInputs!.newTallyCommitment as BigNumberish),
results: {
tally: poll.tallyResult.map((x) => x.toString()),
Expand Down
6 changes: 3 additions & 3 deletions cli/ts/commands/mergeMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export const mergeMessages = async ({
}

const maciContract = MACIFactory.connect(maciContractAddress, signer);
const pollAddress = await maciContract.polls(pollId);
const pollContracts = await maciContract.polls(pollId);

if (!(await contractExists(signer.provider!, pollAddress))) {
if (!(await contractExists(signer.provider!, pollContracts.poll))) {
logError("Poll contract does not exist");
}

const pollContract = PollFactory.connect(pollAddress, signer);
const pollContract = PollFactory.connect(pollContracts.poll, signer);
const extContracts = await pollContract.extContracts();
const messageAqContractAddr = extContracts.messageAq;

Expand Down
6 changes: 3 additions & 3 deletions cli/ts/commands/mergeSignups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export const mergeSignups = async ({ pollId, maciAddress, signer, quiet = true }
}

const maciContract = MACIFactory.connect(maciContractAddress, signer);
const pollAddress = await maciContract.polls(pollId);
const pollContracts = await maciContract.polls(pollId);

if (!(await contractExists(signer.provider!, pollAddress))) {
if (!(await contractExists(signer.provider!, pollContracts.poll))) {
logError("Poll contract does not exist");
}

const pollContract = PollFactory.connect(pollAddress, signer);
const pollContract = PollFactory.connect(pollContracts.poll, signer);

// check if it's time to merge the message AQ
const dd = await pollContract.getDeployTimeAndDuration();
Expand Down
2 changes: 1 addition & 1 deletion cli/ts/commands/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getPoll = async ({
logError(`Invalid poll id ${id}`);
}

const pollAddress = await maciContract.polls(id);
const { poll: pollAddress } = await maciContract.polls(id);

if (pollAddress === ZeroAddress) {
logError(`MACI contract doesn't have any deployed poll ${id}`);
Expand Down
29 changes: 5 additions & 24 deletions cli/ts/commands/proveOnChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export const proveOnChain = async ({
pollId,
proofDir,
maciAddress,
messageProcessorAddress,
tallyAddress,
signer,
quiet = true,
}: ProveOnChainArgs): Promise<void> => {
Expand All @@ -53,43 +51,26 @@ export const proveOnChain = async ({
if (!readContractAddress("MACI", network?.name) && !maciAddress) {
logError("MACI contract address is empty");
}
if (!readContractAddress(`MessageProcessor-${pollId}`, network?.name) && !messageProcessorAddress) {
logError("MessageProcessor contract address is empty");
}
if (!readContractAddress(`Tally-${pollId}`, network?.name) && !tallyAddress) {
logError("Tally contract address is empty");
}

// check validity of contract addresses
const maciContractAddress = maciAddress || readContractAddress("MACI", network?.name);
const messageProcessorContractAddress =
messageProcessorAddress || readContractAddress(`MessageProcessor-${pollId}`, network?.name);
const tallyContractAddress = tallyAddress || readContractAddress(`Tally-${pollId}`, network?.name);

// check contracts are deployed on chain
if (!(await contractExists(signer.provider!, maciContractAddress))) {
logError("MACI contract does not exist");
}

if (!(await contractExists(signer.provider!, messageProcessorContractAddress))) {
logError("MessageProcessor contract does not exist");
}

if (!(await contractExists(signer.provider!, tallyContractAddress))) {
logError("Tally contract does not exist");
}

const maciContract = MACIFactory.connect(maciContractAddress, signer);
const pollAddr = await maciContract.polls(pollId);
const pollContracts = await maciContract.polls(pollId);

if (!(await contractExists(signer.provider!, pollAddr))) {
if (!(await contractExists(signer.provider!, pollContracts.poll))) {
logError("There is no Poll contract with this poll ID linked to the specified MACI contract.");
}

const pollContract = PollFactory.connect(pollAddr, signer);
const pollContract = PollFactory.connect(pollContracts.poll, signer);

const mpContract = MessageProcessorFactory.connect(messageProcessorContractAddress, signer);
const tallyContract = TallyFactory.connect(tallyContractAddress, signer);
const mpContract = MessageProcessorFactory.connect(pollContracts.messageProcessor, signer);
const tallyContract = TallyFactory.connect(pollContracts.tally, signer);

const messageAqContractAddress = (await pollContract.extContracts()).messageAq;

Expand Down
Loading
Loading