You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/circuits/primitives/src/bitwise_op_lookup/README.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,21 @@
2
2
3
3
XOR operation and range checking via lookup table
4
4
5
-
This chip implements a lookup table approach for XOR operations and range checks for integers of size $`\texttt{NUM\_BITS}`$. The lookup table contains all possible combinations of $`x`$ and $`y`$ values (both in the range $`0..2^{\texttt{NUM\_BITS}}`$), along with their XOR result.
5
+
This chip implements a lookup table approach for XOR operations and range checks for integers of size $`\texttt{NUM\_BITS}`$. The chip provides lookup table functionality for all possible combinations of $`x`$ and $`y`$ values (both in the range $`0..2^{\texttt{NUM\_BITS}}`$), enabling verification of XOR operations and range checks. In the trace, $x$ and $y$ are stored as binary decompositions (`x_bits` and `y_bits` arrays) rather than as full field elements.
6
6
7
-
The lookup mechanism works through the Bus interface, with other circuits requesting lookups by incrementing multiplicity counters for the operations they need to perform. Each row in the lookup table corresponds to a specific $(x, y)$ pair.
7
+
The lookup mechanism works through the Bus interface, with other circuits requesting lookups by incrementing multiplicity counters for the operations they need to perform. Each row in the trace corresponds to a specific $(x, y)$ pair.
8
8
9
-
**Preprocessed Columns:**
10
-
-`x`: Column containing the first input value ($0$ to $`2^{\texttt{NUM\_BITS}}-1`$)
11
-
-`y`: Column containing the second input value ($0$ to $`2^{\texttt{NUM\_BITS}}-1`$)
12
-
-`z_xor`: Column containing the XOR result of x and y ($x \oplus y$)
9
+
The chip uses gate-based constraints to generate the trace columns instead of a preprocessed trace. The trace enumerates all valid $(x, y)$ pairs in order: row $n$ corresponds to $(x, y)$ where $x = \lfloor n / 2^{\texttt{NUM\_BITS}} \rfloor$ and $y = n \bmod 2^{\texttt{NUM\_BITS}}$. The enumeration order is: $(0, 0)$, $(0, 1)$, ..., $(0, 2^{\texttt{NUM\_BITS}}-1)$, $(1, 0)$, $(1, 1)$, ..., up to $(2^{\texttt{NUM\_BITS}}-1, 2^{\texttt{NUM\_BITS}}-1)$.
13
10
14
-
**IO Columns:**
11
+
**Columns:**
12
+
-`x_bits[0..NUM_BITS-1]`: Binary decomposition of $x$ (where `x_bits[0]` is the least significant bit)
13
+
-`y_bits[0..NUM_BITS-1]`: Binary decomposition of $y$ (where `y_bits[0]` is the least significant bit)
15
14
-`mult_range`: Multiplicity column tracking the number of range check operations requested for each $(x, y)$ pair
16
15
-`mult_xor`: Multiplicity column tracking the number of XOR operations requested for each $(x, y)$ pair
16
+
17
+
The constraints enforce the enumeration pattern by:
18
+
1. Ensuring each bit is binary (0 or 1) using `assert_bool` constraints
19
+
2. Reconstructing $x$ and $y$ from their binary decompositions: $x = \sum_{i=0}^{\texttt{NUM\_BITS}-1} \texttt{x\_bits}[i] \cdot 2^i$
0 commit comments