You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
3.7 KiB

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