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.

88 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 oldValue;
  34. signal private input siblingsOld[nLevels];
  35. signal private input siblingsNew[nLevels];
  36. signal input rootOld;
  37. signal input rootNew;
  38. signal input commitment;
  39. signal input key;
  40. component hash = Poseidon(4, 6, 8, 57);
  41. hash.inputs[0] <== coinCode;
  42. hash.inputs[1] <== amount;
  43. hash.inputs[2] <== secret;
  44. hash.inputs[3] <== nullifier; // nullifier
  45. component comCheck = IsEqual();
  46. comCheck.in[0] <== hash.out;
  47. comCheck.in[1] <== commitment;
  48. comCheck.out === 1;
  49. // TODO instead of 2 siblings input, get siblingsOld from siblingsNew[len-1]
  50. component smtOld = SMTVerifier(nLevels);
  51. smtOld.enabled <== 1;
  52. smtOld.fnc <== 1;
  53. smtOld.root <== rootOld;
  54. for (var i=0; i<nLevels; i++) {
  55. smtOld.siblings[i] <== siblingsOld[i];
  56. }
  57. /* smtOld.oldKey <== 1; */
  58. smtOld.oldKey <== oldKey;
  59. smtOld.oldValue <== oldValue;
  60. smtOld.isOld0 <== 0;
  61. smtOld.key <== key;
  62. smtOld.value <== hash.out;
  63. component smtNew = SMTVerifier(nLevels);
  64. smtNew.enabled <== 1;
  65. smtNew.fnc <== 0;
  66. smtNew.root <== rootNew;
  67. for (var i=0; i<nLevels; i++) {
  68. smtNew.siblings[i] <== siblingsNew[i];
  69. }
  70. smtNew.oldKey <== 0;
  71. smtNew.oldValue <== 0;
  72. smtNew.isOld0 <== 0;
  73. smtNew.key <== key;
  74. smtNew.value <== hash.out;
  75. }
  76. component main = Deposit(5);