arnaucube
arnaucube/miksi-corePublic Self-hosted repository
miksi-core/circuits/deposit.circom
circuits/deposit.circomRaw
 1/*
 2
 3# deposit.circom
 4                     +----------+
 5                     |          |
 6PRI_secret+--------->+ Poseidon +<----+PUB_key
 7          |          |          |        +
 8          |          +----------+        |     +----------+
 9          |            nullifier         |     |          +<------+PUB_rootOld
10          |               +              |     |          |
11          |               |              |     |          +<------+PUB_rootNew
12          |               v              |     | SMT      |
13          |          +----+-----+        +---->+ Poseidon +<------+PRI_oldKey
14          +--------->+          |              | Verifier |
15                     |          +-----+------->+ (insert) +<------+PRI_oldValue
16PUB_coinCode+------->+ Poseidon |     |        |          |
17                     |          |     |        |          +<------+PRI_isOld0
18PUB_amount+--------->+          |     |        |          |
19                     +----------+     |        |          +<------+PRI_siblings
20                                      |        +----------+
21                                      |
22                                      |
23                                      |
24                                      |
25                   +----+             |
26PUB_commitment+----> == +<------------+
27                   +----+
28
29
30
31*/
32
33include "../node_modules/circomlib/circuits/comparators.circom";
34include "../node_modules/circomlib/circuits/poseidon.circom";
35include "../node_modules/circomlib/circuits/smt/smtprocessor.circom";
36
37template Deposit(nLevels) {
38	signal input coinCode;
39	signal input amount;
40	signal private input secret;
41	signal private input oldKey;
42	signal private input oldValue;
43	signal private input isOld0;
44	signal private input siblings[nLevels];
45	signal input rootOld;
46	signal input rootNew;
47	signal input commitment;
48	signal input key;
49
50	component nullifierCmp = Poseidon(2, 6, 8, 57);
51	nullifierCmp.inputs[0] <== key;
52	nullifierCmp.inputs[1] <== secret;
53
54	component hash = Poseidon(4, 6, 8, 57);
55	hash.inputs[0] <== coinCode;
56	hash.inputs[1] <== amount;
57	hash.inputs[2] <== secret;
58	hash.inputs[3] <== nullifierCmp.out; // nullifier
59
60	component comCheck = IsEqual();
61	comCheck.in[0] <== hash.out;
62	comCheck.in[1] <== commitment;
63	comCheck.out === 1;
64
65	
66	component smtProcessor = SMTProcessor(nLevels);
67	smtProcessor.oldRoot <== rootOld;
68	smtProcessor.newRoot <== rootNew;
69	for (var i=0; i<nLevels; i++) {
70		smtProcessor.siblings[i] <== siblings[i];
71	}
72	smtProcessor.oldKey <== oldKey;
73	smtProcessor.oldValue <== oldValue;
74	smtProcessor.isOld0 <== isOld0;
75	smtProcessor.newKey <== key;
76	smtProcessor.newValue <== hash.out;
77	smtProcessor.fnc[0] <== 1;
78	smtProcessor.fnc[1] <== 0;
79}