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.

78 lines
2.6 KiB

  1. /*
  2. # withdraw.circom
  3. WARNING: WIP, very initial version of the miksi circuit
  4. +----------+
  5. | |
  6. PRI_secret+--------->+ Poseidon +<------+PRI_key+---------+
  7. | | | |
  8. | +----------+ +----+ |
  9. | nullifier+----->+ != +<-----+0 |
  10. | + +----+ v
  11. | | +--+-------+
  12. | v | |
  13. | +-----+----+ | |
  14. +--------->+ | | SMT +<------+PRI_siblings
  15. | +--------------------->+ Poseidon |
  16. PUB_coinCode+------->+ Poseidon | | Verifier |
  17. | | | +<------+PUB_root
  18. PUB_amount+--------->+ | | | +
  19. +----------+ +----------+ |
  20. |
  21. |
  22. +----+ +----+ |
  23. PUB_address+--->+ != +<-------+0+-------------->+ != +<-------+
  24. +----+ +----+
  25. */
  26. include "../node_modules/circomlib/circuits/comparators.circom";
  27. include "../node_modules/circomlib/circuits/poseidon.circom";
  28. include "../node_modules/circomlib/circuits/smt/smtverifier.circom";
  29. template Withdraw(nLevels) {
  30. signal input coinCode;
  31. signal input amount;
  32. signal private input secret;
  33. signal input nullifier;
  34. signal private input siblings[nLevels];
  35. signal input root;
  36. signal input address;
  37. signal private input key;
  38. component nullifierCmp = Poseidon(2, 6, 8, 57);
  39. nullifierCmp.inputs[0] <== key;
  40. nullifierCmp.inputs[1] <== secret;
  41. component nullifierCheck = IsEqual();
  42. nullifierCheck.in[0] <== nullifierCmp.out;
  43. nullifierCheck.in[1] <== nullifier;
  44. nullifierCheck.out === 1;
  45. component hash = Poseidon(4, 6, 8, 57);
  46. hash.inputs[0] <== coinCode;
  47. hash.inputs[1] <== amount;
  48. hash.inputs[2] <== secret;
  49. hash.inputs[3] <== nullifierCmp.out;
  50. component z = IsZero();
  51. z.in <== address;
  52. z.out === 0;
  53. component smtV = SMTVerifier(nLevels);
  54. smtV.enabled <== 1;
  55. smtV.fnc <== 0;
  56. smtV.root <== root;
  57. for (var i=0; i<nLevels; i++) {
  58. smtV.siblings[i] <== siblings[i];
  59. }
  60. smtV.oldKey <== 0;
  61. smtV.oldValue <== 0;
  62. smtV.isOld0 <== 0;
  63. smtV.key <== key;
  64. smtV.value <== hash.out;
  65. }