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.

86 lines
2.9 KiB

  1. /*
  2. # deposit.circom
  3. +----------+ +----------+
  4. PUB_nullifier+------>+ | | |
  5. | | | SMT |
  6. PUB_coinCode+------->+ | | Poseidon +<------+PUB_rootOld
  7. | Poseidon +-+----------->+ Verifier |
  8. PUB_amount+--------->+ | | | Non |
  9. | | | | Existance+<------+PRI_siblings
  10. PRI_secret+--------->+ | | | | +
  11. +----------+ | +----------+ |
  12. | |
  13. | |
  14. | +----------+ |
  15. | | | |
  16. | | | |
  17. +----+ | | SMT +<---------+
  18. PUB_commitment+----> == +<--------+----------->+ Poseidon |
  19. +----+ | Verifier |
  20. | +<------+PUB_rootNew
  21. | |
  22. +----------+
  23. */
  24. include "../node_modules/circomlib/circuits/comparators.circom";
  25. include "../node_modules/circomlib/circuits/poseidon.circom";
  26. include "../node_modules/circomlib/circuits/smt/smtverifier.circom";
  27. template Deposit(nLevels) {
  28. signal input coinCode;
  29. signal input amount;
  30. signal private input secret;
  31. signal private input nullifier;
  32. signal private input oldKey;
  33. signal private input siblingsOld[nLevels];
  34. signal private input siblingsNew[nLevels];
  35. signal input rootOld;
  36. signal input rootNew;
  37. signal input commitment;
  38. component hash = Poseidon(4, 6, 8, 57);
  39. hash.inputs[0] <== coinCode;
  40. hash.inputs[1] <== amount;
  41. hash.inputs[2] <== secret;
  42. hash.inputs[3] <== nullifier;
  43. component comCheck = IsEqual();
  44. comCheck.in[0] <== hash.out;
  45. comCheck.in[1] <== commitment;
  46. comCheck.out === 1;
  47. // TODO instead of 2 siblings input, get siblingsOld from siblingsNew[len-1]
  48. component smtOld = SMTVerifier(nLevels);
  49. smtOld.enabled <== 1;
  50. smtOld.fnc <== 1;
  51. smtOld.root <== rootOld;
  52. for (var i=0; i<nLevels; i++) {
  53. smtOld.siblings[i] <== siblingsOld[i];
  54. }
  55. /* smtOld.oldKey <== 1; */
  56. smtOld.oldKey <== oldKey;
  57. smtOld.oldValue <== 0;
  58. smtOld.isOld0 <== 0;
  59. smtOld.key <== hash.out;
  60. smtOld.value <== 0;
  61. component smtNew = SMTVerifier(nLevels);
  62. smtNew.enabled <== 1;
  63. smtNew.fnc <== 0;
  64. smtNew.root <== rootNew;
  65. for (var i=0; i<nLevels; i++) {
  66. smtNew.siblings[i] <== siblingsNew[i];
  67. }
  68. smtNew.oldKey <== 0;
  69. smtNew.oldValue <== 0;
  70. smtNew.isOld0 <== 0;
  71. smtNew.key <== hash.out;
  72. smtNew.value <== 0;
  73. }
  74. component main = Deposit(5);