Skip to content

Commit

Permalink
fix(circuits): fix coordinator censoring by passing currentVoteWeight…
Browse files Browse the repository at this point in the history
… = 0

Prevent coordinator censoring a valid second message by passing the currentVoteWeight equal to a
number which would result in not enough voice credits in the circuit
  • Loading branch information
ctrlc03 committed Feb 19, 2024
1 parent 510e6ee commit 22e091d
Show file tree
Hide file tree
Showing 6 changed files with 447 additions and 16 deletions.
1 change: 1 addition & 0 deletions circuits/circom/messageValidator.circom
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ template MessageValidator() {
validStateLeafIndex.in[0] <== stateTreeIndex;
validStateLeafIndex.in[1] <== numSignUps;

// @todo check if we need this if we do the check inside processOne
// b) Whether the max vote option tree index is correct
signal input voteOptionIndex;
signal input maxVoteOptions;
Expand Down
10 changes: 9 additions & 1 deletion circuits/circom/processMessages.circom
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,16 @@ template ProcessOne(stateTreeDepth, voteOptionTreeDepth) {
isMessageValid.in[0] <== bothValid;
isMessageValid.in[1] <== transformer.isValid + enoughVoiceCredits.out;

// check that the vote option index is < maxVoteOptions (0-indexed)
component validVoteOptionIndex = SafeLessThan(N_BITS);
validVoteOptionIndex.in[0] <== cmdVoteOptionIndex;
validVoteOptionIndex.in[1] <== maxVoteOptions;

// @note pick the correct vote option index based on whether the index is < max vote options
// @todo can probably add one output to messageValidator and take from there
// or maybe we can remove altogther from messageValidator so we don't double check this
component cmdVoteOptionIndexMux = Mux1();
cmdVoteOptionIndexMux.s <== isMessageValid.out;
cmdVoteOptionIndexMux.s <== validVoteOptionIndex.out;
cmdVoteOptionIndexMux.c[0] <== 0;
cmdVoteOptionIndexMux.c[1] <== cmdVoteOptionIndex;

Expand Down
10 changes: 9 additions & 1 deletion circuits/circom/processMessagesNonQv.circom
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,16 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
isMessageValid.in[0] <== bothValid;
isMessageValid.in[1] <== transformer.isValid + enoughVoiceCredits.out;

// check that the vote option index is < maxVoteOptions (0-indexed)
component validVoteOptionIndex = SafeLessThan(N_BITS);
validVoteOptionIndex.in[0] <== cmdVoteOptionIndex;
validVoteOptionIndex.in[1] <== maxVoteOptions;

// @note pick the correct vote option index based on whether the index is < max vote options
// @todo can probably add one output to messageValidator and take from there
// or maybe we can remove altogther from messageValidator so we don't double check this
component cmdVoteOptionIndexMux = Mux1();
cmdVoteOptionIndexMux.s <== isMessageValid.out;
cmdVoteOptionIndexMux.s <== validVoteOptionIndex.out;
cmdVoteOptionIndexMux.c[0] <== 0;
cmdVoteOptionIndexMux.c[1] <== cmdVoteOptionIndex;

Expand Down
2 changes: 1 addition & 1 deletion circuits/circom/stateLeafAndBallotTransformerNonQv.circom
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ template StateLeafAndBallotTransformerNonQv() {
messageValidator.voteWeight <== cmdNewVoteWeight;

// if the message is valid then we swap out the public key
// we have to do this in two Mux one for pucKey[0]
// we have to do this in two Mux one for pubKey[0]
// and one for pubKey[1]
component newSlPubKey0Mux = Mux1();
newSlPubKey0Mux.s <== messageValidator.isValid;
Expand Down

0 comments on commit 22e091d

Please sign in to comment.