circomlib/circuits/smt/smthash.circom
circuits/smt/smthash.circomRaw
1include "../mimc.circom";
2
3
4/*
5 Hash1 = H(1 | key | value)
6 */
7
8template SMTHash1() {
9 signal input key;
10 signal input value;
11 signal output out;
12
13 component h1 = MiMC7(91); // Constant
14 h1.x_in <== 15021630795539610737508582392395901278341266317943626182700664337106830745361;
15 h1.k <== 1;
16
17 component h2 = MiMC7(91);
18 h2.x_in <== h1.out;
19 h2.k <== key;
20
21 component h3 = MiMC7(91);
22 h3.x_in <== h2.out;
23 h3.k <== value;
24
25 out <== h3.out;
26}
27
28/*
29 This component is used to create the 2 nodes.
30
31 Hash2 = H(Hl | Hr)
32 */
33
34template SMTHash2() {
35 signal input L;
36 signal input R;
37 signal output out;
38
39 component h1 = MiMC7(91);
40 h1.x_in <== 15021630795539610737508582392395901278341266317943626182700664337106830745361;
41 h1.k <== L;
42
43 component h2 = MiMC7(91);
44 h2.x_in <== h1.out;
45 h2.k <== R;
46
47 out <== h2.out;
48}