0

我在Circom 电路编译器中有以下形式的代码

template DecodeUint(len) {
    signal input x;
    signal input pos;
    signal output value;
    signal output nextpos;

    component getV = GetV(len);

    if (x <= 23) {
        value <== x;
        pos ==> nextpos;
    }
    else if(x == 24) {
        value <== 255;
        pos + 1 ==> nextpos;
    }
}

我收到此错误:

error[T2005]: Typing error found
   ┌─ "/Users/ilia/compiling/main-circom/main.circom":93:13
   │
93 │     else if(x == 24) {
   │             ^^^^^^^ There are constraints depending on the value of the condition and it can be unknown during the constraint generation phase

如何以可以生成电路的形式重写条件?除了 if 条件之外,是否有类似Quin Selector的东西?

4

1 回答 1

0

我使用了LessThanand IsEqualfrom circomlib,它返回 1 或 0,这取决于它是 true 还是 false,然后将这些条件的输出乘以返回值,最后使用CalculateTotal将相乘的条件相加得到所有 if 的“结果”以算术方式分支。

于 2022-02-05T00:08:19.390 回答