Skip to content

Commit

Permalink
proper repo structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kendricktan committed Sep 3, 2019
1 parent 36a9d31 commit 2eac0b4
Show file tree
Hide file tree
Showing 14 changed files with 1,320,581 additions and 3 deletions.
88 changes: 88 additions & 0 deletions .gitignore
@@ -0,0 +1,88 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/
1 change: 1 addition & 0 deletions LICENSE
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2019 barryWhiteHat
Copyright (c) 2019 Kendrick Tan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 14 additions & 2 deletions README.md
@@ -1,10 +1,22 @@
# maci
Minimal anti collusion infrastructure

# Intro

This project is based upon https://ethresear.ch/t/minimal-anti-collusion-infrastructure

# Developers

This project has been written to be compatible with node `v10.16.3`. You can install specific node versions via [nvm](https://github.com/nvm-sh/nvm).

Install yarn if you haven't already: `npm install -g yarn`.

```bash
yarn install

yarn run circuit:compile
yarn run circuit:setup
```


# Contribution

We are actively seeking help on implementing this project please join https://t.me/joinchat/LUgOpE7J2gstRcZqdERyvw and ask about contributions
Expand Down
37 changes: 36 additions & 1 deletion ZK_Snarks/Add_New_Leaf/input.json
@@ -1 +1,36 @@
{"tree_root":"13940760067461765982130938392974845347296680163107645280208691062931117375050","accounts_pubkeys":[["5686635804472582232015924858874568287077998278299757444567424097636989354076","20652491795398389193695348132128927424105970377868038232787590371122242422611"],["5188413625993601883297433934250988745151922355819390722918528461123462745458","12688531930957923993246507021135702202363596171614725698211865710242486568828"]],"accounts_detail":[1,0],"sender_pubkey":["5686635804472582232015924858874568287077998278299757444567424097636989354076","20652491795398389193695348132128927424105970377868038232787590371122242422611"],"sender_detail":1,"sender_updated_pubkey":["5686635804472582232015924858874568287077998278299757444567424097636989354076","20652491795398389193695348132128927424105970377868038232787590371122242422611"],"sender_updated_detail":0,"signature_R8x":"20258073093533048486408567149817946255826763269974716247180311231838004556173","signature_R8y":"15883739858452910212315873149043408477939274817445002957584557757545867561995","signature_S":"1748175765385080397470192017798176242537950262566270798123576595520989193946","sender_proof":["11443493029691561771346338450510191575616699340232411888801888147474370182506"],"sender_proof_pos":[1]}
{
"tree_root": "13940760067461765982130938392974845347296680163107645280208691062931117375050",
"accounts_pubkeys": [
[
"5686635804472582232015924858874568287077998278299757444567424097636989354076",
"20652491795398389193695348132128927424105970377868038232787590371122242422611"
],
[
"5188413625993601883297433934250988745151922355819390722918528461123462745458",
"12688531930957923993246507021135702202363596171614725698211865710242486568828"
]
],
"accounts_detail": [
1,
0
],
"sender_pubkey": [
"5686635804472582232015924858874568287077998278299757444567424097636989354076",
"20652491795398389193695348132128927424105970377868038232787590371122242422611"
],
"sender_detail": 1,
"sender_updated_pubkey": [
"5686635804472582232015924858874568287077998278299757444567424097636989354076",
"20652491795398389193695348132128927424105970377868038232787590371122242422611"
],
"sender_updated_detail": 0,
"signature_R8x": "20258073093533048486408567149817946255826763269974716247180311231838004556173",
"signature_R8y": "15883739858452910212315873149043408477939274817445002957584557757545867561995",
"signature_S": "1748175765385080397470192017798176242537950262566270798123576595520989193946",
"sender_proof": [
"11443493029691561771346338450510191575616699340232411888801888147474370182506"
],
"sender_proof_pos": [
1
]
}
82 changes: 82 additions & 0 deletions circuits/circuit.circom
@@ -0,0 +1,82 @@
include "./leaf_existence.circom";
include "./verify_eddsamimc.circom";
include "./get_merkle_root.circom";
include "../node_modules/circomlib/circuits/mimc.circom";

template ProcessUpdate(k){
// k is depth of accounts tree

// accounts tree info
signal input tree_root;
signal private input accounts_pubkeys[2**k, 2];
signal private input accounts_detail[2**k];

// vote update info
signal private input sender_pubkey[2];
signal private input sender_detail;
signal private input sender_updated_pubkey[2];
signal private input sender_updated_detail;
signal private input signature_R8x;
signal private input signature_R8y;
signal private input signature_S;
signal private input sender_proof[k];
signal private input sender_proof_pos[k];

// output
signal output new_tree_root;

// verify sender account exists in tree_root
component senderExistence = LeafExistence(k, 3);
senderExistence.preimage[0] <== sender_pubkey[0];
senderExistence.preimage[1] <== sender_pubkey[1];
senderExistence.preimage[2] <== sender_detail;
senderExistence.root <== tree_root;
for (var i = 0; i < k; i++){
senderExistence.paths2_root_pos[i] <== sender_proof_pos[i];
senderExistence.paths2_root[i] <== sender_proof[i];
}

// check that vote update was signed by voter
component signatureCheck = VerifyEdDSAMiMC(5);
signatureCheck.from_x <== sender_pubkey[0];
signatureCheck.from_y <== sender_pubkey[1];
signatureCheck.R8x <== signature_R8x;
signatureCheck.R8y <== signature_R8y;
signatureCheck.S <== signature_S;
signatureCheck.preimage[0] <== sender_pubkey[0];
signatureCheck.preimage[1] <== sender_pubkey[1];
signatureCheck.preimage[2] <== sender_updated_detail;
signatureCheck.preimage[3] <== sender_updated_pubkey[0];
signatureCheck.preimage[4] <== sender_updated_pubkey[1];
// change voter leave and hash
component newSenderLeaf = MultiMiMC7(3,91){
newSenderLeaf.in[0] <== sender_updated_pubkey[0];
newSenderLeaf.in[1] <== sender_updated_pubkey[1];
newSenderLeaf.in[2] <== sender_updated_detail;
}

// update tree_root
component computed_final_root = GetMerkleRoot(k);
computed_final_root.leaf <== newSenderLeaf.out;
for (var i = 0; i < k; i++){
computed_final_root.paths2_root_pos[i] <== sender_proof_pos[i];
computed_final_root.paths2_root[i] <== sender_proof[i];
}

// verify voter leaf has been updated
component senderExistence2 = LeafExistence(k, 3);
senderExistence2.preimage[0] <== sender_updated_pubkey[0];
senderExistence2.preimage[1] <== sender_updated_pubkey[1];
senderExistence2.preimage[2] <== sender_updated_detail;
senderExistence2.root <== computed_final_root.out;
for (var i = 0; i < k; i++){
senderExistence2.paths2_root_pos[i] <== sender_proof_pos[i];
senderExistence2.paths2_root[i] <== sender_proof[i];
}


// output final tree_root
new_tree_root <== computed_final_root.out;
}

component main = ProcessUpdate(1);
29 changes: 29 additions & 0 deletions circuits/get_merkle_root.circom
@@ -0,0 +1,29 @@
include "../node_modules/circomlib/circuits/mimc.circom";

template GetMerkleRoot(k){
// k is depth of tree

signal input leaf;
signal input paths2_root[k];
signal input paths2_root_pos[k];

signal output out;

// hash of first two entries in tx Merkle proof
component merkle_root[k];
merkle_root[0] = MultiMiMC7(2,91);
merkle_root[0].in[0] <== paths2_root[0] - paths2_root_pos[0]* (paths2_root[0] - leaf);
merkle_root[0].in[1] <== leaf - paths2_root_pos[0]* (leaf - paths2_root[0]);

// hash of all other entries in tx Merkle proof
for (var v = 1; v < k; v++){
merkle_root[v] = MultiMiMC7(2,91);
merkle_root[v].in[0] <== paths2_root[v] - paths2_root_pos[v]* (paths2_root[v] - merkle_root[v-1].out);
merkle_root[v].in[1] <== merkle_root[v-1].out - paths2_root_pos[v]* (merkle_root[v-1].out - paths2_root[v]);

}

// output computed Merkle root
out <== merkle_root[k-1].out;

}
32 changes: 32 additions & 0 deletions circuits/leaf_existence.circom
@@ -0,0 +1,32 @@
include "./get_merkle_root.circom";
include "../node_modules/circomlib/circuits/mimc.circom";

// checks for existence of leaf in tree of depth k

template LeafExistence(k, l){
// k is depth of tree
// l is length of preimage of leaf

signal private input preimage[l];
signal input root;
signal input paths2_root_pos[k];
signal input paths2_root[k];

component leaf = MultiMiMC7(l,91);
for (var i = 0; i < l; i++){
leaf.in[i] <== preimage[i];
}

component computed_root = GetMerkleRoot(k);
computed_root.leaf <== leaf.out;

for (var w = 0; w < k; w++){
computed_root.paths2_root[w] <== paths2_root[w];
computed_root.paths2_root_pos[w] <== paths2_root_pos[w];
}

// equality constraint: input tx root === computed tx root
root === computed_root.out;

}

25 changes: 25 additions & 0 deletions circuits/verify_eddsamimc.circom
@@ -0,0 +1,25 @@
include "../node_modules/circomlib/circuits/eddsamimc.circom";
include "../node_modules/circomlib/circuits/mimc.circom";

template VerifyEdDSAMiMC(k) {
signal input from_x;
signal input from_y;
signal input R8x;
signal input R8y;
signal input S;
signal private input preimage[k];

component M = MultiMiMC7(k,91);
for (var i = 0; i < k; i++){
M.in[i] <== preimage[i];
}

component verifier = EdDSAMiMCVerifier();
verifier.enabled <== 1;
verifier.Ax <== from_x;
verifier.Ay <== from_y;
verifier.R8x <== R8x;
verifier.R8y <== R8y;
verifier.S <== S;
verifier.M <== M.out;
}

0 comments on commit 2eac0b4

Please sign in to comment.