简体   繁体   English

如何在 Circom 中通过引用传递 function 参数?

[英]How to pass function argument by reference in Circom?

How to pass function argument by reference in the circom circuit language ?如何在circom电路语言中通过引用传递function参数?

I'm trying to do the following:我正在尝试执行以下操作:

pragma circom 2.0.0;


function increment(foo) {
    foo++;
}

template MyTemplate() {
    signal input a;
    signal output b;

    var foo;
    foo = 0;

    increment(foo);
    log(foo);


    // ...
}

component main = MyTemplate();

I expect log(pos) to output 1, but I'm getting 0. Is there a certain way I need to pass pos into increment so that it can modify the variable by reference?我希望log(pos)到 output 1,但我得到 0。有没有某种方法我需要将pos传递给increment ,以便它可以通过引用修改变量?

I decided to use the C preprocessor to generate circom code, so now I have:我决定使用 C 预处理器来生成 circom 代码,所以现在我有:

main.circom: 
    cpp -P maintpl.circom > main.circom

in my Makefile在我的 Makefile

and

#define increment(foo) foo++

in my circom code.在我的circom代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM