arkworks-rs / circom-compat

Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
Apache License 2.0
226 stars 108 forks source link

Panic on to_array32 #20

Closed albttx closed 2 years ago

albttx commented 2 years ago

Hello,

i'm new with rust and circom but I'm doing my best to learn.

I'm trying to compile the tornado-cash circuit and use ark-circom to interact with it. here are the circuits: https://github.com/tornadocash/tornado-core/tree/master/circuits they're using v1, but after 2 minor modifications it's compile. you can see my circuits here

I created a small and reproducible project to show my errors: https://github.com/albttx/ark-circom-tc and an issue https://github.com/albttx/ark-circom-tc/issues/1

the function to_array32 panic

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value',
/home/albttx/.cargo/git/checkouts/ark-circom-1c15f1eba3004428/cac27e6/src/witness/witness_calculator.rs:47:43

see the line here

here is the function

fn to_array32(s: &BigInt, size: usize) -> Vec<i32> {
    let mut res = vec![0; size as usize];
    let mut rem = s.clone();
    let radix = BigInt::from(0x100000000u64);
    let mut c = size - 1;
    while !rem.is_zero() {
        res[c] = (&rem % &radix).to_i32().unwrap();   // <-- error here
        rem /= &radix;
        c -= 1;
    }

    res
}

Could you guys help ?

albttx commented 2 years ago

after hours of search, i decided to write the issue...

right after i discover: https://github.com/gakonst/ark-circom/pull/19 which fix my problem..

i failed on

Constraint trace requires enabling `ConstraintLayer`

I'll create a new issue in case i still don't manage to find a solution

really sorry

philsippl commented 2 years ago

@albttx I've just pushed the missing test case, as soon as it is merged you can switch to master again, sorry for the delays. Did you figure out the other issue?

albttx commented 2 years ago

@philsippl Hello, thanks for your PR update.

yes I figure everything out.

i made a poc that is now working: https://github.com/albttx/ark-circom-tc in case you're interested :)