I was working with a zk project. Using some renowned libraries in the field. I wanted to print the input
variable with single value in decimal representation but it's printed as
Inputs: BigInt([4783305916722193742, 10816712439203674239, 7235145682067311982, 1125033445559876531])
The code is down below and referenced exactly from here. According to the article the output should be 7061949393491957813657776856458368574501817871421526214197139795307327923534
use ark_bn254::Bn254;
use ark_circom::CircomBuilder;
use ark_circom::CircomConfig;
use ark_groth16::Groth16;
use ark_snark::SNARK;
use num_bigint::BigUint;
use std::env;
fn main() {
// Get the current directory
let current_dir = env::current_dir().unwrap();
// Load the WASM and R1CS for witness and proof generation
// Construct the absolute paths for your files relative to the current directory
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();
// Insert our secret inputs as key value pairs. We insert a single input, namely the input to the hash function.
let mut builder = CircomBuilder::new(cfg);
builder.push_input("in", 7);
// let h = BigUint::parse_bytes(b"7061949393491957813", 10).expect("Cannot parse hash");
// Create an empty instance for setting it up
let circom = builder.setup();
// WARNING: The code below is just for debugging, and should instead use a verification key generated from a trusted setup.
// See for example https://docs.circom.io/getting-started/proving-circuits/#powers-of-tau.
let mut rng = rand::thread_rng();
let params =
Groth16::<Bn254>::generate_random_parameters_with_reduction(circom, &mut rng).unwrap();
let circom = builder.build().unwrap();
// There's only one public input, namely the hash digest.
let inputs = circom.get_public_inputs().unwrap();
// Generate the proof
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);
}
println!("Inputs: {:?}", inputs[0]);
Change {:?}
to {}
.
{:?}
shows a value's debug representation, which in this case shows the BigInt
's internal representation.{}
shows a value's display representation for human readability.