mirror of
https://github.com/arnaucube/circom-compat.git
synced 2026-01-22 13:11:28 +01:00
initial commit
This commit is contained in:
39
tests/groth16.rs
Normal file
39
tests/groth16.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use ark_circom::{CircomBuilder, CircuitConfig};
|
||||
use ark_std::rand::thread_rng;
|
||||
use color_eyre::Result;
|
||||
|
||||
use ark_bn254::Bn254;
|
||||
use ark_groth16::{
|
||||
create_random_proof as prove, generate_random_parameters, prepare_verifying_key, verify_proof,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn groth16_proof() -> Result<()> {
|
||||
let cfg = CircuitConfig::<Bn254>::new(
|
||||
"./test-vectors/mycircuit.wasm",
|
||||
"./test-vectors/mycircuit.r1cs",
|
||||
)?;
|
||||
let mut builder = CircomBuilder::new(cfg);
|
||||
builder.push_input("a", 3);
|
||||
builder.push_input("b", 11);
|
||||
|
||||
// create an empty instance for setting it up
|
||||
let circom = builder.setup();
|
||||
|
||||
let mut rng = thread_rng();
|
||||
let params = generate_random_parameters::<Bn254, _, _>(circom, &mut rng)?;
|
||||
|
||||
let circom = builder.build()?;
|
||||
|
||||
let inputs = circom.get_public_inputs().unwrap();
|
||||
|
||||
let proof = prove(circom, ¶ms, &mut rng)?;
|
||||
|
||||
let pvk = prepare_verifying_key(¶ms.vk);
|
||||
|
||||
let verified = verify_proof(&pvk, &proof, &inputs)?;
|
||||
|
||||
assert!(verified);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user