Skip to content

Commit

Permalink
fix groth16 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagician committed Jul 13, 2024
1 parent 6e982e3 commit 79a070f
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tests/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ark_circom::{CircomBuilder, CircomConfig};
use ark_std::rand::thread_rng;
use color_eyre::Result;

use ark_bn254::Bn254;
use ark_bn254::{Bn254, Fr};
use ark_crypto_primitives::snark::SNARK;
use ark_groth16::Groth16;

Expand All @@ -11,7 +11,7 @@ type GrothBn = Groth16<Bn254>;
#[tokio::test]
async fn groth16_proof() -> Result<()> {
let cfg = CircomConfig::<Bn254>::new(
"./test-vectors/mycircuit.wasm",
"./test-vectors/mycircuit_js/mycircuit.wasm",
"./test-vectors/mycircuit.r1cs",
)?;
let mut builder = CircomBuilder::new(cfg);
Expand Down Expand Up @@ -40,29 +40,40 @@ async fn groth16_proof() -> Result<()> {
}

#[tokio::test]
async fn groth16_proof_wrong_input() {
async fn groth16_proof_wrong_input() -> Result<()> {
let cfg = CircomConfig::<Bn254>::new(
"./test-vectors/mycircuit.wasm",
"./test-vectors/mycircuit_js/mycircuit.wasm",
"./test-vectors/mycircuit.r1cs",
)
.unwrap();
let mut builder = CircomBuilder::new(cfg);
builder.push_input("a", 3);
// This isn't a public input to the circuit, should fail
// This isn't a public input to the circuit, should fail verification
builder.push_input("foo", 11);

// create an empty instance for setting it up
let circom = builder.setup();

let mut rng = thread_rng();
let _params = GrothBn::generate_random_parameters_with_reduction(circom, &mut rng).unwrap();
let params = GrothBn::generate_random_parameters_with_reduction(circom, &mut rng).unwrap();

let _ = builder.build().unwrap_err();
let circom = builder.build().unwrap();

// we need to manually specify the public input, else the circuit builder will take the default for b = 0, and set public input to 0 (=11*0).
let inputs = vec![Fr::from(33u64)];

let proof = GrothBn::prove(&params, circom, &mut rng).unwrap();

let pvk = GrothBn::process_vk(&params.vk).unwrap();

let verified = GrothBn::verify_with_processed_vk(&pvk, &inputs, &proof).unwrap();
assert!(!verified);

Ok(())
}

#[tokio::test]
#[cfg(feature = "circom-2")]
async fn groth16_proof_circom2() -> Result<()> {
async fn groth16_proof_circom() -> Result<()> {
let cfg = CircomConfig::<Bn254>::new(
"./test-vectors/circom2_multiplier2.wasm",
"./test-vectors/circom2_multiplier2.r1cs",
Expand Down Expand Up @@ -93,8 +104,7 @@ async fn groth16_proof_circom2() -> Result<()> {
}

#[tokio::test]
#[cfg(feature = "circom-2")]
async fn witness_generation_circom2() -> Result<()> {
async fn witness_generation_circom() -> Result<()> {
let cfg = CircomConfig::<Bn254>::new(
"./test-vectors/circom2_multiplier2.wasm",
"./test-vectors/circom2_multiplier2.r1cs",
Expand Down

0 comments on commit 79a070f

Please sign in to comment.