+
Skip to content

allow signals to be used in ternary condition #21

Open
@bkomuves

Description

@bkomuves

The following example circuit fails:

pragma circom 2.1.9;       

template Foo() {
  signal input x;
  signal output out;

  var y = (x == 0) ? 1 : 0;       // this is the problematic line

  out <-- y;
  out === 1 - x;
}

component main {public [x]} = Foo();

with the error message:

if branch or else branch is not a store to the signal, which is the only option for ternary operation

However, if you replace the problematic line with:

signal y <-- (x == 0) ? 1 : 0;

then it will succeed, even though the resulting circuit and witness is exactly the same (as circom optimizes that unused signal away).

So this limitation does not make any sense to me.

Not sure how many similar limitations are there with static computation involving dynamic inputs, but I would expect all of those to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载