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(circuits): remove circomlib fork in favour of latest and zk-kit #1010

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 12 additions & 3 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@ jobs:
wget -qO /home/runner/work/maci/.local/bin/circom https://github.com/iden3/circom/releases/download/v2.1.6/circom-linux-amd64
chmod +x /home/runner/work/maci/.local/bin/circom

- name: Generate zkeys
- name: Create zkeys folder
run: |
cd cli
mkdir -p zkeys

- name: Compile Circuits And Generate zkeys
run: |
cd circuits
export PATH=$PATH:/home/runner/work/maci/.local/bin
pnpm build-test-circuits-c
mv ./build/test/* ../cli/zkeys/
cd ../cli
wget -qO zkeys/powersOfTau28_hez_final_20.ptau https://maci-devops-zkeys.s3.ap-northeast-2.amazonaws.com/powersOfTau28_hez_final_20.ptau
pnpm exec zkey-manager compile -c ./zkeys.config.yml
pnpm exec zkey-manager genZkeys -c ./zkeys.config.yml
pnpm snarkjs groth16 setup ./zkeys/ProcessMessages_10-2-1-2_test.r1cs ./zkeys/powersOfTau28_hez_final_20.ptau ./zkeys/ProcessMessages_10-2-1-2_test.0.zkey
pnpm snarkjs groth16 setup ./zkeys/TallyVotes_10-1-2_test.r1cs ./zkeys/powersOfTau28_hez_final_20.ptau ./zkeys/TallyVotes_10-1-2_test.0.zkey
pnpm snarkjs groth16 setup ./zkeys/SubsidyPerBatch_10-1-2_test.r1cs ./zkeys/powersOfTau28_hez_final_20.ptau ./zkeys/SubsidyPerBatch_10-1-2_test.0.zkey

- name: ${{ matrix.command }}
run: pnpm run ${{ matrix.command }}
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/reusable-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,24 @@ jobs:
wget -qO /home/runner/work/maci/.local/bin/circom https://github.com/iden3/circom/releases/download/v2.1.6/circom-linux-amd64
chmod +x /home/runner/work/maci/.local/bin/circom

- name: Generate zkeys
- name: Create zkeys folder
if: ${{ env.CHANGED == 'true' }}
run: |
cd cli
mkdir -p zkeys

- name: Compile Circuits And Generate zkeys
if: ${{ env.CHANGED == 'true' }}
run: |
cd circuits
export PATH=$PATH:/home/runner/work/maci/.local/bin
pnpm build-test-circuits-c
mv ./build/test/* ../cli/zkeys/
cd ../cli
wget -qO zkeys/powersOfTau28_hez_final_20.ptau https://maci-devops-zkeys.s3.ap-northeast-2.amazonaws.com/powersOfTau28_hez_final_20.ptau
pnpm exec zkey-manager compile -c ./zkeys.config.yml
pnpm exec zkey-manager genZkeys -c ./zkeys.config.yml
pnpm snarkjs groth16 setup ./zkeys/ProcessMessages_10-2-1-2_test.r1cs ./zkeys/powersOfTau28_hez_final_20.ptau ./zkeys/ProcessMessages_10-2-1-2_test.0.zkey
pnpm snarkjs groth16 setup ./zkeys/TallyVotes_10-1-2_test.r1cs ./zkeys/powersOfTau28_hez_final_20.ptau ./zkeys/TallyVotes_10-1-2_test.0.zkey
pnpm snarkjs groth16 setup ./zkeys/SubsidyPerBatch_10-1-2_test.r1cs ./zkeys/powersOfTau28_hez_final_20.ptau ./zkeys/SubsidyPerBatch_10-1-2_test.0.zkey

- name: Download zkeys
if: ${{ env.CHANGED == 'false' }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ cli/tallyinput.json
cli/contractAddresses.json
cli/contractAddresses.old.json

circuits/circom/test

# mdBook rendered files
publish

Expand Down
32 changes: 32 additions & 0 deletions circuits/circom/circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"processMessages": {
"file": "processMessages",
"template": "ProcessMessages",
"params": [6, 8, 2, 3],
"pubs": ["inputHash"]
},
"ProcessMessages_10-2-1-2_test": {
"file": "processMessages",
"template": "ProcessMessages",
"params": [10, 2, 1, 2],
"pubs": ["inputHash"]
},
"tallyVotes": {
"file": "tallyVotes",
"template": "TallyVotes",
"params": [6, 2, 3],
"pubs": ["inputHash"]
},
"TallyVotes_10-1-2_test": {
"file": "tallyVotes",
"template": "TallyVotes",
"params": [10, 1, 2],
"pubs": ["inputHash"]
},
"SubsidyPerBatch_10-1-2_test": {
"file": "subsidy",
"template": "SubsidyPerBatch",
"params": [10, 1, 2],
"pubs": ["inputHash"]
}
}
6 changes: 4 additions & 2 deletions circuits/circom/ecdh.circom
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pragma circom 2.0.0;
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/escalarmulany.circom";

// circomlib imports
include "./bitify.circom";
ctrlc03 marked this conversation as resolved.
Show resolved Hide resolved
include "./escalarmulany.circom";

template Ecdh() {
// Note: the private key needs to be hashed and pruned first
Expand Down
8 changes: 5 additions & 3 deletions circuits/circom/float.circom
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pragma circom 2.0.0;
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/comparators.circom";
include "../node_modules/circomlib/circuits/mux1.circom";

// circomlib imports
include "./bitify.circom";
include "./comparators.circom";
include "./mux1.circom";

template msb(n) {
// require in < 2**n
Expand Down
2 changes: 2 additions & 0 deletions circuits/circom/hasherPoseidon.circom
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pragma circom 2.0.0;

// local imports
include "./poseidon/poseidonHashT3.circom";
include "./poseidon/poseidonHashT4.circom";
include "./poseidon/poseidonHashT5.circom";
Expand Down
6 changes: 4 additions & 2 deletions circuits/circom/hasherSha256.circom
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pragma circom 2.0.0;
include "../node_modules/circomlib/circuits/sha256/sha256.circom";
include "../node_modules/circomlib/circuits/bitify.circom";

// circomlib imports
include "./sha256/sha256.circom";
include "./bitify.circom";

template Sha256HashLeftRight() {
signal input left;
Expand Down
2 changes: 2 additions & 0 deletions circuits/circom/messageHasher.circom
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pragma circom 2.0.0;

// local import
include "./hasherPoseidon.circom";

// hash a MACI message together with the public key
Expand Down
9 changes: 7 additions & 2 deletions circuits/circom/messageToCommand.circom
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
pragma circom 2.0.0;

// circomlib import
include "./bitify.circom";
// @zk-kit import
include "./poseidon-cipher.circom";

// local imports
include "./ecdh.circom";
include "./unpackElement.circom";
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/poseidon.circom";

// template that converts a MACI message
// to a command (decrypts it)
Expand Down
2 changes: 2 additions & 0 deletions circuits/circom/messageValidator.circom
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pragma circom 2.0.0;

// local imports
include "./verifySignature.circom";
include "./utils.circom";

Expand Down
16 changes: 16 additions & 0 deletions circuits/circom/poseidon/poseidon.circom
ctrlc03 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma circom 2.0.0;

// https://github.com/weijiekoh/circomlib/blob/feat/poseidon-encryption/circuits/poseidon.circom
include "./poseidon-cipher.circom";

template Poseidon_OLD(nInputs) {
0xmad marked this conversation as resolved.
Show resolved Hide resolved
signal input inputs[nInputs];
signal output out;

component strategy = PoseidonPerm(nInputs + 1);
strategy.inputs[0] <== 0;
for (var i = 0; i < nInputs; i++) {
strategy.inputs[i + 1] <== inputs[i];
}
out <== strategy.out[0];
}
5 changes: 3 additions & 2 deletions circuits/circom/poseidon/poseidonHashT3.circom
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
pragma circom 2.0.0;
include "../../node_modules/circomlib/circuits/poseidon.circom";

include "./poseidon.circom";

template PoseidonHashT3() {
var nInputs = 2;
signal input inputs[nInputs];
signal output out;

component hasher = Poseidon(nInputs);
component hasher = Poseidon_OLD(nInputs);
for (var i = 0; i < nInputs; i ++) {
hasher.inputs[i] <== inputs[i];
}
Expand Down
5 changes: 3 additions & 2 deletions circuits/circom/poseidon/poseidonHashT4.circom
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
pragma circom 2.0.0;
include "../../node_modules/circomlib/circuits/poseidon.circom";

include "./poseidon.circom";

template PoseidonHashT4() {
var nInputs = 3;
signal input inputs[nInputs];
signal output out;

component hasher = Poseidon(nInputs);
component hasher = Poseidon_OLD(nInputs);
for (var i = 0; i < nInputs; i ++) {
hasher.inputs[i] <== inputs[i];
}
Expand Down
5 changes: 3 additions & 2 deletions circuits/circom/poseidon/poseidonHashT5.circom
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
pragma circom 2.0.0;
include "../../node_modules/circomlib/circuits/poseidon.circom";

include "./poseidon.circom";

template PoseidonHashT5() {
var nInputs = 4;
signal input inputs[nInputs];
signal output out;

component hasher = Poseidon(nInputs);
component hasher = Poseidon_OLD(nInputs);
for (var i = 0; i < nInputs; i ++) {
hasher.inputs[i] <== inputs[i];
}
Expand Down
5 changes: 3 additions & 2 deletions circuits/circom/poseidon/poseidonHashT6.circom
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
pragma circom 2.0.0;
include "../../node_modules/circomlib/circuits/poseidon.circom";

include "./poseidon.circom";

template PoseidonHashT6() {
var nInputs = 5;
signal input inputs[nInputs];
signal output out;

component hasher = Poseidon(nInputs);
component hasher = Poseidon_OLD(nInputs);
for (var i = 0; i < nInputs; i ++) {
hasher.inputs[i] <== inputs[i];
}
Expand Down
6 changes: 4 additions & 2 deletions circuits/circom/privToPubKey.circom
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pragma circom 2.0.0;
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/escalarmulfix.circom";

// circomlib imports
include "./bitify.circom";
include "./escalarmulfix.circom";

// convert a private key to a public key
// @note the basepoint is the base point of the baby jubjub curve
Expand Down
6 changes: 5 additions & 1 deletion circuits/circom/processMessages.circom
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
pragma circom 2.0.0;

// circomlib import
include "./mux1.circom";

// local imports
include "./hasherSha256.circom";
include "./messageHasher.circom";
include "./messageToCommand.circom";
include "./privToPubKey.circom";
include "./stateLeafAndBallotTransformer.circom";
include "./trees/incrementalQuinTree.circom";
include "../node_modules/circomlib/circuits/mux1.circom";
include "./utils.circom";

// Proves the correctness of processing a batch of messages.
Expand Down
6 changes: 5 additions & 1 deletion circuits/circom/stateLeafAndBallotTransformer.circom
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
pragma circom 2.0.0;

// circomlib import
include "./mux1.circom";

// local import
include "./messageValidator.circom";
include "../node_modules/circomlib/circuits/mux1.circom";

// Apply a command to a state leaf and ballot.
template StateLeafAndBallotTransformer() {
Expand Down
7 changes: 5 additions & 2 deletions circuits/circom/subsidy.circom
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
pragma circom 2.0.0;
include "../node_modules/circomlib/circuits/comparators.circom";

// circomlib import
include "./comparators.circom";

// local imports
include "./trees/incrementalQuinTree.circom";
include "./trees/calculateTotal.circom";
include "./trees/checkRoot.circom";
include "./hasherSha256.circom";
include "./hasherPoseidon.circom";
include "./unpackElement.circom";

include "./float.circom";

/*
Expand Down
6 changes: 5 additions & 1 deletion circuits/circom/tallyVotes.circom
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
pragma circom 2.0.0;
include "../node_modules/circomlib/circuits/comparators.circom";

// circomlib import
include "./comparators.circom";

// local imports
include "./trees/incrementalQuinTree.circom";
include "./trees/calculateTotal.circom";
include "./trees/checkRoot.circom";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pragma circom 2.0.0;

include "../processMessages.circom";

/*
stateTreeDepth,
msgTreeDepth,
Expand Down
5 changes: 5 additions & 0 deletions circuits/circom/test/SubsidyPerBatch_10-1-2_test.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.0.0;

include "../subsidy.circom";

component main {public [inputHash]} = SubsidyPerBatch(10, 1, 2);
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pragma circom 2.0.0;

include "../tallyVotes.circom";

component main {public [inputHash]} = TallyVotes(10, 1, 2);
/*stateTreeDepth,*/
/*intStateTreeDepth,*/
/*voteOptionTreeDepth*/
4 changes: 0 additions & 4 deletions circuits/circom/test/calculateTotal_test.circom

This file was deleted.

10 changes: 0 additions & 10 deletions circuits/circom/test/ceremonyParams/processMessages_test.circom

This file was deleted.

7 changes: 0 additions & 7 deletions circuits/circom/test/ceremonyParams/tallyVotes_test.circom

This file was deleted.

4 changes: 0 additions & 4 deletions circuits/circom/test/ecdh_test.circom

This file was deleted.

4 changes: 0 additions & 4 deletions circuits/circom/test/hasher13_test.circom

This file was deleted.

4 changes: 0 additions & 4 deletions circuits/circom/test/hasher3_test.circom

This file was deleted.

4 changes: 0 additions & 4 deletions circuits/circom/test/hasher4_test.circom

This file was deleted.

4 changes: 0 additions & 4 deletions circuits/circom/test/hasher5_test.circom

This file was deleted.

4 changes: 0 additions & 4 deletions circuits/circom/test/hashleftright_test.circom

This file was deleted.

4 changes: 0 additions & 4 deletions circuits/circom/test/merkleTreeCheckRoot_test.circom

This file was deleted.

Loading
Loading