diff --git a/tests/groth16.rs b/tests/groth16.rs index 5d9400c..5f9cd29 100644 --- a/tests/groth16.rs +++ b/tests/groth16.rs @@ -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; @@ -11,7 +11,7 @@ type GrothBn = Groth16; #[tokio::test] async fn groth16_proof() -> Result<()> { let cfg = CircomConfig::::new( - "./test-vectors/mycircuit.wasm", + "./test-vectors/mycircuit_js/mycircuit.wasm", "./test-vectors/mycircuit.r1cs", )?; let mut builder = CircomBuilder::new(cfg); @@ -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::::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(¶ms, circom, &mut rng).unwrap(); + + let pvk = GrothBn::process_vk(¶ms.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::::new( "./test-vectors/circom2_multiplier2.wasm", "./test-vectors/circom2_multiplier2.r1cs", @@ -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::::new( "./test-vectors/circom2_multiplier2.wasm", "./test-vectors/circom2_multiplier2.r1cs",