基于其他两个信号的信号
我正在尝试编写一个电路,以证明一个数字在指定的范围内。我正在使用 circomlib library : comparatorter.circuit.circuit
文件。我的代码是:
template RangeProof(n) {
assert(n <= 252);
signal input in; // number to be proved
signal input range[2]; // [lower bound, upper bound]
signal output out;
component low = LessEqThan(n);
component high = GreaterEqThan(n);
low.in[0] <== in;
low.in[1] <== range[0];
low.out === 1;
high.in[0] <== in;
high.in[1]<==range[1];
high.out === 1;
out <== (low.out + high.out) == 2 ? 1: 0; //this is the line in question
}
我要返回 1
如果 true
和 0
如果 false
。但这将取决于其他两个信号。我该怎么做?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码中,您可以简单地做
out&lt; == low.out * high.out
。它可以准确地实现您想要的:
不过,如果您想根据“ if语句”分配给两个分支到两个分支的信号,则需要使用多路复用器。参见
mux1
来自CircomlibIn your code, you can simply do
out <== low.out * high.out
.It achieves exactly what you want:
In general though, if you want to assign to a signal based on an 'if statement' which branches into 2 branches, you need to use a Multiplexer. See
Mux1
template from circomlib https://github.com/iden3/circomlib/blob/master/circuits/mux1.circom#L33