如何在 Circom 的信号中使用 & (AND) 运算符

How to use & (AND) operator in a signal in Circom

我正在尝试在信号上使用 & 运算符并在 Circom circuit compiler language 中获取另一个信号,如下所示:

pragma circom 2.0.0;


template MAIN() {

    signal input a;
    signal output x;

    signal v;
    v <== 168;

    x <== v & 31;
}

component main = MAIN();

我收到此错误:

error[T3001]: Non quadratic constraints are not allowed!
    ┌─ "/Users/ilia/compiling/main-circom/main.circom":146:5
    │
146 │     x <== v & 31; // 0b00011111
    │     ^^^^^^^^^^^^ found here
    │
    = call trace:
      ->MAIN

如何生成 x 信号的约束以使其为二次方?

我用 Num2Bits:

// the code bellow is a quadratic equivalent of:
// x <== v & 31; // 0b00011111
component num2Bits = Num2Bits(8);
num2Bits.in <== v;
signal vbits[8];
for(k = 0; k < 8; k++) {
    vbits[k] <== num2Bits.out[k];
}
var lc1=0;
var e2 = 1;
for (var i = 0; i<5; i++) {
    lc1 += vbits[i] * e2;
    e2 = e2 + e2;
}
lc1 ==> x;