Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behaviour with for loop #21

Open
GuthL opened this issue Jan 21, 2019 · 0 comments
Open

Unexpected behaviour with for loop #21

GuthL opened this issue Jan 21, 2019 · 0 comments

Comments

@GuthL
Copy link

GuthL commented Jan 21, 2019

Thanks for this great library. A lot of every helpful error code and well designed!
I'm reimplementing scalarMul on babyjubjub using a naive double and add approach.
When I compile my circuit with a for loop doing only one loop (for stops at 2), the circuit compile.
When I compile my circuit with a for loop doing two loops (for stops at 3), the circuit hung forever.

Stop at 2

include "babyjub.circom";
include "bitify.circom";

template babyMul(){
    signal input exp;
    signal input point[2];
    signal output mulPoint[2];

    component adder = BabyAdd();
    component n2ba = Num2Bits(253);

    var R0[2] = [0,1];
    var R1[2] = point;

    exp <= 2**253;
    exp >= 0;

    n2ba.in <== exp;

    for (var i = 1; i<2; i++) {
        if (n2ba.out[253-i] == 1){
            R0[0] ==> adder.x1;
            R0[1] ==> adder.y1;
            R1[0] ==> adder.x2;
            R1[1] ==> adder.y2;
            adder.xout --> R0[0];
            adder.yout --> R0[1];
        }
        R1[0] ==> adder.x1;
        R1[1] ==> adder.y1;
        R1[0] ==> adder.x2;
        R1[1] ==> adder.y2;

        adder.xout --> R1[0];
        adder.yout--> R1[1];
    }

    mulPoint[0] <== R0[0];
    mulPoint[1] <== R0[1];

}

component main = babyMul()

Stop at 3

include "babyjub.circom";
include "bitify.circom";

template babyMul(){
    signal input exp;
    signal input point[2];
    signal output mulPoint[2];

    component adder = BabyAdd();
    component n2ba = Num2Bits(253);

    var R0[2] = [0,1];
    var R1[2] = point;

    exp <= 2**253;
    exp >= 0;

    n2ba.in <== exp;

    for (var i = 1; i<3; i++) {
        if (n2ba.out[253-i] == 1){
            R0[0] ==> adder.x1;
            R0[1] ==> adder.y1;
            R1[0] ==> adder.x2;
            R1[1] ==> adder.y2;
            adder.xout --> R0[0];
            adder.yout --> R0[1];
        }
        R1[0] ==> adder.x1;
        R1[1] ==> adder.y1;
        R1[0] ==> adder.x2;
        R1[1] ==> adder.y2;

        adder.xout --> R1[0];
        adder.yout--> R1[1];
    }

    mulPoint[0] <== R0[0];
    mulPoint[1] <== R0[1];

}

component main = babyMul()

Have I done something wrong?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant