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.

74 lines
2.2 KiB

  1. # <h1 align="center"> ark-circom </h1>
  2. Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
  3. ![Github Actions](https://github.com/gakonst/ark-circom/workflows/Tests/badge.svg)
  4. ## Documentation
  5. Clone the repository and run `cd ark-circom/ && cargo doc --open`
  6. ## Add ark-circom to your repository
  7. ```toml
  8. [dependencies]
  9. ark-circom = { git = "https://github.com/gakonst/ark-circom.git" }
  10. ```
  11. ## Example
  12. ```rust
  13. // Load the WASM and R1CS for witness and proof generation
  14. let cfg = CircomConfig::<Bn254>::new(
  15. "./test-vectors/mycircuit.wasm",
  16. "./test-vectors/mycircuit.r1cs",
  17. )?;
  18. // Insert our public inputs as key value pairs
  19. let mut builder = CircomBuilder::new(cfg);
  20. builder.push_input("a", 3);
  21. builder.push_input("b", 11);
  22. // Create an empty instance for setting it up
  23. let circom = builder.setup();
  24. // Run a trusted setup
  25. let mut rng = thread_rng();
  26. let params = generate_random_parameters::<Bn254, _, _>(circom, &mut rng)?;
  27. // Get the populated instance of the circuit with the witness
  28. let circom = builder.build()?;
  29. let inputs = circom.get_public_inputs().unwrap();
  30. // Generate the proof
  31. let proof = prove(circom, &params, &mut rng)?;
  32. // Check that the proof is valid
  33. let pvk = prepare_verifying_key(&params.vk);
  34. let verified = verify_proof(&pvk, &proof, &inputs)?;
  35. assert!(verified);
  36. ```
  37. ## Running the tests
  38. Tests require the following installed:
  39. 1. [`solc`](https://solidity.readthedocs.io/en/latest/installing-solidity.html). We also recommend using [solc-select](https://github.com/crytic/solc-select) for more flexibility.
  40. 2. [`ganache-cli`](https://github.com/trufflesuite/ganache-cli#installation)
  41. ## Features
  42. - [x] Witness generation using Circom's WASM witness code
  43. - [x] ZKey parsing into Arkworks Proving Key over BN254
  44. - [x] Compatibility layer for Ethereum types, so that proofs can be used in Solidity verifiers
  45. - [x] Proof generations and verification using Arkworks
  46. - [ ] CLI for common operations
  47. ## Acknowledgements
  48. This library would not have been possibly without the great work done in:
  49. - [`zkutil`](https://github.com/poma/zkutil/)
  50. - [`snarkjs`](https://github.com/iden3/snarkjs/)
  51. Special shoutout to [Kobi Gurkan](https://github.com/kobigurk/) for all the help in parsing SnarkJS' ZKey file format.