'How to pass function argument by reference in Circom?

How to pass function argument by reference in the circom circuit language?

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source