0

我正在尝试对信号使用运算符并在Circom 电路编译器语言&中获取另一个信号,如下所示:

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 信号生成约束,使其成为二次方?

4

1 回答 1

0

我做到了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;
于 2022-02-02T13:38:18.543 回答