arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/circuits/smt/smtinsertsm.circom
circuits/smt/smtinsertsm.circomRaw
 1/***************************************************************************************************
 2Each level on a SMTInsert has a state.
 3
 4The state of the level depends on the state of te botom level and on `xor` and
 5`is0` signals.
 6
 7`isOldLev` 1 when is the level where oldLeaf is.
 8
 9`xor` signal is 0 if the index bit at the current level is the same in the old
10and the new index, and 1 if it is different.
11
12`is0` signal, is 1 if we are inserting in an empty leaf and 0 if we are inserting
13in a leaf that contains an element.
14
15The states are:
16
17top: While the index bits of the old and new insex in the top level is the same, whe are in the top state.
18old0 and old1: When the we reach insert level,  we go to old0 and old1 states
19according to `is0` signal.
20btn: Once in old1 we go to btn until xor=1
21new1: This level is reached when xor=1. Here is where we insert the hash of the
22old and the new trees with just one element.
23na: Not appliable.  After inserting it, we go to the na level.
24
25
26
27                                                ###########
28                     levIns==curLevel          #           #
29   xor=0                  is0=1 ┌────────────▶#    old0     #────────┐
30  ┌─────┐                       │              ##         ##         │
31  │     │                       │                #########           │ any
32  │     ▼                       │                                    │
33  │    ###########              │                                    │          ###########
34  │   #           # ────────────┘                                    └────────▶#           #
35  └──#    top      #                                                          #    na       #
36      ##         ## ────┐                                                  ┌──▶##         ##
37        #########       │                                                  │     #########
38                        │                                                  │
39                        │      ###########                  ###########    │ any
40       levIns==curLevel │     #           #      xor=1     #           #   │
41            is0=0       └───▶#   old1      #─────────────▶#    new1     #──┘
42                              ##         ##                ##         ##
43                                #########──┐                 #########
44                                           │                     ▲
45                                           │               ┌─────┘
46                                      any  │    ###########│  xor=1
47                                           │   #           #
48                                           └─▶#    btn      #
49                                               ##         ##
50                                                 #########◀───────┐
51                                                     │            │
52                                                     │            │
53                                                     └────────────┘
54                                                         xor=0
55
56***************************************************************************************************/
57
58state