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