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.

65 lines
2.0 KiB

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