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