circom-compat icon indicating copy to clipboard operation
circom-compat copied to clipboard

How to `push_input` for a 3d array input?

Open 0xbok opened this issue 2 years ago • 7 comments

0xbok avatar Jan 04 '23 19:01 0xbok

I have a similar question, but for an array input.

In my circuit, main.circom, I have: signal input digits[7];

In main.rs, I have:

let mut builder = CircomBuilder::new(cfg);
builder.push_input("digits", &[1, 2, 3, 4, 5, 6, 7]);

The error encountered is:

error[E0277]: the trait bound `num_bigint::bigint::BigInt: From<&[{integer}; 7]>` is not satisfied
  --> src\main.rs:18:34
   |
18 |     builder.push_input("digits", &[1, 2, 3, 4, 5, 6, 7]);
   |             ----------           ^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&[{integer}; 7]>` is not implemented for `num_bigint::bigint::BigInt`
   |             |
   |             required by a bound introduced by this call

The error is easy to understand because

pub fn push_input<T: Into<BigInt>>(&mut self, name: impl ToString, val: T) {
        let values = self.inputs.entry(name.to_string()).or_insert_with(Vec::new);
        values.push(val.into());
    }

T must implement Into<BigInt>.

So how do we pass array inputs to circom circuits via rust?

jymchng avatar May 12 '23 05:05 jymchng

@gakonst Please help us with it.

jymchng avatar May 12 '23 08:05 jymchng

Doing it this way doesn't work as well:

(1..=7)
        .for_each(|d| builder.push_input(format!("digits[{d}]"), d));

jymchng avatar May 12 '23 08:05 jymchng

Hey - I hadn't figured out how to make this work when I was working on this. It's currently not supported, and I don't have bandwidth to figure this out unfortunately.

gakonst avatar May 12 '23 19:05 gakonst

Hey - I hadn't figured out how to make this work when I was working on this. It's currently not supported, and I don't have bandwidth to figure this out unfortunately.

@gakonst Hi, thank you for your response. Lol, I'll guess a funny workaround will be to split the input array into individual signals and push_input one by one.

jymchng avatar May 13 '23 01:05 jymchng

Hey - I hadn't figured out how to make this work when I was working on this. It's currently not supported, and I don't have bandwidth to figure this out unfortunately.

@gakonst Hi, thank you for your response. Lol, I'll guess a funny workaround will be to split the input array into individual signals and push_input one by one.

@jymchng Are you working on this issue?

RajeshRk18 avatar Aug 01 '23 17:08 RajeshRk18

I think that if you try to push different BigInt values one by one into the same signal, it should work. Push_input seems to append values to the vector. Try something as follows:

builder.push_input("digits", ToBigInt::to_bigint(&1).unwrap() ); builder.push_input("digits", ToBigInt::to_bigint(&2).unwrap() ); ...

ivabe avatar Jun 26 '24 09:06 ivabe