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: anonymous poll joining milestone 1 #1625

Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
55879f1
feat(poll): add chain hash features
radojevicMihailo Jun 6, 2024
c7c8f98
fix(ipoll): add missing parameter
radojevicMihailo Jun 6, 2024
b485130
fix(poll-tests): add missing parameter maxMessagebatchSize
aleksprospeh2 Jun 6, 2024
fbdc037
feat(poll.ts): add chain hash updating
aleksprospeh2 Jun 6, 2024
2261883
test(poll tests): add test for checking chain hash computation
radojevicMihailo Jun 6, 2024
f92e78c
feat(poll.ts): add batch hashes array computation
aleksprospeh2 Jun 6, 2024
0605f91
feat(poll.sol): pad zeroes to the maximum size of batch
radojevicMihailo Jun 7, 2024
b01c648
feat(messageprocessor): update process messages to use chain hash
radojevicMihailo Jun 14, 2024
e688b08
refactor(vkregistry): refactor function call
radojevicMihailo Jun 14, 2024
137f8f9
feat(processmessages.circom): add chainHash feature in circuits and t…
radojevicMihailo Jun 20, 2024
94b7e59
test(processmessages): rearrange test for key-change
radojevicMihailo Jun 21, 2024
97498b7
refactor(mergemessages): refactor functions calls which include merge…
radojevicMihailo Jun 25, 2024
2ec0765
refactor(mergemessages): add some more changes about functions call w…
radojevicMihailo Jun 25, 2024
37aaad2
test(all tests): fixing tests after refactoring code
radojevicMihailo Jun 25, 2024
d7c273e
refactor(accqueue): remove all calls for accqueue
radojevicMihailo Jun 26, 2024
29dc495
fix(currentmessagebatchindex): fix message batch indexing
radojevicMihailo Jun 27, 2024
a574527
refactor(circuit tests): refactor code for circuit testing
radojevicMihailo Jun 27, 2024
58f083c
test(ceremonyparams.test): correct constants for CeremonyParams test
radojevicMihailo Jun 28, 2024
ed6b2db
chore(codebase): sync with main repo
radojevicMihailo Jul 1, 2024
5486594
perf(processmessages.circom + contracts): optimize last batch padding…
aleksprospeh2 Jul 2, 2024
eb6862a
docs(padlastbatch method): update doc comment
aleksprospeh2 Jul 2, 2024
db7a257
docs(poll.ts): remove stale comments
aleksprospeh2 Jul 2, 2024
79d761b
docs(test comments): fix typos
aleksprospeh2 Jul 2, 2024
f7cd951
ci(treedepths mock): modify interface for mocked function
aleksprospeh2 Jul 2, 2024
0615975
fix(ceremony params test): fix circuit inputs
aleksprospeh2 Jul 2, 2024
bb80ea9
test(messagevalidator): fix function calls for messagevalidator circu…
radojevicMihailo Jul 2, 2024
6e74a23
chore(comments): fix unusefull comments
radojevicMihailo Jul 2, 2024
50596cf
Merge branch 'feat/anon-poll-joining' of github.com:0x3327/maci into …
radojevicMihailo Jul 2, 2024
3164ca7
refactor(poll.sol): replace external contracts with maci only
aleksprospeh2 Jul 2, 2024
e7dddb6
perf(messageprocessor.sol): hardcode initialization for batchHashes a…
aleksprospeh2 Jul 2, 2024
4925310
Merge branch 'feat/anon-poll-joining' of github.com:0x3327/maci into …
aleksprospeh2 Jul 2, 2024
5082deb
docs(comments): fix some more comments
radojevicMihailo Jul 2, 2024
286c8c0
docs(merge): merge codebase
radojevicMihailo Jul 2, 2024
fb2a327
test(test for pr checks): correct some of tests for PR checks
radojevicMihailo Jul 3, 2024
652c0d1
ci: 🎡 renamed old ProcessMessages_10-2-1-2_test
djanluka Jul 3, 2024
a8019e5
ci: 🎡 correct rapidsnark/build/prover path
djanluka Jul 3, 2024
8921637
style(reviews): solve some reviews for merging
radojevicMihailo Jul 3, 2024
eeb21b8
refactor(messageaqq): remove more message merging and message aqq
radojevicMihailo Jul 3, 2024
25b567a
style(messageaqq): remove more message merging and message aqq
radojevicMihailo Jul 3, 2024
29980d3
Merge branch 'feat/anon-poll-joining' of github.com:0x3327/maci into …
radojevicMihailo Jul 3, 2024
adb1843
refactor(messageaqq): remove message aqq from subgraph
radojevicMihailo Jul 3, 2024
74c4ab0
test(coordinator): hide NOT_MERGED_MESSAGE_TREE error
djanluka Jul 3, 2024
a723725
test(coordinator): fix test about message merging
radojevicMihailo Jul 4, 2024
92c478a
test(proveonchain): change chainHash calculation
radojevicMihailo Jul 4, 2024
81938c6
test(proveonchain): fix chainHashes declaration
radojevicMihailo Jul 4, 2024
273c06c
test(proveonchain): fix chainHash calculation
radojevicMihailo Jul 4, 2024
2dde17f
test(proveonchain): fix chainHashes calculations
radojevicMihailo Jul 4, 2024
256e8c7
test(proveonchain): fix chainHashes calculation
radojevicMihailo Jul 4, 2024
9120425
test(proveonchain): fix loop limit
djanluka Jul 4, 2024
6bef8a9
style(review comments): resolve some of review comments
radojevicMihailo Jul 5, 2024
bb01657
style(review comments): resolve some of review comments
radojevicMihailo Jul 8, 2024
e29f3fb
test(lint:ts): fix e2e test because of lint:ts check
radojevicMihailo Jul 8, 2024
30cf4eb
docs(wrong changes): fix wrong changes about documentation that is no…
radojevicMihailo Jul 8, 2024
984aaec
refactor(batchsizes): change batchSizes struct with messageBatchSize …
radojevicMihailo Jul 9, 2024
e70f9ae
refactor(contracts): rollback to provide external contract references
aleksprospeh2 Jul 9, 2024
c8cce92
docs(messageprocessor.sol): fix typo
aleksprospeh2 Jul 9, 2024
8617781
refactor(messagebatchsize): chenge messageBatchSize location from Par…
radojevicMihailo Jul 10, 2024
5c9c59d
refactor(merge): resolve merge conflict
radojevicMihailo Jul 10, 2024
7185e38
refactor(maxmessages): remove maxMessages from maxValues
radojevicMihailo Jul 10, 2024
f68b9ef
refactor(sltimestemp): remove slTimestamp from circuits
radojevicMihailo Jul 10, 2024
e95efb3
refactor(review comments): resolve more review comments
radojevicMihailo Jul 10, 2024
2d92f56
fix(subgraph): fix bug about maxVoteOptions dunction call
radojevicMihailo Jul 10, 2024
ebdc278
fix(sltimestamp): fix test for removing slTimestap signal
radojevicMihailo Jul 10, 2024
b6179b0
refactor(promise.all): refactor promise.all for only one async call
radojevicMihailo Jul 11, 2024
c34b1ff
fix(subgraph): try to fix subgraph build
radojevicMihailo Jul 11, 2024
d4d10eb
revert(.nx folder): remove .nx folder from cli folder
radojevicMihailo Jul 11, 2024
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: 1 addition & 1 deletion .github/workflows/coordinator-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
COORDINATOR_PUBLIC_KEY_PATH: "./pub.key"
COORDINATOR_PRIVATE_KEY_PATH: "./priv.key"
COORDINATOR_TALLY_ZKEY_NAME: "TallyVotes_10-1-2_test"
COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME: "ProcessMessages_10-2-1-2_test"
COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME: "ProcessMessages_10-20-2_test"
COORDINATOR_ZKEY_PATH: "./zkeys/"
COORDINATOR_RAPIDSNARK_EXE: "~/rapidsnark/build/prover"

