Skip to content

Commit

Permalink
chore: optimize message processing circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmad committed Dec 3, 2024
1 parent 108750f commit d5b170b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
14 changes: 1 addition & 13 deletions packages/circuits/circom/core/non-qv/processMessages.circom
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,6 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {

// 5. Verify that currentVoteWeight exists in the ballot's vote option root
// at cmdVoteOptionIndex.
var voiceCreditAmountValid = SafeGreaterEqThan(252)([
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] + currentVoteWeight,
cmdNewVoteWeight
]);

var cmdVoteOptionIndexMux = Mux1()([0, cmdVoteOptionIndex], computedIsVoteOptionIndexValid);
var computedCurrentVoteWeightPathIndices[voteOptionTreeDepth] = QuinGeneratePathIndices(voteOptionTreeDepth)(cmdVoteOptionIndexMux);

Expand All @@ -396,17 +391,10 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {
computedCurrentVoteWeightQip === ballot[BALLOT_VO_ROOT_IDX];

var voteWeightMux = Mux1()([currentVoteWeight, cmdNewVoteWeight], computedIsValid);
var newSlVoiceCreditBalanceMux = Mux1()(
[
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX],
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] + currentVoteWeight - cmdNewVoteWeight
],
voiceCreditAmountValid
);
var voiceCreditBalanceMux = Mux1()(
[
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX],
newSlVoiceCreditBalanceMux
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] + currentVoteWeight - cmdNewVoteWeight
],
computedIsValid
);
Expand Down
14 changes: 1 addition & 13 deletions packages/circuits/circom/core/qv/processMessages.circom
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,6 @@ template ProcessOne(stateTreeDepth, voteOptionTreeDepth) {
currentVoteWeightSquare <== currentVoteWeight * currentVoteWeight;
cmdNewVoteWeightSquare <== cmdNewVoteWeight * cmdNewVoteWeight;

var voiceCreditAmountValid = SafeGreaterEqThan(252)([
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] + currentVoteWeightSquare,
cmdNewVoteWeightSquare
]);

var cmdVoteOptionIndexMux = Mux1()([0, cmdVoteOptionIndex], computedIsVoteOptionIndexValid);
var computedCurrentVoteWeightPathIndices[voteOptionTreeDepth] = QuinGeneratePathIndices(voteOptionTreeDepth)(cmdVoteOptionIndexMux);

Expand All @@ -399,17 +394,10 @@ template ProcessOne(stateTreeDepth, voteOptionTreeDepth) {
computedCurrentVoteWeightQip === ballot[BALLOT_VO_ROOT_IDX];

var voteWeightMux = Mux1()([currentVoteWeight, cmdNewVoteWeight], computedIsValid);
var newSlVoiceCreditBalanceMux = Mux1()(
[
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX],
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] + currentVoteWeightSquare - cmdNewVoteWeightSquare
],
voiceCreditAmountValid
);
var voiceCreditBalanceMux = Mux1()(
[
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX],
newSlVoiceCreditBalanceMux
stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] + currentVoteWeightSquare - cmdNewVoteWeightSquare
],
computedIsValid
);
Expand Down

0 comments on commit d5b170b

Please sign in to comment.