Try โ€‚โ€‰HackMD

ZK-Email Halo2 Circuit Design

Deterministic Finite Automaton (DFA) Chip

A deterministic finite automaton (DFA) chip verifies that state transitions of DFA are valid for a given input string. In ZK-Email, it will be used to confirm that the given email string matches with the regular expression corresponding to the DFA.

The DFA chip consists of the following tables and constraints, where

q denotes a state of DFA,
Q,t
represent the number of states and input patterns, respectively, and
n
is the number of state transitions to be proved. Notably, the following tables are combined and a selector column is also defined in the actual implementation.

Witness table:

cur_state next_state input
q1cur
q2next
x1
q2cur
q3next
x2
โ‹ฎ
โ‹ฎ
โ‹ฎ
qncur
qn+1next
xn

Lookup table:

valid_cur_state valid_next_state valid_input
q1curโˆ—
q1,1nextโˆ—
x1โˆ—
q1curโˆ—
q1,2nextโˆ—
x2โˆ—
โ‹ฎ
โ‹ฎ
โ‹ฎ
q1curโˆ—
q1,tnextโˆ—
xtโˆ—
q2curโˆ—
q2,1nextโˆ—
x1โˆ—
q2curโˆ—
q2,2nextโˆ—
x2โˆ—
โ‹ฎ
โ‹ฎ
โ‹ฎ
q2curโˆ—
q2,tnextโˆ—
xtโˆ—
โ‹ฎ
โ‹ฎ
โ‹ฎ
qQcurโˆ—
qQ,1nextโˆ—
x1โˆ—
qQcurโˆ—
qQ,2nextโˆ—
x2โˆ—
โ‹ฎ
โ‹ฎ
โ‹ฎ
qQcurโˆ—
qQ,tnextโˆ—
xtโˆ—

Constraints:

  1. q1cur=q1curโˆ—
    , where
    q1curโˆ—
    is the fixed initial state in the DFA.
  2. For
    iโˆˆ[nโˆ’1]/{1}
    ,
    qinext=qi+1cur
    .
  3. For
    iโˆˆ[n]
    , there is a row
    (qcurโˆ—,qnextโˆ—,xโˆ—)
    in the lookup table such that
    qicurโˆ’qcurโˆ—=0
    ,
    qinextโˆ’qnextโˆ—=0
    , and
    xiโˆ’xโˆ—=0
    hold.
  4. When
    F=(f1,f2,โ€ฆ,fF)
    is a set of accept states,
    qn+1nextโˆˆF
    is satisfied.

In a nutshell, the valid patterns of the state transitions are fixed in the lookup table, and the actual state transitions to be proved are written in the witness table. The third constraint requires that each state transition in the witness table is included in the valid patterns. The second constraint confirms that the next state

qinext is used as the current state
qi+1cur
in the next state transition. The first and the fourth constraints correspond to the initial and final conditions, respectively.