Skip to content

【session 2】 Exercise Integer Division - why does the if-else statement throw "signal already assigned" error? #54

Discussion options

You must be logged in to vote

还是没找到答案,用circom(之前用的是zkrepl)跑了也是一样的报错

这里补充2点:

  1. 根据Circom文档 Control Flow的例子
    这个例子里用的是var不是signal,所以我们知道用的是var的话不会throw signal already assigned
var x = 0;
var y = 1;
if (x >= 0) {
   x = y + 1;
   y += 1;
} else {
   y = x;
}

但这个点好像没什么帮助,因为remainder必须是output signal 😂

  1. 根据Circom文档 Unknowns,我们如果用signal作为if condition,在compile的时候由于in是未知的,所以不能生成constraint
pragma circom 2.0.0;

template A(){
   signal input in;
   signal output out;

   if (in < 0){
   // Error: There are constraints depending on the value of the condition and it can be unknown during the constraint generation phase
       out <== 0;
   }
}

component main = A();

但若if condition之后不是生成constraint而是单纯地assign是ok的

pragma circom 2.0.0;…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Demian101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants