Skip to content

Commit

Permalink
chore: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kittybest committed Jan 11, 2024
2 parents e510d81 + 0689040 commit 3531840
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 239 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [master, dev]
branches: [dev]
pull_request:

env:
Expand Down Expand Up @@ -43,6 +43,11 @@ jobs:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
# Depending on the STATE_TREE_DEPTH param, there
# might be changes in the EmptyBallotRoots.sol file
git add contracts/contracts/trees/EmptyBallotRoots.sol
git diff --staged --quiet || git commit -m "Commit changes before publishing"
lerna version 0.0.0-ci.$(git rev-parse --short HEAD) --no-push --yes
lerna publish from-git --dist-tag ci --yes
env:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ jobs:
- name: Publish NPM
run: |
# Depending on the STATE_TREE_DEPTH param, there
# might be changes in the EmptyBallotRoots.sol file
git add contracts/contracts/trees/EmptyBallotRoots.sol
git diff --staged --quiet || git commit -m "Commit changes before publishing"
npx lerna publish from-git --yes
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 4 additions & 0 deletions cli/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
## and that none of these values are mandatory for testing
## purposes

# Ethereum provider, replace with your own
# needed if running in production against
# a test network
ETH_PROVIDER="the_eth_provider_url"
# Ethereum secret key, replace with your own
# needed if running in production against
# a test network
Expand Down
3 changes: 3 additions & 0 deletions cli/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import "@nomicfoundation/hardhat-toolbox";
import { config as envConfig } from "dotenv";

import path from "path";

import type { HardhatUserConfig } from "hardhat/config";

import { DEFAULT_ETH_SK, DEFAULT_ETH_PROVIDER } from "./ts/utils/defaults";

envConfig();

const parentDir = __dirname.includes("build") ? ".." : "";

