如何将 BigInt 数组表示形式转换为 Integer 表示形式?

问题描述 投票:0回答:1

我正在参与一个 zk 项目。使用该领域的一些知名库。我想以十进制表示形式打印具有单个值的

input
变量,但它打印为

Inputs: BigInt([4783305916722193742, 10816712439203674239, 7235145682067311982, 1125033445559876531])

代码位于下方,并完全从here引用。根据文章,输出应该是

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(&params, circom, &mut rng).unwrap();

    // Check that the proof is valid
    let pvk = Groth16::<Bn254>::process_vk(&params.vk).unwrap();
    let verified = Groth16::<Bn254>::verify_with_processed_vk(&pvk, &inputs, &proof).unwrap();
    println!("Verified: {:?}", verified);
    println!("Inputs: {:?}", inputs[0]);

    assert!(verified);
}
rust biginteger bigint circom sui
1个回答
0
投票

{:?}
(调试表示)更改为
{}
(显示表示)。

© www.soinside.com 2019 - 2024. All rights reserved.