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