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 authored and 0xmad committed Feb 16, 2024
1 parent 1685035 commit 9a17cd0
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 14 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
Loading

0 comments on commit 9a17cd0

Please sign in to comment.