You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1020 B

3 years ago
3 years ago
  1. use ark_circom::{CircomBuilder, CircomConfig};
  2. use ark_std::rand::thread_rng;
  3. use color_eyre::Result;
  4. use ark_bn254::Bn254;
  5. use ark_groth16::{
  6. create_random_proof as prove, generate_random_parameters, prepare_verifying_key, verify_proof,
  7. };
  8. #[test]
  9. fn groth16_proof() -> Result<()> {
  10. let cfg = CircomConfig::<Bn254>::new(
  11. "./test-vectors/mycircuit.wasm",
  12. "./test-vectors/mycircuit.r1cs",
  13. )?;
  14. let mut builder = CircomBuilder::new(cfg);
  15. builder.push_input("a", 3);
  16. builder.push_input("b", 11);
  17. // create an empty instance for setting it up
  18. let circom = builder.setup();
  19. let mut rng = thread_rng();
  20. let params = generate_random_parameters::<Bn254, _, _>(circom, &mut rng)?;
  21. let circom = builder.build()?;
  22. let inputs = circom.get_public_inputs().unwrap();
  23. let proof = prove(circom, &params, &mut rng)?;
  24. let pvk = prepare_verifying_key(&params.vk);
  25. let verified = verify_proof(&pvk, &proof, &inputs)?;
  26. assert!(verified);
  27. Ok(())
  28. }