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.

63 lines
1.8 KiB

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