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*).
 6
 7This 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).
 8This allows to use only `~325.000 gas` for the *deposit*, and `~308.000 gas` for the withdraw.
 9
10![](miksi-logo00-small.png)
11
12**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.
13
14WebApp to use miksi-core can be found at https://github.com/arnaucube/miksi-app
15
16## Circuits tests
17```
18npm run test-circuits
19```
20
21## Smart Contracts tests
22```
23npm run test-sc
24```
25
26### Compile circom circuit & generate Groth16 verifier contract
27
28```
29./compile-circuits.sh
30```
31
32
33## Spec draft
34**Note:** The spec & code is a work in progress, there are some pending works & improvements planned to do, and some diagrams for better explanation.
35
36### Deposit
37*All computation & constructions are done offchain and then proved inside a zkSNARK to the Smart Contract*
38- user generates a random `secret` & `nullifier`
39- computes the `commitment`, which is the Poseidon hash: `commitment = H(coinCode, amount, secret, nullifier)`, where:
40	- `coinCode`: code that specifies which currency is being used (`0`==ETH)
41	- `amount`: the amount to be deposited
42	- `secret`: random, private
43	- `nullifier`: random
44- get all the commitments from the SmartContract
45- build the MerkleTree with the getted commitments
46- add the new computed `commitment` into the MerkleTree
47- generate zkSNARK proof, where is proving:
48	- prover knows the `secret` & `nullifier` for the `commitment` which is in a leaf in the merkletree
49	- 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)
50- user sends ETH to the smart contract `deposit` call, together with the zkProof data
51- smart contract verifies the zkProof of the deposit, and if everything is ok stores the commitment & the new root
52
53Deposit circuit can be found [here](https://github.com/miksi-labs/miksi-core/blob/master/circuits/deposit.circom).
54
55### Withdraw
56*All computation & constructions are done offchain and then proved inside a zkSNARK to the Smart Contract*
57- user gets all the commitments from the SmartContract
58- build the MerkleTree with the getted commitments
59- generate the siblings (merkle proof) for the `commitment` of which the user knows the `secret` & `nullifier`
60- generate zkSNARK proof, where is proving:
61        - user knows a `secret` for a public `nullifier`
62        - which `commitment` is in the MerkleTree
63        - which MerkleTree `root` is the one that knows the SmartContract
64- if the zkProof verification passes, and the nullifier was not already used, the Smart Contract sends the ETH to the specified address
65
66Withdraw circuit can be found [here](https://github.com/miksi-labs/miksi-core/blob/master/circuits/withdraw.circom).
67
68
69# Thanks
70Miksi 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).