Expand Down
8 changes: 4 additions & 4 deletions circuits/circom/circuits.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"ProcessMessages_10-2-1-2_test": {
"ProcessMessages_10-20-2_test": {
"file": "./core/qv/processMessages",
"template": "ProcessMessages",
"params": [10, 2, 1, 2],
"params": [10, 20, 2],
"pubs": ["inputHash"]
},
"ProcessMessagesNonQv_10-2-1-2_test": {
"ProcessMessagesNonQv_10-20-2_test": {
"file": "./core/non-qv/processMessages",
"template": "ProcessMessagesNonQv",
"params": [10, 2, 1, 2],
"params": [10, 20, 2],
"pubs": ["inputHash"]
},
"TallyVotes_10-1-2_test": {
Expand Down
88 changes: 25 additions & 63 deletions circuits/circom/core/non-qv/processMessages.circom
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,22 @@ include "../../trees/incrementalQuinaryTree.circom";

/**
* Proves the correctness of processing a batch of MACI messages.
* The msgBatchDepth parameter is known as msgSubtreeDepth and indicates the depth
* of the shortest tree that can fit all the messages in a batch.
* This template does not support Quadratic Voting (QV).
*/
template ProcessMessagesNonQv(
stateTreeDepth,
msgTreeDepth,
msgBatchDepth,
batchSize,
voteOptionTreeDepth
) {
// Must ensure that the trees have a valid structure.
assert(stateTreeDepth > 0);
assert(msgBatchDepth > 0);
assert(batchSize > 0);
assert(voteOptionTreeDepth > 0);
assert(msgTreeDepth >= msgBatchDepth);

// Default for IQT (quinary trees).
var MESSAGE_TREE_ARITY = 5;
var VOTE_OPTION_TREE_ARITY = 5;
// Default for Binary trees.
var STATE_TREE_ARITY = 2;
var batchSize = MESSAGE_TREE_ARITY ** msgBatchDepth;
var MSG_LENGTH = 10;
var PACKED_CMD_LENGTH = 4;
var STATE_LEAF_LENGTH = 4;
Expand All @@ -59,14 +54,12 @@ include "../../trees/incrementalQuinaryTree.circom";
signal numSignUps;
// Number of options for this poll.
signal maxVoteOptions;
// Time when the poll ends.
signal input pollEndTimestamp;
// The existing message tree root.
signal input msgRoot;
// Value of chainHash at beginning of batch
signal input inputBatchHash;
// Value of chainHash at end of batch
signal input outputBatchHash;
// The messages.
signal input msgs[batchSize][MSG_LENGTH];
// Sibling messages.
signal input msgSubrootPathElements[msgTreeDepth - msgBatchDepth][MESSAGE_TREE_ARITY - 1];
// The coordinator's private key.
signal input coordPrivKey;
// The cooordinator's public key (derived from the contract).
Expand Down Expand Up @@ -104,16 +97,16 @@ include "../../trees/incrementalQuinaryTree.circom";
signal input currentBallotsPathElements[batchSize][stateTreeDepth][STATE_TREE_ARITY - 1];
// Intermediate vote weights.
signal input currentVoteWeights[batchSize];
signal input currentVoteWeightsPathElements[batchSize][voteOptionTreeDepth][MESSAGE_TREE_ARITY - 1];
signal input currentVoteWeightsPathElements[batchSize][voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];

// nb. The messages are processed in REVERSE order.
// Therefore, the index of the first message to process does not match the index of the
// first message (e.g., [msg1, msg2, msg3] => first message to process has index 3).

// The index of the first message leaf in the batch, inclusive.
// The index of the first message in the batch, inclusive.
signal batchStartIndex;

// The index of the last message leaf in the batch to process, exclusive.
// The index of the last message in the batch to process, exclusive.
// This value may be less than batchStartIndex + batchSize if this batch is
// the last batch and the total number of messages is not a multiple of the batch size.
signal batchEndIndex;
Expand All @@ -135,16 +128,15 @@ include "../../trees/incrementalQuinaryTree.circom";
var (
computedMaxVoteOptions,
computedNumSignUps,
computedBatchStartIndex,
computedBatchStartIndex,
computedBatchEndIndex,
computedHash
) = ProcessMessagesInputHasher()(
packedVals,
coordPubKey,
msgRoot,
outputBatchHash,
currentSbCommitment,
newSbCommitment,
pollEndTimestamp,
actualStateTreeDepth
);

Expand All @@ -159,7 +151,7 @@ include "../../trees/incrementalQuinaryTree.circom";
// -----------------------------------------------------------------------
// 0. Ensure that the maximum vote options signal is valid and if
// the maximum users signal is valid.
var maxVoValid = LessEqThan(32)([maxVoteOptions, MESSAGE_TREE_ARITY ** voteOptionTreeDepth]);
var maxVoValid = LessEqThan(32)([maxVoteOptions, VOTE_OPTION_TREE_ARITY ** voteOptionTreeDepth]);
maxVoValid === 1;

// Check numSignUps <= the max number of users (i.e., number of state leaves
Expand All @@ -169,50 +161,23 @@ include "../../trees/incrementalQuinaryTree.circom";

// Hash each Message to check their existence in the Message tree.
ctrlc03 marked this conversation as resolved.
Show resolved Hide resolved
var computedMessageHashers[batchSize];
var computedHashes[batchSize];
var chainHash[batchSize + 1];
chainHash[0] = inputBatchHash;
for (var i = 0; i < batchSize; i++) {
ctrlc03 marked this conversation as resolved.
Show resolved Hide resolved
computedMessageHashers[i] = MessageHasher()(msgs[i], encPubKeys[i]);
var batchStartIndexValid = SafeLessThan(32)([batchStartIndex + i, batchEndIndex]);
computedHashes[i] = PoseidonHasher(2)([chainHash[i], computedMessageHashers[i]]);

chainHash[i + 1] = Mux1()([chainHash[i], computedHashes[i]], batchStartIndexValid);
}

// If batchEndIndex - batchStartIndex < batchSize, the remaining
ctrlc03 marked this conversation as resolved.
Show resolved Hide resolved
// message hashes should be the zero value.
// e.g. [m, z, z, z, z] if there is only 1 real message in the batch
// This makes possible to have a batch of messages which is only partially full.
var computedLeaves[batchSize];
var computedPathElements[msgTreeDepth - msgBatchDepth][MESSAGE_TREE_ARITY - 1];
var computedPathIndex[msgTreeDepth - msgBatchDepth];

for (var i = 0; i < batchSize; i++) {
var batchStartIndexValid = SafeLessThan(32)([batchStartIndex + i, batchEndIndex]);
computedLeaves[i] = Mux1()([msgTreeZeroValue, computedMessageHashers[i]], batchStartIndexValid);
}

for (var i = 0; i < msgTreeDepth - msgBatchDepth; i++) {
for (var j = 0; j < MESSAGE_TREE_ARITY - 1; j++) {
computedPathElements[i][j] = msgSubrootPathElements[i][j];
}
}

// Computing the path_index values. Since msgBatchLeavesExists tests
// the existence of a subroot, the length of the proof correspond to the last
// n elements of a proof from the root to a leaf, where n = msgTreeDepth - msgBatchDepth.
// e.g. if batchStartIndex = 25, msgTreeDepth = 4, msgBatchDepth = 2, then path_index = [1, 0].
var computedMsgBatchPathIndices[msgTreeDepth] = QuinGeneratePathIndices(msgTreeDepth)(batchStartIndex);

for (var i = msgBatchDepth; i < msgTreeDepth; i++) {
computedPathIndex[i - msgBatchDepth] = computedMsgBatchPathIndices[i];
}

// Check whether each message exists in the Message tree.
// Otherwise, throws (needs constraint to prevent such a proof).
// To save constraints, compute the subroot of the messages and check
// whether the subroot is a member of the message tree. This means that
// batchSize must be the message tree arity raised to some power (e.g. 5 ^ n).
QuinBatchLeavesExists(msgTreeDepth, msgBatchDepth)(
msgRoot,
computedLeaves,
computedPathIndex,
computedPathElements
);
chainHash[batchSize] === outputBatchHash;

// Decrypt each Message to a Command.
// MessageToCommand derives the ECDH shared key from the coordinator's
Expand Down Expand Up @@ -274,7 +239,7 @@ include "../../trees/incrementalQuinaryTree.circom";
// Process as vote type message.
var currentStateLeavesPathElement[stateTreeDepth][STATE_TREE_ARITY - 1];
var currentBallotPathElement[stateTreeDepth][STATE_TREE_ARITY - 1];
var currentVoteWeightsPathElement[voteOptionTreeDepth][MESSAGE_TREE_ARITY - 1];
var currentVoteWeightsPathElement[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];

for (var j = 0; j < stateTreeDepth; j++) {
for (var k = 0; k < STATE_TREE_ARITY - 1; k++) {
Expand All @@ -284,15 +249,14 @@ include "../../trees/incrementalQuinaryTree.circom";
}

for (var j = 0; j < voteOptionTreeDepth; j++) {
for (var k = 0; k < MESSAGE_TREE_ARITY - 1; k++) {
for (var k = 0; k < VOTE_OPTION_TREE_ARITY - 1; k++) {
currentVoteWeightsPathElement[j][k] = currentVoteWeightsPathElements[i][j][k];
}
}

(computedNewVoteStateRoot[i], computedNewVoteBallotRoot[i]) = ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth)(
numSignUps,
maxVoteOptions,
pollEndTimestamp,
stateRoots[i + 1],
ballotRoots[i + 1],
actualStateTreeDepth,
Expand Down Expand Up @@ -336,7 +300,7 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
var BALLOT_LENGTH = 2;
var MSG_LENGTH = 10;
var PACKED_CMD_LENGTH = 4;
var MESSAGE_TREE_ARITY = 5;
var VOTE_OPTION_TREE_ARITY = 5;
var STATE_TREE_ARITY = 2;
var BALLOT_NONCE_IDX = 0;
// Ballot vote option (VO) root index.
Expand All @@ -355,7 +319,6 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
// Inputs representing the message and the current state.
signal input numSignUps;
signal input maxVoteOptions;
signal input pollEndTimestamp;

// The current value of the state tree root.
signal input currentStateRoot;
Expand All @@ -375,7 +338,7 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {

// The current vote weight and related path elements.
signal input currentVoteWeight;
signal input currentVoteWeightsPathElements[voteOptionTreeDepth][MESSAGE_TREE_ARITY - 1];
signal input currentVoteWeightsPathElements[voteOptionTreeDepth][VOTE_OPTION_TREE_ARITY - 1];

// Inputs related to the command being processed.
signal input cmdStateIndex;
Expand Down Expand Up @@ -409,7 +372,6 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
[stateLeaf[STATE_LEAF_PUB_X_IDX], stateLeaf[STATE_LEAF_PUB_Y_IDX]],
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX],
stateLeaf[STATE_LEAF_TIMESTAMP_IDX],
pollEndTimestamp,
ballot[BALLOT_NONCE_IDX],
currentVoteWeight,
cmdStateIndex,
Expand Down
Loading
Loading