Skip to content

Commit

Permalink
Merge branch 'dev' into feat/subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
hangleang authored Feb 26, 2024
2 parents 1ef5d72 + 6f99cac commit 2e5341e
Show file tree
Hide file tree
Showing 68 changed files with 1,590 additions and 274 deletions.
485 changes: 485 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions circuits/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,102 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.2.0](https://github.com/privacy-scaling-explorations/maci/compare/v1.1.1...v1.2.0) (2024-02-23)


### Features

* **circuits:** remove circomlib fork in favour of latest and zk-kit ([bf11b40](https://github.com/privacy-scaling-explorations/maci/commit/bf11b4092cd531cf0993534061cf7c24e8de44e2)), closes [#772](https://github.com/privacy-scaling-explorations/maci/issues/772)
* **circuits:** remove zkey-manager in favour of circomkit ([d79e9c0](https://github.com/privacy-scaling-explorations/maci/commit/d79e9c0ee18df27c3bd3e5e49924db21303d1c45))
* **contracts:** return contract addresses when deploying the poll contract ([e94998c](https://github.com/privacy-scaling-explorations/maci/commit/e94998c12d8a5f2bde2fb54b4af384d42e35d646))
* **proofs:** make preferred witness type in circuit's genProof function ([2b95044](https://github.com/privacy-scaling-explorations/maci/commit/2b95044921cd0bed72694d069e2f9ed8fa44e72e))
* **qv:** add optional flag to use quadratic voting or not in MACI ([86ba854](https://github.com/privacy-scaling-explorations/maci/commit/86ba8548780049245482e5277cc47f4a8776e9e6))


### Bug Fixes

* **add safelessthan:** add SafeLessThan in utility.circom and use it in incrementalQuinnTree.circom ([60727d4](https://github.com/privacy-scaling-explorations/maci/commit/60727d4d10406edda32ad28e53d399d41d45ed88))
* **build:** fix bug that prevented c witness from being compiled ([d22caad](https://github.com/privacy-scaling-explorations/maci/commit/d22caadca15dc6de639720faf1d9a53259714ce8))
* **circuits:** enforce use of stateIndex from message ([510e6ee](https://github.com/privacy-scaling-explorations/maci/commit/510e6ee365958e8c7f72cfca6cea75d15a89d28b))
* **circuits:** ensure we account for correct num signups in messageValidator ([04c847c](https://github.com/privacy-scaling-explorations/maci/commit/04c847cbc3f34979f292ec7561109f14e274efaf))
* **circuits:** fix coordinator censoring by passing currentVoteWeight = 0 ([22e091d](https://github.com/privacy-scaling-explorations/maci/commit/22e091d2941b5e86ecd7df2f228bd0e10b6c4c47))
* **circuits:** replace execSync with execFileSync ([4c121ca](https://github.com/privacy-scaling-explorations/maci/commit/4c121ca0413495979be7af87da5474a9f0b093bf))
* **contracts:** save numSignups after merging maciStateAq inside the Poll contract ([4985b2d](https://github.com/privacy-scaling-explorations/maci/commit/4985b2d61655f3b802186fc03c2d85a658c0f0da)), closes [#1091](https://github.com/privacy-scaling-explorations/maci/issues/1091)
* **crypto:** get rid of potential prototype polution ([9b8a97c](https://github.com/privacy-scaling-explorations/maci/commit/9b8a97cc9661e0ee6f535cdcab19b4aa0fa98136))
* fixed the maci-circuit package to allow building on circom >2.0.7 ([e954f78](https://github.com/privacy-scaling-explorations/maci/commit/e954f78224d53342826bfe73b082b673e0f147c8))
* **incrementalquintree:** remove unnecessary condition check in incrementalQuinnTree.circom ([87b3397](https://github.com/privacy-scaling-explorations/maci/commit/87b339790a5d44adb8c5bf447346e16933c48d5c))
* **publish:** ensure we publish the correct files ([bc42724](https://github.com/privacy-scaling-explorations/maci/commit/bc42724b34cf0c047c5692fbf477ed013a102aee))
* remove trailing chars ([3101a60](https://github.com/privacy-scaling-explorations/maci/commit/3101a6016ebda3385273b47b2de33f5fd9c1221f))
* **safelessthan:** replaced several LessThan with SafeLessThan; fixed check on enoughVoiceCredit ([2d7a3a0](https://github.com/privacy-scaling-explorations/maci/commit/2d7a3a0efd33dfc3a5f4d3f95bec3adda7abb963))
* **topup:** check valid new state leaf balance ([ec12d2b](https://github.com/privacy-scaling-explorations/maci/commit/ec12d2b1ec31b0607f65be49a5679fcae5e3939d))


### Code Refactoring

* **circuits:** fix ts types, improve docs ([a849486](https://github.com/privacy-scaling-explorations/maci/commit/a84948685d2e4be426cef50c5c608c107b5142b1))
* **core:** refactor the core package subsidy and tally functions ([0af7dd2](https://github.com/privacy-scaling-explorations/maci/commit/0af7dd2d448c4796c3872665d43654343f9fc3e3))
* **core:** refactor the process message functions and general cleanup ([823cacd](https://github.com/privacy-scaling-explorations/maci/commit/823cacd8659281b8390b74c8d765b23ee7a83a80))
* **core:** remove unnecessary messageAq from Poll ([d3930f7](https://github.com/privacy-scaling-explorations/maci/commit/d3930f706963747903305cce1ee5a716ea28c31d))
* **core:** remove unnecessary stateAq from MaciState ([22a4f28](https://github.com/privacy-scaling-explorations/maci/commit/22a4f286010ff5add413eee88d933c0e74898346))
* **crypto:** remove ffjavascript and implement utils functions locally ([0b2986f](https://github.com/privacy-scaling-explorations/maci/commit/0b2986fcaadbfce37ff9fc0007ddeae97573924e)), closes [#458](https://github.com/privacy-scaling-explorations/maci/issues/458)
* fix ESLint issues ([6c0ed97](https://github.com/privacy-scaling-explorations/maci/commit/6c0ed97c0976a81b5e5506699d550ec93a553cb8))
* **maci-core:** refactor directory structure for quick core component access ([3aeba77](https://github.com/privacy-scaling-explorations/maci/commit/3aeba77435fbd783e5cecf88a1f2c0d4c58c8022))
* **nonqv:** optimize tally votes non qv circuit and contracts ([ea632a9](https://github.com/privacy-scaling-explorations/maci/commit/ea632a97862c4304c764f511ab480b3664224b5f))
* **optimisedmt:** remove dependency and implement locally ([c7d81e2](https://github.com/privacy-scaling-explorations/maci/commit/c7d81e20aaf6308c7d4e1efc09c497729f6a8f10))
* **remove messageaqfactory:** remove messageAqFactory; remove redundant pollFactory dependency ([dcd1c67](https://github.com/privacy-scaling-explorations/maci/commit/dcd1c67f14f0cb92979d13e7887373ff6e354a6f))
* **repo:** remove redundant code from certain packages ([d55497a](https://github.com/privacy-scaling-explorations/maci/commit/d55497a9805812b2d2472386caecf75995d6efcf))


### Miscellaneous

* add a badges to README.md ([888524b](https://github.com/privacy-scaling-explorations/maci/commit/888524baae82d56edbf0c794e587de174906c34c))
* add test file routes to circuit test commands ([6f0228f](https://github.com/privacy-scaling-explorations/maci/commit/6f0228f115211f8cf6581d7e80438791f98f6de0))
* add types check ([69f038f](https://github.com/privacy-scaling-explorations/maci/commit/69f038f55e6c740d43b8b5376db999bcf92de845))
* apply prettier ([8b905c0](https://github.com/privacy-scaling-explorations/maci/commit/8b905c0948d4a1f950653c6812067ec98ebfcbc8))
* bundle size optimizations ([18da49c](https://github.com/privacy-scaling-explorations/maci/commit/18da49c791e53350158659df8248d48af8e80f6d))
* **ceremony:** add circuit tests with ceremony params ([58611db](https://github.com/privacy-scaling-explorations/maci/commit/58611dbf62f2dc01cf978d6bf01cf15bdef77356))
* **changelog:** add CHANGELOG of v1.1.1 ([f0c315a](https://github.com/privacy-scaling-explorations/maci/commit/f0c315a4c1b86f88839f2dbe4c4b9f59193f7be4))
* **circuits:** integrate linter ([93e8a65](https://github.com/privacy-scaling-explorations/maci/commit/93e8a657fccb3232b18bf191984c6bea5ccabf85))
* **circuits:** refactor and add tests for the circom circuits ([4d6419b](https://github.com/privacy-scaling-explorations/maci/commit/4d6419b4962af6e94929721a3008406b6bc29c1e))
* **circuits:** remove todo messages ([071acc4](https://github.com/privacy-scaling-explorations/maci/commit/071acc42322be736932ef05d6e02356da4808bda))
* **cli:** optimize bundle size ([39268b2](https://github.com/privacy-scaling-explorations/maci/commit/39268b2ff8e0d27d062c6d3bc52a63ce8038ec5e))
* **contract:** apply linter for deploy scripts and contracts ([9af9c04](https://github.com/privacy-scaling-explorations/maci/commit/9af9c0497a2491eaf89fbff475cf0f60bc04f59c))
* **contracts:** add proof generation for task coordinator ([c145883](https://github.com/privacy-scaling-explorations/maci/commit/c145883ecc42b87170a401894b68cd2287d15832))
* **core:** add `CircuitInputs` type ([c4b72b0](https://github.com/privacy-scaling-explorations/maci/commit/c4b72b0f0b25a1bb147348a728a9550c8b6460a1))
* **core:** add Typedoc comments ([a8521ee](https://github.com/privacy-scaling-explorations/maci/commit/a8521eea97bca47298bc2c59ae1c31df9533258b))
* **core:** integrate linter ([614e76b](https://github.com/privacy-scaling-explorations/maci/commit/614e76b1b1de5d2c9876b11f15439e92b86db8f6))
* **dependencies:** update project dependencies and remove redundant ones ([4c5ac27](https://github.com/privacy-scaling-explorations/maci/commit/4c5ac27767492c9867a6e2ab2acd6b10fe132847))
* **deps-dev:** bump @types/node from 18.19.6 to 20.10.8 ([6645120](https://github.com/privacy-scaling-explorations/maci/commit/664512038212d36d40799e8c4787847735bd7d82))
* **deps-dev:** bump @types/node from 20.10.8 to 20.11.0 ([805d253](https://github.com/privacy-scaling-explorations/maci/commit/805d2536a54478c51403362419ecad0b6ab736a7))
* **deps-dev:** bump @types/node from 20.11.0 to 20.11.2 ([45839e8](https://github.com/privacy-scaling-explorations/maci/commit/45839e8c2668ec56ea06221758605f88029ea8a1))
* **deps-dev:** bump @types/node from 20.11.10 to 20.11.16 ([8144919](https://github.com/privacy-scaling-explorations/maci/commit/8144919939f7d9a841eb6fce7182628cedbf8746))
* **deps-dev:** bump @types/node from 20.11.16 to 20.11.17 ([44de5db](https://github.com/privacy-scaling-explorations/maci/commit/44de5db0c25a5fdfd5c13c397f49edb7185bf1f5))
* **deps-dev:** bump @types/node from 20.11.17 to 20.11.19 ([8d86b32](https://github.com/privacy-scaling-explorations/maci/commit/8d86b32ef70b89f4239aad3903fd36937cf6a90f))
* **deps-dev:** bump @types/node from 20.11.2 to 20.11.5 ([7698ede](https://github.com/privacy-scaling-explorations/maci/commit/7698edef2b95bc017e54c1fc0d796ccc9da3de85))
* **deps-dev:** bump @types/node from 20.11.5 to 20.11.10 ([a2c445a](https://github.com/privacy-scaling-explorations/maci/commit/a2c445a295e792e421f6c1537b2b21f8a7648683))
* **deps-dev:** bump lerna from 6.6.2 to 8.0.2 ([4b150ad](https://github.com/privacy-scaling-explorations/maci/commit/4b150ade7c4fbaf88eb0e1f629cec6749377706d))
* **deps-dev:** bump mocha from 10.2.0 to 10.3.0 ([2b76e04](https://github.com/privacy-scaling-explorations/maci/commit/2b76e0445f5da5864a335352f66eac33c070ab29))
* **deps-dev:** bump typescript from 5.2.2 to 5.3.3 ([4ec399d](https://github.com/privacy-scaling-explorations/maci/commit/4ec399dd6e984c12ebd24d0b20c14c1104872500))
* **deps:** bump circomkit from 0.0.21 to 0.0.22 ([1c4e405](https://github.com/privacy-scaling-explorations/maci/commit/1c4e4051920e84df88a28b1ed908ee8e6d3266b8))
* **deps:** bump circomkit from 0.0.22 to 0.0.24 ([2ff4d38](https://github.com/privacy-scaling-explorations/maci/commit/2ff4d380d6601e363abd2435d59ac150ca2c190f))
* **deps:** bump snarkjs from 0.7.2 to 0.7.3 ([cf95b6f](https://github.com/privacy-scaling-explorations/maci/commit/cf95b6ff6f66342e3b75dedd5c70d62f8f0816b1))
* **deps:** update circomkit to latest version and add console logs ([9f7ec50](https://github.com/privacy-scaling-explorations/maci/commit/9f7ec50dadcfb1a27bccb845f1552a2af2b8b1f2))
* linter ([42ea4f0](https://github.com/privacy-scaling-explorations/maci/commit/42ea4f0ae8b342f6bd5ca5ac86f1bdd143978324))
* linter unification ([61a8bcd](https://github.com/privacy-scaling-explorations/maci/commit/61a8bcd915fd3e4b4da3c00d40704d892c02f51b))
* **maci:** added README for the circuit package and fixed typo in contract's README ([4d0f74b](https://github.com/privacy-scaling-explorations/maci/commit/4d0f74b8480cd2d20e835d43b33c2aab6578d194))
* **maci:** updated docs after review ([fd0da34](https://github.com/privacy-scaling-explorations/maci/commit/fd0da346406a5c2c6648bbff1b081863039bcf2b)), closes [#531](https://github.com/privacy-scaling-explorations/maci/issues/531) [#556](https://github.com/privacy-scaling-explorations/maci/issues/556)
* **poll:** unify pollId type ([21d01ef](https://github.com/privacy-scaling-explorations/maci/commit/21d01efc565df74ea8b71dfeeead60be5a07db56))
* **publishing:** remove bash script for empty ballot roots contract ([025287c](https://github.com/privacy-scaling-explorations/maci/commit/025287c778547e0acb1582532f3412e022cca6fa))
* **release:** publish 1.1.2 ([10b3a85](https://github.com/privacy-scaling-explorations/maci/commit/10b3a85cc9b53c0fc1ccdf54221a48ec8d6efe0d))
* remove `gitHead` field from package.json ([d38ba71](https://github.com/privacy-scaling-explorations/maci/commit/d38ba71301469f350b3d80eab5bf94e779dda9cc))
* run prettier ([d09cd0e](https://github.com/privacy-scaling-explorations/maci/commit/d09cd0e01ac747245307ceec5343d9ed30d7a6f0))
* run prettier fix after bumping version ([e1f85a5](https://github.com/privacy-scaling-explorations/maci/commit/e1f85a53bbb72696b6998af5406748fd18df4701))
* **topup:** implement test cases for the topup feature ([7775a8b](https://github.com/privacy-scaling-explorations/maci/commit/7775a8b3295f29b098446d3e78a4200c03c847dd))
* update circomlib dependency format in package.json ([f0e8d19](https://github.com/privacy-scaling-explorations/maci/commit/f0e8d1978db6a0771d876b828843bc763e397220))
* update README with build guide for MACI circuits ([77fdb63](https://github.com/privacy-scaling-explorations/maci/commit/77fdb63c9993612117505bc8319555321bf8b9d0))



## [1.1.2](https://github.com/gurrpi/maci/compare/v1.1.1...v1.1.2) (2023-01-19)

### Code Refactoring
Expand Down
22 changes: 16 additions & 6 deletions circuits/circom/processMessages.circom
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ template ProcessMessages(

// The index of the last message leaf 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 mesages is not a multiple of the
// the last batch and the total number of messages is not a multiple of the
// batch size.
signal batchEndIndex;

Expand Down Expand Up @@ -401,8 +401,8 @@ template ProcessTopup(stateTreeDepth) {
// msgType of topup command is 2
amt <== amount * (msgType - 1);
index <== stateTreeIndex * (msgType - 1);
component validCreditBalance = LessEqThan(N_BITS);
// check stateIndex, if invalid index, set index and amount to zero

// check stateIndex, if invalid index, set index to zero
component validStateLeafIndex = LessEqThan(N_BITS);
validStateLeafIndex.in[0] <== index;
validStateLeafIndex.in[1] <== numSignUps;
Expand All @@ -419,17 +419,27 @@ template ProcessTopup(stateTreeDepth) {
amtMux.c[0] <== 0;
amtMux.c[1] <== amt;

// check less than field size
// check new balance is valid
signal newCreditBalance;
// add either 0 or the actual amount (if the state index is valid)
newCreditBalance <== stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] + amtMux.out;

// we need to ensure it did not overflow (so previous must be <= new)
component validCreditBalance = SafeLessEqThan(N_BITS);
validCreditBalance.in[0] <== stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX];
validCreditBalance.in[1] <== newCreditBalance;

// if the new one is <= the old one, then we have a valid topup
component creditBalanceMux = Mux1();
creditBalanceMux.s <== validCreditBalance.out;
creditBalanceMux.c[0] <== stateLeaf[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX];
creditBalanceMux.c[1] <== newCreditBalance;

// update credit voice balance
component newStateLeafHasher = Hasher4();
newStateLeafHasher.in[STATE_LEAF_PUB_X_IDX] <== stateLeaf[STATE_LEAF_PUB_X_IDX];
newStateLeafHasher.in[STATE_LEAF_PUB_Y_IDX] <== stateLeaf[STATE_LEAF_PUB_Y_IDX];
newStateLeafHasher.in[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] <== newCreditBalance;
newStateLeafHasher.in[STATE_LEAF_VOICE_CREDIT_BALANCE_IDX] <== creditBalanceMux.out;
newStateLeafHasher.in[STATE_LEAF_TIMESTAMP_IDX] <== stateLeaf[STATE_LEAF_TIMESTAMP_IDX];

component stateLeafPathIndices = QuinGeneratePathIndices(stateTreeDepth);
Expand Down Expand Up @@ -534,7 +544,7 @@ template ProcessOne(stateTreeDepth, voteOptionTreeDepth) {

// -----------------------------------------------------------------------
// 2. If msgType = 0 and isValid is 0, generate indices for leaf 0
// Otherwise, generate indices for commmand.stateIndex or topupStateIndex depending on msgType
// Otherwise, generate indices for command.stateIndex or topupStateIndex depending on msgType
signal indexByType;
signal tmpIndex1;
signal tmpIndex2;
Expand Down
4 changes: 2 additions & 2 deletions circuits/circom/processMessagesNonQv.circom
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ template ProcessMessagesNonQv(

// The index of the last message leaf 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 mesages is not a multiple of the
// the last batch and the total number of messages is not a multiple of the
// batch size.
signal batchEndIndex;

Expand Down Expand Up @@ -457,7 +457,7 @@ template ProcessOneNonQv(stateTreeDepth, voteOptionTreeDepth) {

// -----------------------------------------------------------------------
// 2. If msgType = 0 and isValid is 0, generate indices for leaf 0
// Otherwise, generate indices for commmand.stateIndex or topupStateIndex depending on msgType
// Otherwise, generate indices for command.stateIndex or topupStateIndex depending on msgType
signal indexByType;
signal tmpIndex1;
signal tmpIndex2;
Expand Down
2 changes: 1 addition & 1 deletion circuits/circom/stateLeafAndBallotTransformer.circom
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ template StateLeafAndBallotTransformer() {
signal input slPubKey[2];
// the current voice credit balance of the signed up user
signal input slVoiceCreditBalance;
// the signup timestmap
// the signup timestamp
signal input slTimestamp;
// when the poll ends
signal input pollEndTimestamp;
Expand Down
2 changes: 1 addition & 1 deletion circuits/circom/stateLeafAndBallotTransformerNonQv.circom
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ template StateLeafAndBallotTransformerNonQv() {
signal input slPubKey[2];
// the current voice credit balance of the signed up user
signal input slVoiceCreditBalance;
// the signup timestmap
// the signup timestamp
signal input slTimestamp;
// when the poll ends
signal input pollEndTimestamp;
Expand Down
2 changes: 1 addition & 1 deletion circuits/circom/trees/incrementalQuinTree.circom
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include "./checkRoot.circom";
include "../hasherPoseidon.circom";
include "../utils.circom";

// This file contains circuits for quintary Merkle tree verifcation.
// This file contains circuits for quintary Merkle tree verification.
// It assumes that each node contains 5 leaves, as we use the PoseidonT6
// circuit to hash leaves, which supports up to 5 input elements.

Expand Down
8 changes: 4 additions & 4 deletions circuits/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maci-circuits",
"version": "1.1.2",
"version": "1.2.0",
"description": "zk-SNARK circuits for MACI",
"main": "build/ts/index.js",
"files": [
Expand Down Expand Up @@ -41,9 +41,9 @@
"@zk-kit/circuits": "^0.3.0",
"circomkit": "^0.0.24",
"circomlib": "^2.0.5",
"maci-core": "^1.1.2",
"maci-crypto": "^1.1.2",
"maci-domainobjs": "^1.1.2",
"maci-core": "^1.2.0",
"maci-crypto": "^1.2.0",
"maci-domainobjs": "^1.2.0",
"snarkjs": "^0.7.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion circuits/ts/__tests__/CeremonyParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe("Ceremony param tests", () => {
await testCircuit.expectConstraintPass(witness);
});

it("should produce the correct result if the inital tally is not zero", async () => {
it("should produce the correct result if the initial tally is not zero", async () => {
const generatedInputs = poll.tallyVotes() as unknown as ITallyVotesInputs;

// Start the tally from non-zero value
Expand Down
2 changes: 1 addition & 1 deletion circuits/ts/__tests__/Ecdh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("Public key derivation circuit", () => {
pubKey: keypair2.pubKey.asCircuitInputs() as unknown as bigint[],
};

// calculate first time witness and check contraints
// calculate first time witness and check constraints
const witness = await circuit.calculateWitness(circuitInputs);
await circuit.expectConstraintPass(witness);

Expand Down
Loading

0 comments on commit 2e5341e

Please sign in to comment.