[英]How to use & (AND) operator in a signal in Circom
我正在嘗試在信號上使用&
運算符並在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 信號生成約束,使其成為二次方?
我用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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.