基于其他两个信号的信号

发布于 2025-01-26 11:56:14 字数 857 浏览 2 评论 0 原文

我正在尝试编写一个电路,以证明一个数字在指定的范围内。我正在使用 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 。但这将取决于其他两个信号。我该怎么做?

I am trying to write a circuit to prove that a number is within a specified range. I am using the circomlib library: comparators.circuit file. My code is this :

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
}

I want to return 1 if true and 0 if false. But that would depend on whether the other two out signals. How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2025-02-02 11:56:14

在您的代码中,您可以简单地做
out&lt; == low.out * high.out

它可以准确地实现您想要的:

low.out 0 * high.out 0 = out 0
low.out 1 * high.out 0 = out 0
low.out 0 * high.out 1 = out 0
low.out 1 * high.out 1 = out 1

不过,如果您想根据“ if语句”分配给两个分支到两个分支的信号,则需要使用多路复用器。参见 mux1 来自Circomlib

In your code, you can simply do
out <== low.out * high.out.

It achieves exactly what you want:

low.out 0 * high.out 0 = out 0
low.out 1 * high.out 0 = out 0
low.out 0 * high.out 1 = out 0
low.out 1 * high.out 1 = out 1

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文