arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/circuits/smt/smthash.circom
circuits/smt/smthash.circomRaw
 1/*
 2    Copyright 2018 0KIMS association.
 3
 4    This file is part of circom (Zero Knowledge Circuit Compiler).
 5
 6    circom is a free software: you can redistribute it and/or modify it
 7    under the terms of the GNU General Public License as published by
 8    the Free Software Foundation, either version 3 of the License, or
 9    (at your option) any later version.
10
11    circom is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14    License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with circom. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20include "../mimc.circom";
21
22
23/*
24    Hash1 = H(1 | key | value)
25 */
26
27template SMTHash1() {
28    signal input key;
29    signal input value;
30    signal output out;
31
32    component h1 = MiMC7(91);   // Constant
33    h1.x_in <== 15021630795539610737508582392395901278341266317943626182700664337106830745361;
34    h1.k <== 1;
35
36    component h2 = MiMC7(91);
37    h2.x_in <== h1.out;
38    h2.k <== key;
39
40    component h3 = MiMC7(91);
41    h3.x_in <== h2.out;
42    h3.k <== value;
43
44    out <== h3.out;
45}
46
47/*
48    This component is used to create the 2 nodes.
49
50    Hash2 = H(Hl | Hr)
51 */
52
53template SMTHash2() {
54    signal input L;
55    signal input R;
56    signal output out;
57
58    component h1 = MiMC7(91);
59    h1.x_in <== 15021630795539610737508582392395901278341266317943626182700664337106830745361;
60    h1.k <== L;
61
62    component h2 = MiMC7(91);
63    h2.x_in <== h1.out;
64    h2.k <== R;
65
66    out <== h2.out;
67}