const config: HardhatUserConfig = {
Expand Down
6 changes: 4 additions & 2 deletions cli/testScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js setVerifyingKeys
HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js create -s 10
HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js deployPoll \
--pubkey macipk.ea638a3366ed91f2e955110888573861f7c0fc0bb5fb8b8dca9cd7a08d7d6b93 \
-t 30 -g 25 -mv 25 -i 1 -m 2 -b 1 -v 2
-t 30 -g 25 -mv 25 -i 1 -m 2 -b 1 -v 2 -d false
HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js signup \
--pubkey macipk.e743ffb5298ef0f5c1f63b6464a48fea19ea7ee5a885c67ae1b24a1d04f03f07
HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js publish \
Expand Down Expand Up @@ -47,7 +47,9 @@ HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js genProofs \
-w true
HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js proveOnChain \
--poll-id 0 \
--proof-dir proofs/
--proof-dir proofs/ \
--deploy-subsidy false
HARDHAT_CONFIG=./build/hardhat.config.js node build/ts/index.js verify \
--poll-id 0 \
--deploy-subsidy false \
--tally-file tally.json
4 changes: 2 additions & 2 deletions cli/tests/e2e/e2e.subsidy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import {
testTallyVotesWasmPath,
testTallyVotesWitnessPath,
} from "../constants";
import { cleanSubsidy, isArm } from "../utils";
import { cleanSubsidy } from "../utils";

describe("e2e with Subsidy tests", function test() {
const useWasm = isArm();
const useWasm = true;
this.timeout(900000);

let maciAddresses: DeployedContracts;
Expand Down
16 changes: 2 additions & 14 deletions cli/tests/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ describe("e2e tests", function test() {
let maciAddresses: DeployedContracts;
let pollAddresses: PollContracts;

const deploySubsidy = false;

// before all tests we deploy the vk registry contract and set the verifying keys
before(async () => {
// we deploy the vk registry contract
Expand All @@ -86,7 +88,6 @@ describe("e2e tests", function test() {
});

const user = new Keypair();
const deploySubsidy = true;

before(async () => {
// deploy the smart contracts
Expand Down Expand Up @@ -155,7 +156,6 @@ describe("e2e tests", function test() {
tallyFileData,
maciAddresses.maciAddress,
pollAddresses.tally,
pollAddresses.subsidy,
);
});
});
Expand All @@ -166,7 +166,6 @@ describe("e2e tests", function test() {
});

const users = [new Keypair(), new Keypair(), new Keypair(), new Keypair()];
const deploySubsidy = true;

before(async () => {
// deploy the smart contracts
Expand Down Expand Up @@ -272,7 +271,6 @@ describe("e2e tests", function test() {
tallyFileData,
maciAddresses.maciAddress,
pollAddresses.tally,
pollAddresses.subsidy,
);
});
});
Expand All @@ -283,7 +281,6 @@ describe("e2e tests", function test() {
});

const users = [new Keypair(), new Keypair(), new Keypair(), new Keypair()];
const deploySubsidy = true;

before(async () => {
// deploy the smart contracts
Expand Down Expand Up @@ -411,7 +408,6 @@ describe("e2e tests", function test() {
tallyFileData,
maciAddresses.maciAddress,
pollAddresses.tally,
pollAddresses.subsidy,
);
});
});
Expand All @@ -432,7 +428,6 @@ describe("e2e tests", function test() {
new Keypair(),
new Keypair(),
];
const deploySubsidy = true;

before(async () => {
// deploy the smart contracts
Expand Down Expand Up @@ -505,7 +500,6 @@ describe("e2e tests", function test() {
tallyFileData,
maciAddresses.maciAddress,
pollAddresses.tally,
pollAddresses.subsidy,
);
});
});
Expand All @@ -516,7 +510,6 @@ describe("e2e tests", function test() {
});

const user = new Keypair();
const deploySubsidy = true;

before(async () => {
// deploy the smart contracts
Expand Down Expand Up @@ -591,7 +584,6 @@ describe("e2e tests", function test() {
tallyFileData,
maciAddresses.maciAddress,
pollAddresses.tally,
pollAddresses.subsidy,
);
});
});
Expand Down Expand Up @@ -620,7 +612,6 @@ describe("e2e tests", function test() {
});

const user = new Keypair();
const deploySubsidy = false;

before(async () => {
// deploy the smart contracts
Expand Down Expand Up @@ -748,7 +739,6 @@ describe("e2e tests", function test() {
];

let secondPollAddresses: PollContracts;
const deploySubsidy = false;

after(() => {
cleanVanilla();
Expand Down Expand Up @@ -1004,7 +994,6 @@ describe("e2e tests", function test() {
const stateOutPath = "./state.json";

const user = new Keypair();
const deploySubsidy = false;

after(() => {
cleanVanilla();
Expand Down Expand Up @@ -1093,7 +1082,6 @@ describe("e2e tests", function test() {
const user = new Keypair();
const tokenAmount = 100;
let stateIndex: number | undefined;
const deploySubsidy = false;

after(() => {
cleanVanilla();
Expand Down
14 changes: 4 additions & 10 deletions contracts/contracts/MACI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ contract MACI is IMACI, Params, Utilities, Ownable {
if (hash2([uint256(1), uint256(1)]) == 0) revert PoseidonHashLibrariesNotLinked();
}

/// @notice Get the depth of the state tree
/// @return The depth of the state tree
/// @inheritdoc IMACI
function stateTreeDepth() external view returns (uint8) {
return STATE_TREE_DEPTH;
}
Expand Down Expand Up @@ -255,22 +254,17 @@ contract MACI is IMACI, Params, Utilities, Ownable {
emit DeployPoll(pollId, pollAddr, _coordinatorPubKey, mp, tally);
}

/// @notice Allow Poll contracts to merge the state subroots
/// @param _numSrQueueOps Number of operations
/// @param _pollId The active Poll ID
/// @inheritdoc IMACI
function mergeStateAqSubRoots(uint256 _numSrQueueOps, uint256 _pollId) public override onlyPoll(_pollId) {
stateAq.mergeSubRoots(_numSrQueueOps);
}

/// @notice Allow Poll contracts to merge the state root
/// @param _pollId The active Poll ID
/// @return root The calculated Merkle root
/// @inheritdoc IMACI
function mergeStateAq(uint256 _pollId) public override onlyPoll(_pollId) returns (uint256 root) {
root = stateAq.merge(STATE_TREE_DEPTH);
}

/// @notice Return the main root of the StateAq contract
/// @return root The Merkle root
/// @inheritdoc IMACI
function getStateAqRoot() public view override returns (uint256 root) {
root = stateAq.getMainRoot(STATE_TREE_DEPTH);
}
Expand Down
10 changes: 7 additions & 3 deletions contracts/contracts/MessageProcessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { SnarkCommon } from "./crypto/SnarkCommon.sol";
import { Hasher } from "./crypto/Hasher.sol";
import { IVerifier } from "./interfaces/IVerifier.sol";
import { IVkRegistry } from "./interfaces/IVkRegistry.sol";
import { IMessageProcessor } from "./interfaces/IMessageProcessor.sol";
import { CommonUtilities } from "./utilities/CommonUtilities.sol";

/// @title MessageProcessor
/// @dev MessageProcessor is used to process messages published by signup users.
/// It will process message by batch due to large size of messages.
/// After it finishes processing, the sbCommitment will be used for Tally and Subsidy contracts.
contract MessageProcessor is Ownable, SnarkCommon, Hasher, CommonUtilities {
contract MessageProcessor is Ownable, SnarkCommon, Hasher, CommonUtilities, IMessageProcessor {
/// @notice custom errors
error NoMoreMessages();
error StateAqNotMerged();
Expand All @@ -27,15 +28,18 @@ contract MessageProcessor is Ownable, SnarkCommon, Hasher, CommonUtilities {
error CurrentMessageBatchIndexTooLarge();
error BatchEndIndexTooLarge();

/// @notice Whether there are unprocessed messages left
/// @inheritdoc IMessageProcessor
bool public processingComplete;

/// @notice The number of batches processed
uint256 public numBatchesProcessed;

/// @notice The current message batch index. When the coordinator runs
/// processMessages(), this action relates to messages
/// currentMessageBatchIndex to currentMessageBatchIndex + messageBatchSize.
uint256 public currentMessageBatchIndex;
/// @notice The commitment to the state and ballot roots

/// @inheritdoc IMessageProcessor
uint256 public sbCommitment;

IPoll public poll;
Expand Down
12 changes: 4 additions & 8 deletions contracts/contracts/MessageProcessorFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@ pragma solidity ^0.8.10;
import { Params } from "./utilities/Params.sol";
import { DomainObjs } from "./utilities/DomainObjs.sol";
import { MessageProcessor } from "./MessageProcessor.sol";
import { IMessageProcessorFactory } from "./interfaces/IMPFactory.sol";

/// @title MessageProcessorFactory
/// @notice A factory contract which deploys MessageProcessor contracts.
contract MessageProcessorFactory is Params, DomainObjs {
/// @notice Deploy a new MessageProcessor contract and return the address.
/// @param _verifier Verifier contract
/// @param _vkRegistry VkRegistry contract
/// @param _poll Poll contract
/// @param _owner Owner of the MessageProcessor contract
/// @return messageProcessorAddr The deployed MessageProcessor contract
contract MessageProcessorFactory is Params, DomainObjs, IMessageProcessorFactory {
/// @inheritdoc IMessageProcessorFactory
function deploy(
address _verifier,
address _vkRegistry,
address _poll,
address _owner
) public returns (address messageProcessorAddr) {
/// @notice deploy MessageProcessor for this Poll
// deploy MessageProcessor for this Poll
MessageProcessor messageProcessor = new MessageProcessor(_verifier, _vkRegistry, _poll);
messageProcessor.transferOwnership(_owner);
messageProcessorAddr = address(messageProcessor);
Expand Down
Loading

0 comments on commit 3531840

Please sign in to comment.