Browse Source

refactor: rename circuit -> circom

pull/3/head
Georgios Konstantopoulos 3 years ago
parent
commit
72c533ac62
10 changed files with 27 additions and 30 deletions
  1. +0
    -1
      Cargo.toml
  2. +5
    -5
      src/circom/builder.rs
  3. +3
    -3
      src/circom/circuit.rs
  4. +6
    -3
      src/circom/mod.rs
  5. +0
    -0
      src/circom/qap.rs
  6. +1
    -1
      src/circom/r1cs_reader.rs
  7. +5
    -7
      src/lib.rs
  8. +2
    -2
      src/zkey.rs
  9. +2
    -2
      tests/groth16.rs
  10. +3
    -6
      tests/solidity.rs

+ 0
- 1
Cargo.toml

@ -30,7 +30,6 @@ ethers = { git = "https://github.com/gakonst/ethers-rs", features = ["abigen"] }
serde_json = "1.0.64"
serde = "1.0.126"
thiserror = "1.0.26"
memmap = "0.7.0"
ark-serialize = "0.3.0"
[dev-dependencies]

src/circuit/builder.rs → src/circom/builder.rs

@ -6,22 +6,22 @@ use super::{CircomCircuit, R1CS};
use num_bigint::BigInt;
use std::collections::HashMap;
use crate::{circuit::R1CSFile, WitnessCalculator};
use crate::{circom::R1CSFile, witness::WitnessCalculator};
use color_eyre::Result;
pub struct CircomBuilder<E: PairingEngine> {
pub cfg: CircuitConfig<E>,
pub cfg: CircomConfig<E>,
pub inputs: HashMap<String, Vec<BigInt>>,
}
// Add utils for creating this from files / directly from bytes
pub struct CircuitConfig<E: PairingEngine> {
pub struct CircomConfig<E: PairingEngine> {
pub r1cs: R1CS<E>,
pub wtns: WitnessCalculator,
pub sanity_check: bool,
}
impl<E: PairingEngine> CircuitConfig<E> {
impl<E: PairingEngine> CircomConfig<E> {
pub fn new(wtns: impl AsRef<Path>, r1cs: impl AsRef<Path>) -> Result<Self> {
let wtns = WitnessCalculator::new(wtns).unwrap();
let reader = File::open(r1cs)?;
@ -37,7 +37,7 @@ impl CircuitConfig {
impl<E: PairingEngine> CircomBuilder<E> {
/// Instantiates a new builder using the provided WitnessGenerator and R1CS files
/// for your circuit
pub fn new(cfg: CircuitConfig<E>) -> Self {
pub fn new(cfg: CircomConfig<E>) -> Self {
Self {
cfg,
inputs: HashMap::new(),

src/circuit/circom.rs → src/circom/circuit.rs

@ -3,7 +3,7 @@ use ark_relations::r1cs::{
ConstraintSynthesizer, ConstraintSystemRef, LinearCombination, SynthesisError, Variable,
};
use crate::circuit::R1CS;
use super::R1CS;
use color_eyre::Result;
@ -84,13 +84,13 @@ impl ConstraintSynthesizer for CircomCircuit {
#[cfg(test)]
mod tests {
use super::*;
use crate::{CircomBuilder, CircuitConfig};
use crate::{CircomBuilder, CircomConfig};
use ark_bn254::{Bn254, Fr};
use ark_relations::r1cs::ConstraintSystem;
#[test]
fn satisfied() {
let cfg = CircuitConfig::<Bn254>::new(
let cfg = CircomConfig::<Bn254>::new(
"./test-vectors/mycircuit.wasm",
"./test-vectors/mycircuit.r1cs",
)

src/circuit/mod.rs → src/circom/mod.rs

@ -3,11 +3,14 @@ use ark_ec::PairingEngine;
pub mod r1cs_reader;
pub use r1cs_reader::{R1CSFile, R1CS};
mod circom;
pub use circom::CircomCircuit;
mod circuit;
pub use circuit::CircomCircuit;
mod builder;
pub use builder::{CircomBuilder, CircuitConfig};
pub use builder::{CircomBuilder, CircomConfig};
mod qap;
pub use qap::R1CStoQAPCircom;
pub type Constraints<E> = (ConstraintVec<E>, ConstraintVec<E>, ConstraintVec<E>);
pub type ConstraintVec<E> = Vec<(usize, <E as PairingEngine>::Fr)>;

src/circom_qap.rs → src/circom/qap.rs


src/circuit/r1cs_reader.rs → src/circom/r1cs_reader.rs

@ -7,7 +7,7 @@ use ark_ec::PairingEngine;
use ark_ff::FromBytes;
use ark_std::io::Read;
use crate::circuit::{ConstraintVec, Constraints};
use super::{ConstraintVec, Constraints};
#[derive(Clone, Debug)]
pub struct R1CS<E: PairingEngine> {

+ 5
- 7
src/lib.rs

@ -66,14 +66,12 @@
//! Groth16 Proof verification:
//! `snarkjs groth16 verify verification_key.json public.json proof.json`
mod circom_wasm;
pub use circom_wasm::WitnessCalculator;
mod witness;
pub mod circuit;
pub use circuit::{CircomBuilder, CircomCircuit, CircuitConfig};
pub mod circom;
pub use circom::{CircomBuilder, CircomCircuit, CircomConfig, R1CStoQAPCircom};
pub mod ethereum;
pub mod zkey;
pub mod circom_qap;
mod zkey;
pub use zkey::read_zkey;

+ 2
- 2
src/zkey.rs

@ -299,7 +299,7 @@ mod tests {
use serde_json::Value;
use std::fs::File;
use crate::{circom_qap::R1CStoQAPCircom, CircomBuilder, CircuitConfig};
use crate::{circom::R1CStoQAPCircom, CircomBuilder, CircomConfig};
use ark_groth16::{create_random_proof_with_qap as prove, prepare_verifying_key, verify_proof};
use ark_std::rand::thread_rng;
use num_traits::{One, Zero};
@ -769,7 +769,7 @@ mod tests {
let mut file = File::open(path).unwrap();
let params = read_zkey(&mut file).unwrap(); // binfile.proving_key().unwrap();
let cfg = CircuitConfig::<Bn254>::new(
let cfg = CircomConfig::<Bn254>::new(
"./test-vectors/mycircuit.wasm",
"./test-vectors/mycircuit.r1cs",
)

+ 2
- 2
tests/groth16.rs

@ -1,4 +1,4 @@
use ark_circom::{CircomBuilder, CircuitConfig};
use ark_circom::{CircomBuilder, CircomConfig};
use ark_std::rand::thread_rng;
use color_eyre::Result;
@ -9,7 +9,7 @@ use ark_groth16::{
#[test]
fn groth16_proof() -> Result<()> {
let cfg = CircuitConfig::<Bn254>::new(
let cfg = CircomConfig::<Bn254>::new(
"./test-vectors/mycircuit.wasm",
"./test-vectors/mycircuit.r1cs",
)?;

+ 3
- 6
tests/solidity.rs

@ -1,6 +1,6 @@
use ark_circom::{
ethereum::{Inputs, Proof, VerifyingKey},
CircomBuilder, CircuitConfig,
CircomBuilder, CircomConfig,
};
use ark_std::rand::thread_rng;
use color_eyre::Result;
@ -18,7 +18,7 @@ use std::{convert::TryFrom, sync::Arc};
#[tokio::test]
async fn solidity_verifier() -> Result<()> {
let cfg = CircuitConfig::<Bn254>::new(
let cfg = CircomConfig::<Bn254>::new(
"./test-vectors/mycircuit.wasm",
"./test-vectors/mycircuit.r1cs",
)?;
@ -70,10 +70,7 @@ async fn solidity_verifier() -> Result<()> {
Ok(())
}
abigen!(
Groth16Verifier,
"./tests/verifier_abi.json"
);
abigen!(Groth16Verifier, "./tests/verifier_abi.json");
impl<M: Middleware> Groth16Verifier<M> {
async fn check_proof<I: Into<Inputs>, P: Into<Proof>, VK: Into<VerifyingKey>>(

Loading…
Cancel
Save