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