I need to provide an array of input signals using rust based crate ark-circom. Throughout the documentation there are examples with simple input variables only. Neither did I find any resource online too.
I have experimented enough to conclude that the issue is due to the way I have provided the array of ‘in’ in my program. It would be really helpful if someone could guide me use arrays in ark-cirom.
An example circom code to reproduce the error:
pragma circom 2.1.5;
include "node_modules/circomlib/circuits/poseidon.circom";
template Main() {
component poseidon = Poseidon(2);
signal input in[2];
// signal input in1;
signal output digest;
poseidon.inputs[0] <== in[0];
poseidon.inputs[1] <== in[1];
digest <== poseidon.out;
}
component main = Main();
The rust program I’m using and not being able to generate proof:
fn main() {
let current_dir = env::current_dir().unwrap();
let main_js_path = current_dir.join("circuits/main_js/main.wasm");
let main_r1cs_path = current_dir.join("circuits/main.r1cs");
let cfg = CircomConfig::<Bn254>::new(main_js_path, main_r1cs_path).unwrap();
let vec = vec![1, 2]; // Your vector of integers
let s: String = vec.iter().map(|i| i.to_string()).collect();
let big_int = BigInt::parse_bytes(s.as_bytes(), 10).unwrap();
let mut builder = CircomBuilder::new(cfg);
builder.push_input("in", big_int);
let circom = builder.setup();
let mut rng = rand::thread_rng();
let params =
Groth16::<Bn254>::generate_random_parameters_with_reduction(circom, &mut rng).unwrap();
let circom = builder.build().unwrap();
let inputs = circom.get_public_inputs().unwrap();
let proof = Groth16::<Bn254>::prove(¶ms, circom, &mut rng).unwrap();
// Check that the proof is valid
let pvk = Groth16::<Bn254>::process_vk(¶ms.vk).unwrap();
let verified = Groth16::<Bn254>::verify_with_processed_vk(&pvk, &inputs, &proof).unwrap();
println!("Verified: {:?}", verified);
println!("Inputs: {}", inputs[0]);
assert!(verified);
}
The error log I’m getting:
wasm path "/Users/root/Documents/cryptography/groth16_sui_rs/circuits/main_js/main.wasm" r1cs path "/Users/root/Documents/cryptography/groth16_sui_rs/circuits/main_js/main.wasm" Constraint trace requires enabling `ConstraintLayer` Constraint trace requires enabling `ConstraintLayer` Unsatisfied constraint: Some("0") thread 'main' panicked at /Users/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ark-circom-0.1.0/src/circom/builder.rs:82:9: assertion failed: {
use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystem};
let cs = ConstraintSystem::<E::ScalarField>::new_ref();
circom.clone().generate_constraints(cs.clone()).unwrap();
let is_satisfied = cs.is_satisfied().unwrap();
if !is_satisfied {
println!("Unsatisfied constraint: {:?}",
cs.which_is_unsatisfied().unwrap());
}
is_satisfied } stack backtrace: 0: rust_begin_unwind
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:647:5 1: core::panicking::panic_fmt
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:72:14 2: core::panicking::panic
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:144:5 3: ark_circom::circom::builder::CircomBuilder<E>::build
at /Users/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ark-circom-0.1.0/src/circom/builder.rs:82:9 4: groth16_sui_rs::main
at ./src/main.rs:49:18 5: core::ops::function::FnOnce::call_once
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:250:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.