arnaucube
arnaucube/miksi-corePublic Self-hosted repository
miksi-core/README.md
README.mdRaw
 1# miksi [![Test](https://github.com/miksi-labs/miksi-core/workflows/Test/badge.svg)](https://github.com/miksi-labs/miksi-core/actions?query=workflow%3ATest)
 2
 3*From Esperanto, **miksi** (miks·i): to mingle, to blend, to mix, to shuffle*
 4
 5Ethereum mixer where all the computation & constructions are done offchain and then proved inside a zkSNARK to the Smart Contract (for the *deposit* and for the *withdraw*).
 6This means that the client builds a MerkleTree and makes all the needed computation, and then generates a zk-proof where proves that all the offchain computation is done following all the rules (no leaf deletion, only one leaf addition, correct leaf format).
 7This allows to use only `~325.000 gas` for the *deposit*, and `~308.000 gas` for the withdraw.
 8
 9![](miksi-logo00-small.png)
10
11**Warning:** This repository is in a very early stage. The current version works, but is not finished and there are some improvements to be added.
12
13WebApp to use miksi-core can be found at https://github.com/arnaucube/miksi-app
14
15## Circuits tests
16```
17npm run test-circuits
18```
19
20## Smart Contracts tests
21```
22npm run test-sc
23```
24
25### Compile circom circuit & generate Groth16 verifier contract
26
27```
28./compile-circuits.sh
29```
30
31
32## Spec draft
33**Note:** The spec & code is a work in progress, there are some pending works & improvements planned to do, and some diagrams for better explanation.
34
35### Deposit
36*All computation & constructions are done offchain and then proved inside a zkSNARK to the Smart Contract*
37- user generates a random `secret` & `nullifier`
38- computes the `commitment`, which is the Poseidon hash: `commitment = H(coinCode, amount, secret, nullifier)`, where:
39	- `coinCode`: code that specifies which currency is being used (`0`==ETH)
40	- `amount`: the amount to be deposited
41	- `secret`: random, private
42	- `nullifier`: random
43- get all the commitments from the SmartContract
44- build the MerkleTree with the getted commitments
45- add the new computed `commitment` into the MerkleTree
46- generate zkSNARK proof, where is proving:
47	- prover knows the `secret` & `nullifier` for the `commitment` which is in a leaf in the merkletree
48	- the transition from `RootOld` (the current one in the Smart Contract) to `RootNew` has been done following the rules (only one leaf addition, no leaf deletion, correct leaf format, etc)
49- user sends ETH to the smart contract `deposit` call, together with the zkProof data
50- smart contract verifies the zkProof of the deposit, and if everything is ok stores the commitment & the new root
51
52Deposit circuit can be found [here](https://github.com/miksi-labs/miksi-core/blob/master/circuits/deposit.circom).
53
54### Withdraw
55*All computation & constructions are done offchain and then proved inside a zkSNARK to the Smart Contract*
56- user gets all the commitments from the SmartContract
57- build the MerkleTree with the getted commitments
58- generate the siblings (merkle proof) for the `commitment` of which the user knows the `secret` & `nullifier`
59- generate zkSNARK proof, where is proving:
60        - user knows a `secret` for a public `nullifier`
61        - which `commitment` is in the MerkleTree
62        - which MerkleTree `root` is the one that knows the SmartContract
63- if the zkProof verification passes, and the nullifier was not already used, the Smart Contract sends the ETH to the specified address
64
65Withdraw circuit can be found [here](https://github.com/miksi-labs/miksi-core/blob/master/circuits/withdraw.circom).
66
67
68# Thanks
69Miksi is possible thanks to  [circom](https://github.com/iden3/circom), [circomlib](https://github.com/iden3/circomlib), [wasmsnark](https://github.com/iden3/wasmsnark), and thanks to the ideas about offchain computation validated with a zkSNARK in the [Zexe paper](https://eprint.iacr.org/2018/962.pdf).